Closed Bug 1595762 Opened 5 years ago Closed 5 years ago

Honor X-Frame-Options / frame-ancestors for all embed/object loads

Categories

(Core :: DOM: Security, enhancement, P1)

enhancement

Tracking

()

RESOLVED FIXED
mozilla72
Tracking Status
firefox72 --- fixed

People

(Reporter: annevk, Assigned: ckerschb)

References

(Blocks 1 open bug)

Details

(Whiteboard: [domsecurity-active])

Attachments

(1 file)

This is important for the security guarantees around Fetch metadata headers and for being able to simplify our loading setup around the embed and object elements.

I thought this is what was just re-fixed with the fission bug? Perhaps I a missing more of this task.

Flags: needinfo?(ckerschb)
Priority: -- → P3
Whiteboard: [domsecurity-backlog1]
Assignee: nobody → ckerschb
Blocks: 1584993
Status: NEW → ASSIGNED
Flags: needinfo?(ckerschb)
Priority: P3 → P1
Whiteboard: [domsecurity-backlog1] → [domsecurity-active]

Please note that we are already doing the correct checks for XFO [0] but apparently we missed embed/object for frame-ancestors (the attached patch will fix that) when we made frame-ancestors fission compatible (Bug 1584993). Further, TYPE_INTERNAL_EMBED [1] as well as TYPE_INTERNAL_OBJECT will both be mapped to TYPE_OBJECT.

Was there any specific testcase you came across this? Besides the missing bits for frame-ancestors (which the patch will fix) I suppose that should just work with fetch, or is there anything we are missing in addition?

[0] https://searchfox.org/mozilla-central/source/dom/security/FramingChecker.cpp#221
[1] https://searchfox.org/mozilla-central/rev/6566d92dd46417a2f57e75c515135ebe84c9cef5/dom/base/nsIContentPolicy.idl#213

Flags: needinfo?(annevk)

The idea would be to also block if the response is for an image or plugin, e.g., data:text/html,<embed src="https://avatars3.githubusercontent.com/u/665379?s=88&v=4"> or data:text/html,<embed src="https://avatars3.githubusercontent.com/u/665379?s=88&v=4" type="image/jpeg">, but there are some compatibility risks with doing that so we'd need to roll that out carefully.

(This is now tracked by bug 1596402.)

Flags: needinfo?(annevk)
Pushed by nbeleuzu@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/da9476881d62
Make type object loads subject to CSP frame ancestors. r=jkt,annevk
Blocks: 1596402
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla72

I'm a little worried by the resulting code here. The code in PermitsAncestry happens to be checking the window attached to the loadinfo, not just its ancestors, which is arguably wrong for the subdocument case but critically important for the object case, right? At the very least, that code should have comments explaining why that window, not just its ancestors, needs to be checked...

Flags: needinfo?(ckerschb)

(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #7)

I'm a little worried by the resulting code here. The code in PermitsAncestry happens to be checking the window attached to the loadinfo, not just its ancestors, which is arguably wrong for the subdocument case but critically important for the object case, right? At the very least, that code should have comments explaining why that window, not just its ancestors, needs to be checked...

Sorry, I don't fully understand what you mean and if there is a problem I would like to understand it entirely. The code in permitsAncestry [1] queries the browsing context from the loadinfo, which is the context this frame will be loaded into, and then walks all the parent browsing contexts (the ancestor chain), correct? As far as I understand this is what should be happening, but as I said, maybe I am missing something. If so, please let me know!

[1] https://searchfox.org/mozilla-central/rev/cac340f10816707e91c46db6d285f80259420f07/dom/security/nsCSPContext.cpp#1531

Flags: needinfo?(ckerschb) → needinfo?(bzbarsky)

For iframe loads, is the browsing context from the loadinfo the browsing context inside the iframe, or the browsing context of the iframe's parent document?

Flags: needinfo?(bzbarsky) → needinfo?(ckerschb)

(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #9)

For iframe loads, is the browsing context from the loadinfo the browsing context inside the iframe, or the browsing context of the iframe's parent document?

It's the iframe's parent document, for quering the iframe browsing context itself I thought one would have to query frameBrowsingContext, see:
https://searchfox.org/mozilla-central/rev/cac340f10816707e91c46db6d285f80259420f07/netwerk/base/nsILoadInfo.idl#679

Flags: needinfo?(ckerschb) → needinfo?(bzbarsky)

Ah, I see. I wish this were clearly documented in the loadinfo API... Right now the documentation for all the windowid and browsing context id bits is somewhere between "confusing" and "misleading". :(

Reading through the code carefully, it looks like .browsingContext on the loadinfo returns the following things (for a selected subset of possible loadinfos; I didn't look hard into all the other cases):

  • Iframe loads: the browsing context of the document the <iframe> element is in.
  • Toplevel loads: the browsing context the load is happening in.
  • object/embed loads: the browsing context of the document the <object>/<embed> element is in.

So the PermitsAncestry bits are OK as long as we never have toplevel loads come through there.

As for .frameBrowsingContext, its behavior is even more bizarre:

  • iframe loads: the browsing context inside the iframe
  • object/embed loads: Hard to say. Might be the browsing context of the document the <object>/<embed>` is in, but might be the browsing context inside the object/embed if there happens to be one from the previous load, depending on what exactly got loaded previously. I'm not actually sure what happens here; might depend on whether we drop the old frameloader when a new load starts...

It really would be good to get this documented. Do you know who might be in a good position to do that?

Flags: needinfo?(bzbarsky) → needinfo?(ckerschb)

(In reply to Boris Zbarsky [:bzbarsky, bz on IRC] from comment #11)

It really would be good to get this documented. Do you know who might be in a good position to do that?

I agree, it's too confusing. It seems Nika added browsingContext as well as frameBrowsingContext to nsILoadInfo within Bug 1467223 and Bug 1522637 but it seems Nika is on leave currently.

Neha, who might be able to update documentation to reflect the scenarios Boris outlined in the previous comment? Could you please forward the ni? to someone in the team?

Flags: needinfo?(ckerschb) → needinfo?(nkochar)

Andreas, can you update the documentation to add clarity? Thanks!

Flags: needinfo?(nkochar) → needinfo?(afarre)

Filed bug 1600375 for this request.

Flags: needinfo?(afarre)
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: