Closed
Bug 1223647
Opened 9 years ago
Closed 9 years ago
CSP erroneously "inherited" into dedicated workers
Categories
(Core :: DOM: Security, defect)
Core
DOM: Security
Tracking
()
RESOLVED
FIXED
mozilla45
Tracking | Status | |
---|---|---|
firefox45 | --- | fixed |
People
(Reporter: sicking, Assigned: sicking)
References
(Blocks 1 open bug)
Details
(Keywords: dev-doc-complete, site-compat)
Attachments
(5 files, 2 obsolete files)
(deleted),
patch
|
ckerschb
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ckerschb
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ckerschb
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
ckerschb
:
review+
|
Details | Diff | Splinter Review |
(deleted),
patch
|
Details | Diff | Splinter Review |
The XHR and importScripts code in dedicated workers currently set the wrong loadingPrincipal when creating a channel. That means that we end up using the CSP of the parent document when doing network security checks. I.e. we "inherit" the policy of the parent document into workers when XHR and importScripts are used.
Patch to fix attached
Attachment #8685757 -
Flags: review?(mozilla)
Assignee | ||
Updated•9 years ago
|
Assignee: nobody → jonas
Assignee | ||
Comment 1•9 years ago
|
||
Just add missing file_main_worker.js
Attachment #8685757 -
Attachment is obsolete: true
Attachment #8685757 -
Flags: review?(mozilla)
Assignee | ||
Updated•9 years ago
|
Attachment #8685770 -
Attachment is patch: true
Attachment #8685770 -
Flags: review?(mozilla)
Comment 2•9 years ago
|
||
Comment on attachment 8685770 [details] [diff] [review]
Patch v2
Review of attachment 8685770 [details] [diff] [review]:
-----------------------------------------------------------------
Tests looks great, thanks for fixing. Please just address my nits and r=me.
::: dom/security/test/csp/file_redirects_main.html
@@ +20,5 @@
> "style-src": thisSite+page+"?testid=style-src&csp=1",
> "worker": thisSite+page+"?testid=worker&csp=1",
> "xhr-src": thisSite+page+"?testid=xhr-src&csp=1",
> + "from-worker": thisSite+page+"?testid=from-worker&csp=1",
> + "from-blob-worker": thisSite+page+"?testid=from-blob-worker&csp=1",
nit: since you are already modifying those files, can you also remove the redundant: '&csp=1'. This file is the only file that uses file_redirects_page.sjs, you could then also remove the 'if (query["csp"] == 1) {' from file_redirects_page.sjs - thanks.
::: dom/workers/ScriptLoader.cpp
@@ +122,5 @@
> return NS_ERROR_DOM_SYNTAX_ERR;
> }
>
> + if (parentDoc && parentDoc->NodePrincipal() != principal) {
> + parentDoc = nullptr;
please add a comment, similar to the one you have in nsXMLHttpRequest.cpp, otherwise this is really confusing.
Attachment #8685770 -
Flags: review?(mozilla) → review+
Comment 4•9 years ago
|
||
Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/e72c6539d6b5 for Mulet timeouts in dom/workers/test/test_csp.html, https://treeherder.mozilla.org/logviewer.html#?job_id=17113139&repo=mozilla-inbound, and desktop/Fennec timeouts in dom/security/test/csp/test_redirects.html and failures in dom/security/test/csp/test_worker_redirect.html, https://treeherder.mozilla.org/logviewer.html#?job_id=17114818&repo=mozilla-inbound
Assignee | ||
Comment 5•9 years ago
|
||
Attachment #8686227 -
Flags: review?(mozilla)
Comment 6•9 years ago
|
||
Comment on attachment 8686227 [details] [diff] [review]
more fixes
Review of attachment 8686227 [details] [diff] [review]:
-----------------------------------------------------------------
For the record: We are removing test_worker_redirect.html since it relies on the fact that policies are inherited for workers - which was a false assumption. We are not loosing any testcoverage because we have test_redirects.html.
::: dom/security/test/csp/file_redirects_resource.sjs
@@ +139,5 @@
> // script that invokes XHR
> if (query["res"] == "xhr") {
> response.setHeader("Content-Type", "application/javascript", false);
> + var resp = 'var x = new XMLHttpRequest();x.open("GET", "' + thisSite +
> + resource+'?redir=other&res=xhr-resp&id=xhr-src-redir", false);\n' +
Ah I see, so this was not a redirect but tried to access that URL directly, but the CSP error still fired :-( Writing proper CSP tests is hard - thanks.
::: dom/security/test/csp/test_CSP.html
@@ +97,5 @@
> window.examiner = new examiner();
>
> window.testResult = function(testname, result, msg) {
> + // test already complete.... forget it... remember the first result.
> + if (window.tests[testname] != -1)
ok - so this you are changing back to what was in the initial test.
Attachment #8686227 -
Flags: review?(mozilla) → review+
This apparently broke mochitests on android: https://treeherder.mozilla.org/logviewer.html#?job_id=17160307&repo=mozilla-inbound
Backed out in https://hg.mozilla.org/integration/mozilla-inbound/rev/51dbf899ae40
Flags: needinfo?(jonas)
And a mulet mochitest, too: https://treeherder.mozilla.org/logviewer.html#?job_id=17160000&repo=mozilla-inbound
Assignee | ||
Comment 10•9 years ago
|
||
Turns out we're not just doing the wrong thing for network policies. We also do the wrong thing for JS policies.
This makes us grab the CSP from the result-principal of the channel, rather than grab it from the calling JS.
Flags: needinfo?(jonas)
Attachment #8686752 -
Flags: review?(mozilla)
Comment 11•9 years ago
|
||
Comment on attachment 8686752 [details] [diff] [review]
Also don't inherit JS policy
Review of attachment 8686752 [details] [diff] [review]:
-----------------------------------------------------------------
::: dom/base/nsContentUtils.cpp
@@ -6629,5 @@
> - }
> -
> - csp.forget(aCSP);
> - return true;
> -}
Thanks for removing that piece of code - that is indeed really scary!!
::: dom/workers/test/test_csp.html^headers^
@@ +1,2 @@
> Cache-Control: no-cache
> +Content-Security-Policy: default-src 'self' blob:
Thanks for adding blob tests here.
Attachment #8686752 -
Flags: review?(mozilla) → review+
Assignee | ||
Comment 12•9 years ago
|
||
Apparently we had tests for the wrong inheritance-behavior with SWs as well.
This kills the test which checks that eval() does not work in a SW if it was registered from a page with a CSP. And then applies CSP to the already-existing test which verifies that eval() works in SWs.
Attachment #8686903 -
Flags: review?(mozilla)
Assignee | ||
Comment 13•9 years ago
|
||
Modify the test to verify that we actually apply the csp on the page correctly.
Attachment #8686903 -
Attachment is obsolete: true
Attachment #8686903 -
Flags: review?(mozilla)
Attachment #8686908 -
Flags: review?(mozilla)
Assignee | ||
Comment 14•9 years ago
|
||
Roll up of all patches
Assignee | ||
Updated•9 years ago
|
Attachment #8686949 -
Attachment description: cspworker → Roll up of all patches
Updated•9 years ago
|
Attachment #8686908 -
Flags: review?(mozilla) → review+
Comment 15•9 years ago
|
||
Comment 16•9 years ago
|
||
Comment 17•9 years ago
|
||
bugherder |
https://hg.mozilla.org/mozilla-central/rev/12a852867c16
https://hg.mozilla.org/mozilla-central/rev/88025b4a432b
Status: NEW → RESOLVED
Closed: 9 years ago
status-firefox45:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
Updated•9 years ago
|
Keywords: dev-doc-needed,
site-compat
Comment 18•9 years ago
|
||
Posted the site compatibility doc: https://www.fxsitecompat.com/en-CA/docs/2016/dedicated-workers-no-longer-inherit-csp-from-parent-document-unless-embedded/
Keywords: dev-doc-needed → dev-doc-complete
You need to log in
before you can comment on or make changes to this bug.
Description
•