Add CSP to loadURIOptions dictionary
Categories
(Core :: DOM: Security, enhancement, P2)
Tracking
()
Tracking | Status | |
---|---|---|
firefox67 | --- | fixed |
People
(Reporter: ckerschb, Assigned: ckerschb)
References
Details
(Whiteboard: [domsecurity-active])
Attachments
(4 files, 1 obsolete file)
90.45 KB,
patch
|
bzbarsky
:
review-
|
Details | Diff | Splinter Review |
46.09 KB,
patch
|
Gijs
:
review+
|
Details | Diff | Splinter Review |
2.85 KB,
patch
|
snorp
:
review+
|
Details | Diff | Splinter Review |
47 bytes,
text/x-phabricator-request
|
Details | Review |
Assignee | ||
Updated•6 years ago
|
Assignee | ||
Comment 1•6 years ago
|
||
Hey Nika, if I would want to extend CreateWindow() [1] by an 'nsIContentSecurityPolicy' argument, what is the right way of doing that these days? I looked at IPC::Princpial [2] and I would have implemented ParamTraits for nsIContentSecurityPolicy, but the comment on line 24 [2] says 'Legacy IPC::Princpal type' so I am not sure what do if I want to pass a CSP through the IPC layer.
Thanks!
[1] https://searchfox.org/mozilla-central/source/dom/ipc/ContentParent.cpp#4814
[2] https://searchfox.org/mozilla-central/source/dom/ipc/PermissionMessageUtils.h#24
Assignee | ||
Updated•6 years ago
|
Comment 2•6 years ago
|
||
(In reply to Christoph Kerschbaumer [:ckerschb] from comment #1)
Hey Nika, if I would want to extend CreateWindow() [1] by an 'nsIContentSecurityPolicy' argument, what is the right way of doing that these days? I looked at IPC::Princpial [2] and I would have implemented ParamTraits for nsIContentSecurityPolicy, but the comment on line 24 [2] says 'Legacy IPC::Princpal type' so I am not sure what do if I want to pass a CSP through the IPC layer.
So, the 'Legacy IPC::Principal type' is the legacy wrapper type, because there is now a ParamTraits<> implementation directly on the nsIPrincipal object. It's totally fine & recommended to implement ParamTraits (or IPDLParamTraits) for nsIContentSecurityPolicy :-).
Assignee | ||
Comment 3•6 years ago
|
||
Hey :mossop,
I would like to also send a CSP within that JSON here [1]. I tried to figure out how the principal is serialized there, but unfortunately I couldn't. If I do:
json.csp = ownerDoc.nodePrincipal.csp;
then automagically the ::toJSON() implementation of nsIContentSecurityPolicy [2] is called - but I guess that's rather some consistence than happening on purpose, right?
Either way, if I would like to send a CSP there, what would I have to do?
Thanks!
[1] https://searchfox.org/mozilla-central/source/browser/actors/ClickHandlerChild.jsm#89-91
[2] https://searchfox.org/mozilla-central/source/dom/security/nsCSPContext.cpp#1494
Comment 4•6 years ago
|
||
(In reply to Christoph Kerschbaumer [:ckerschb] from comment #3)
Hey :mossop,
I would like to also send a CSP within that JSON here [1]. I tried to figure out how the principal is serialized there, but unfortunately I couldn't. If I do:
json.csp = ownerDoc.nodePrincipal.csp;
then automagically the ::toJSON() implementation of nsIContentSecurityPolicy [2] is called - but I guess that's rather some consistence than happening on purpose, right?
JSON.stringify atuomatically calls an object's toJSON if it exists. I guess maybe the code that serialises for IPC does the same?
Either way, if I would like to send a CSP there, what would I have to do?
Now that https://phabricator.services.mozilla.com/D15728 is landed doesn't including the principal just include the CSP?
Comment 5•6 years ago
|
||
(In reply to Dave Townsend [:mossop] (he/him) from comment #4)
(In reply to Christoph Kerschbaumer [:ckerschb] from comment #3)
Either way, if I would like to send a CSP there, what would I have to do?
Now that https://phabricator.services.mozilla.com/D15728 is landed doesn't including the principal just include the CSP?
It does, but the plan is to move the CSP off the principal...
Comment 6•6 years ago
|
||
(In reply to Dave Townsend [:mossop] (he/him) from comment #4)
(In reply to Christoph Kerschbaumer [:ckerschb] from comment #3)
Hey :mossop,
I would like to also send a CSP within that JSON here [1]. I tried to figure out how the principal is serialized there, but unfortunately I couldn't. If I do:
json.csp = ownerDoc.nodePrincipal.csp;
then automagically the ::toJSON() implementation of nsIContentSecurityPolicy [2] is called - but I guess that's rather some consistence than happening on purpose, right?JSON.stringify atuomatically calls an object's toJSON if it exists. I guess maybe the code that serialises for IPC does the same?
Actually this is really strange. I can't see the structured cloning code calling toJSON methods anywhere, and JS shouldn't be able to access the csp attribute of principals since it is marked as [noscript]. So I have no idea how that worked.
So I think you have two options:
Assuming JS can get the nsIContentSecurityPolicy for the policies, add that to the JSON and write the code for structured cloning it (most of that already exists in https://phabricator.services.mozilla.com/D15728).
Or send something that represents the CSP across and make it possible to recreate on the other side. nsIPrincipal.cspJSON seems to be something you could use for this.
Assignee | ||
Comment 7•6 years ago
|
||
(In reply to Dave Townsend [:mossop] (he/him) from comment #6)
Actually this is really strange. I can't see the structured cloning code calling toJSON methods anywhere, and JS shouldn't be able to access the csp attribute of principals since it is marked as [noscript]. So I have no idea how that worked.
Right, I should have mentioned that I changed nsIPrincipal
- [noscript] attribute nsIContentSecurityPolicy csp;
- attribute nsIContentSecurityPolicy csp;
so that JS can access the CSP.
So I think you have two options:
Assuming JS can get the nsIContentSecurityPolicy for the policies, add that to the JSON and write the code for structured cloning it (most of that already exists in https://phabricator.services.mozilla.com/D15728).
Yeah that makes sense - I'll try that - thanks!
Assignee | ||
Comment 8•6 years ago
|
||
Boris, I am attaching a patch which provides the backend bits needed to pass the CSP around explicitly for top-level loads. The patch passes TRY but I am guessing we still miss some corner cases - but I would like to follow up on those in separate bugs as we encounter those corner cases. Please note that this patch still queries the CSP to be used from the principal within nsDocshell.cpp, but I added an assertion that the explicit CSP is identical to the CSP on the principal.
Regarding the inclusion of |#include "nsIXULRuntime.h"|. I couldn't figure out what I changed, but all of sudden I encountered that compiler error:
0:16.83 In file included from /home/ckerschb/source/mc-dbg/dom/ipc/Unified_cpp_dom_ipc1.cpp:2:
0:16.83 /home/ckerschb/source/mc/dom/ipc/PreallocatedProcessManager.cpp:157:16: error: no member named 'BrowserTabsRemoteAutostart' in namespace 'mozilla'
0:16.83 if (mozilla::BrowserTabsRemoteAutostart() &&
0:16.83 ~~~~~~~~~^
0:20.90 1 error generated.
hence I included nsIXULRuntime.h to make that compile error go away.
Finally, if you can review the backend part then Gijs can help with the frontend bits.
Assignee | ||
Comment 9•6 years ago
|
||
Gijs, as you are aware, we are trying to get the CSP off the principal. To do so, we need to pass the CSP explicitly from the frontend to docshell. Now, ultimately the CSP will hang off the document, hence the new entry points are wherever we still have a document. At the moment, I query the CSP from the principal, but ultimately I will query it from that document.
I am pretty sure we will encounter places in the codebase where we don't pass the CSP correctly. This patch at least passes TRY and we can follow up on individual code paths later, because the CSP used at the moment is still the one from the principal.
One case however I am unsure, which is within browser/base/content/nsContextMenu.js. Is it possible to query the document somewhere there. If so, please let me know. Otherwise we have to pass the CSP as an argument into that function. (Not sure if within that patch or as a follow up).
Comment 10•6 years ago
|
||
Assignee | ||
Comment 11•6 years ago
|
||
Gijs,
thanks for your suggestions. Please note that the various *.idl changes are in the other patch where I incorporated all the backend changes [1]. After review, I'll merge the patches together anyway - sorry for not mentioning this explicitly in the initial review. Further, I moved the (de)serializeCSP bits into E10SUtils and updated the interface of loadURI() within WebNavigationChild.jsm as suggested.
To answer your question if this update is incomplete or not. I updated all the codepaths so this implementation runs cleanly on TRY. In addition, I did quite intensive testing (see list underneath) to make sure we are covering all the highly executed codepaths. Please note that (within the other patch) we have an assertion within nsDocShell.cpp to make sure the passed in CSP matches the CSP from the principal. More importantly for now however, we do not use the passed in CSP - we just assert. Probably there might be a follow up, but I would like to get that fundamental implementation of the explicit CSP landed. Again it doesn't affect any of our production code. Finally, I manually inspected callsites, e.g. you mentioned webext-panels, there for example we use a systemPrincipal as the loadingPrincipal hence we don't have a CSP.
[1] https://bugzilla.mozilla.org/attachment.cgi?id=9037523&action=diff
Testing included:
- regular click
- ctrl-click
- right-click->open-link in new tab
- right-click->open-link in new container tab
- drag and drop the link to a new tab
- right-click->open-link in new window
- right-click->open link in new private window
- various other drag and drop operations (drag from one window into another window/tab, etc.).
Assignee | ||
Comment 12•6 years ago
|
||
Hey :snorp, I am not sure if you are the right reviewer. If not, maybe you can suggest someone who can take a look at the changes. In short, we are trying to explicitly pass a CSP from the frontend to the backend (docshell) because ultimately we would like to remove the CSP from the principal.
The *.idl changes for the change are in the other patch [1].
Please feel free to ping me on slack in case you have any questions - thanks!
[1] https://bugzilla.mozilla.org/attachment.cgi?id=9037523&action=diff
Comment 14•6 years ago
|
||
(In reply to Christoph Kerschbaumer [:ckerschb] from comment #11)
To answer your question if this update is incomplete or not. I updated all the codepaths so this implementation runs cleanly on TRY. In addition, I did quite intensive testing (see list underneath) to make sure we are covering all the highly executed codepaths. Please note that (within the other patch) we have an assertion within nsDocShell.cpp to make sure the passed in CSP matches the CSP from the principal. More importantly for now however, we do not use the passed in CSP - we just assert. Probably there might be a follow up, but I would like to get that fundamental implementation of the explicit CSP landed. Again it doesn't affect any of our production code. Finally, I manually inspected callsites, e.g. you mentioned webext-panels, there for example we use a systemPrincipal as the loadingPrincipal hence we don't have a CSP.
So let me get this straight... we don't use the new parameter? And "failure" in this case would imply not passing it, as that's the status quo. So the only way any behavior change would trip things on try is if we had failing tests on debug, right?
The thing is, it looks to me like at least https://searchfox.org/mozilla-central/rev/330daedbeac2bba296d663668e0e0cf248bc6823/toolkit/content/widgets/browser-custom-element.js#793 needs updating and isn't in this patch. I also would expect at least some of the callsites of openUILink(In) and openLink(In) to need updating... I realize quite a few use system principal or a newly minted null principal, but some also don't, right?
Assignee | ||
Comment 15•6 years ago
|
||
(In reply to :Gijs (he/him) from comment #14)
So let me get this straight... we don't use the new parameter? And "failure" in this case would imply not passing it, as that's the status quo. So the only way any behavior change would trip things on try is if we had failing tests on debug, right?
Yes, your assumptions are correct. Please note that we have hundreds of CSP tests, and also quite so many wpt tests for CSP. I did quite so much manual testing additionally. If you have more suggestions of how I can exercise code-paths I am happy to do so.
Please don't get me wrong, I will invest even more time testing and updating after this initial version has landed - but I think we should land this bug rather sooner than later to get more debug time. I would hope that the community (our own engineers) will file bugs and we can follow up on them individually. More or less get code-paths updated iteratively. Similar to what we did for passing the right triggeringPrincipal for top-level loads.
The thing is, it looks to me like at least https://searchfox.org/mozilla-central/rev/330daedbeac2bba296d663668e0e0cf248bc6823/toolkit/content/widgets/browser-custom-element.js#793 needs updating and isn't in this patch. I also would expect at least some of the callsites of openUILink(In) and openLink(In) to need updating... I realize quite a few use system principal or a newly minted null principal, but some also don't, right?
I agree, would you be fine with me doing that in a follow up bug?
Comment 16•6 years ago
|
||
Assignee | ||
Comment 17•6 years ago
|
||
(In reply to :Gijs (he/him) from comment #16)
r=me on the understanding that there will need to be follow-ups to update
any remaining codepaths, and that we won't land this until after merge day.
Yes for sure - as agreed we will land after the merge day and we will update remaining codepaths in that upcoming cycle. Thanks!
Assignee | ||
Comment 18•6 years ago
|
||
FWIW, here is a green TRY run:
https://treeherder.mozilla.org/#/jobs?repo=try&revision=3e3878bc7a3791decb9db4a26846f2c03ef6fdae
Comment 19•6 years ago
|
||
Assignee | ||
Comment 20•6 years ago
|
||
Comment 21•6 years ago
|
||
Comment 22•6 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/9b18d986ef29
https://hg.mozilla.org/mozilla-central/rev/530bf099ee9d
https://hg.mozilla.org/mozilla-central/rev/c794488399f7
Description
•