Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(659)

Issue 47923008: Block execution of failed 'crossorigin' <script>s. (Closed)

Created:
7 years, 1 month ago by sof
Modified:
7 years, 1 month ago
CC:
blink-reviews, dglazkov+blink, eae+blinkwatch, adamk+blink_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/blink.git@master
Visibility:
Public.

Description

Block execution of failed 'crossorigin' <script>s. The HTML spec tells us that if a script element has a 'crossorigin' attribute, a potentially CORS enabled fetch of its source URL must be performed: http://www.whatwg.org/specs/web-apps/current-work/multipage/scripting-1.html#dfnReturnLink-39 http://www.whatwg.org/specs/web-apps/current-work/multipage/fetching-resources.html#potentially-cors-enabled-fetch If the CORS cross-origin request status of that fetch is not a success due to a failed CORS resource sharing check, the implementation must act as if no script resource has been obtained. No such CORS check was in place for parser inserted elements, allowing a cross-origin CORS resource that either didn't permit the script access or the resource wasn't CORS enabled, to load in the presence of 'crossorigin'. Address this here by interposing a CORS check prior to starting script execution. This (tries) to mirror how the operations are sequenced in the underlying spec. Specifically, ScriptLoader::executePotentiallyCrossOriginScript() now performs the needed access check for fetched scripts _if_ the fetch was initiated as potentially CORS-enabled. That is, if the script was fetched from same-origin or the CORS check passes in the cross-origin case, then script execution can go ahead. If not and a cross-origin script, a console error message is added and an error event is dispatched. Script execution does not go ahead. To support the above, the ResourceFetcher::canAccess() predicate over resources now needs to be informed if the resource fetch was initiated in a potentially CORS enabled manner. If it was, the required CORS resource sharing check will be performed. By making the "CORS enabled" property of a fetch something that a loader keeps separate from the (potentially cached) resource, we can simplify the underlying structure a bit, removing the RequestOriginPolicy portion from the resource options. As a result, FetchRequest now instead keeps track of any origin restrictions of the fetch resource + the canAccess() predicate must be supplied with the "CORS enabled" setting to use when checking access to the actual resource. R=mkwst,abarth BUG=286684 Committed: https://src.chromium.org/viewvc/blink?view=rev&revision=162417

Patch Set 1 #

Total comments: 2

Patch Set 2 : Have loader record potentially-CORS-enabled load #

Patch Set 3 : Dispatch error event + correct handling cached cross-origin scripts. #

Patch Set 4 : Minimize code changes + remove redundant leftovers. #

Total comments: 13

Patch Set 5 : Remove RequestOriginPolicy + suggested improvements #

Total comments: 4

Patch Set 6 : Keep OriginRestriction on FetchRequest #

Total comments: 2

Patch Set 7 : Rebased patch #

Patch Set 8 : Have CSSImageValue::cachedImage() take a CORS enabled argument #

Total comments: 2

Patch Set 9 : Shortened ...CrossOriginEnabled to ...CORSEnabled #

Patch Set 10 : Rebased #

Unified diffs Side-by-side diffs Delta from patch set Stats (+278 lines, -89 lines) Patch
M LayoutTests/http/tests/security/cross-origin-css.html View 1 2 3 4 5 6 7 8 1 chunk +7 lines, -1 line 0 comments Download
M LayoutTests/http/tests/security/cross-origin-css-expected.txt View 1 2 3 4 5 6 7 8 1 chunk +1 line, -0 lines 0 comments Download
M LayoutTests/http/tests/security/resources/cors-script.php View 1 chunk +7 lines, -1 line 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-fails-cross-origin.html View 1 2 1 chunk +22 lines, -0 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-fails-cross-origin-2.xhtml View 1 chunk +32 lines, -0 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-fails-cross-origin-2-expected.txt View 1 chunk +4 lines, -0 lines 0 comments Download
A + LayoutTests/http/tests/security/script-crossorigin-fails-cross-origin-expected.txt View 1 chunk +2 lines, -2 lines 0 comments Download
M LayoutTests/http/tests/security/script-crossorigin-loads-correctly.html View 1 chunk +1 line, -1 line 0 comments Download
A + LayoutTests/http/tests/security/script-crossorigin-loads-correctly-credentials.html View 1 chunk +2 lines, -2 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-loads-correctly-credentials-2.html View 1 2 1 chunk +44 lines, -0 lines 0 comments Download
A + LayoutTests/http/tests/security/script-crossorigin-loads-correctly-credentials-2-expected.txt View 1 2 1 chunk +3 lines, -5 lines 0 comments Download
A + LayoutTests/http/tests/security/script-crossorigin-loads-correctly-credentials-expected.txt View 0 chunks +-1 lines, --1 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-loads-cross-origin.html View 1 chunk +22 lines, -0 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-loads-cross-origin-2.xhtml View 1 chunk +30 lines, -0 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-loads-cross-origin-2-expected.txt View 1 chunk +3 lines, -0 lines 0 comments Download
A LayoutTests/http/tests/security/script-crossorigin-loads-cross-origin-expected.txt View 1 chunk +3 lines, -0 lines 0 comments Download
M LayoutTests/http/tests/security/script-onerror-crossorigin-cors.html View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M LayoutTests/http/tests/security/script-onerror-crossorigin-no-cors.html View 1 2 3 4 5 6 1 chunk +14 lines, -13 lines 0 comments Download
M LayoutTests/http/tests/security/script-onerror-crossorigin-no-cors-expected.txt View 1 chunk +2 lines, -7 lines 0 comments Download
A + LayoutTests/http/tests/security/script-onerror-crossorigin-same-origin.html View 1 2 3 4 5 6 2 chunks +4 lines, -4 lines 0 comments Download
A + LayoutTests/http/tests/security/script-onerror-crossorigin-same-origin-expected.txt View 1 chunk +2 lines, -2 lines 0 comments Download
M LayoutTests/http/tests/security/script-onerror-no-crossorigin-cors.html View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M LayoutTests/http/tests/security/script-onerror-no-crossorigin-no-cors.html View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M Source/core/css/CSSImageValue.h View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -2 lines 0 comments Download
M Source/core/css/CSSImageValue.cpp View 1 2 3 4 5 6 7 8 1 chunk +6 lines, -6 lines 0 comments Download
M Source/core/css/resolver/StyleResourceLoader.cpp View 1 2 3 4 5 6 7 8 1 chunk +1 line, -2 lines 0 comments Download
M Source/core/dom/ScriptLoader.h View 1 2 3 4 3 chunks +8 lines, -0 lines 0 comments Download
M Source/core/dom/ScriptLoader.cpp View 1 2 3 4 5 6 7 8 6 chunks +20 lines, -5 lines 0 comments Download
M Source/core/fetch/FetchRequest.h View 1 2 3 4 5 3 chunks +5 lines, -1 line 0 comments Download
M Source/core/fetch/FetchRequest.cpp View 1 2 3 4 5 4 chunks +4 lines, -3 lines 0 comments Download
M Source/core/fetch/ResourceFetcher.h View 1 2 3 4 5 6 7 8 3 chunks +7 lines, -2 lines 0 comments Download
M Source/core/fetch/ResourceFetcher.cpp View 1 2 3 4 5 6 7 8 8 chunks +10 lines, -10 lines 0 comments Download
M Source/core/fetch/ResourceLoaderOptions.h View 1 2 3 4 5 chunks +0 lines, -10 lines 0 comments Download
M Source/core/html/HTMLImportLoader.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M Source/core/html/HTMLImportsController.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M Source/core/html/parser/HTMLScriptRunner.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
M Source/core/loader/DocumentLoader.cpp View 1 2 3 4 5 6 7 8 9 1 chunk +1 line, -1 line 0 comments Download
M Source/core/xml/XSLTProcessorLibxslt.cpp View 1 2 3 4 5 6 1 chunk +1 line, -1 line 0 comments Download
M Source/core/xml/parser/XMLDocumentParser.cpp View 1 2 3 4 5 6 1 chunk +2 lines, -2 lines 0 comments Download

Messages

Total messages: 42 (0 generated)
sof
Please take a look, or suggest reviewers (even) better placed for CORS + loader related ...
7 years, 1 month ago (2013-10-29 06:53:43 UTC) #1
Mike West
Thanks for taking a look at this. The approach seems pretty reasonable, but checking the ...
7 years, 1 month ago (2013-10-29 11:00:53 UTC) #2
sof
https://codereview.chromium.org/47923008/diff/1/Source/core/dom/ScriptLoader.cpp File Source/core/dom/ScriptLoader.cpp (right): https://codereview.chromium.org/47923008/diff/1/Source/core/dom/ScriptLoader.cpp#newcode374 Source/core/dom/ScriptLoader.cpp:374: && !m_element->fastGetAttribute(HTMLNames::crossoriginAttr).isNull() On 2013/10/29 11:00:53, Mike West wrote: > ...
7 years, 1 month ago (2013-10-29 12:04:41 UTC) #3
sof
On 2013/10/29 12:04:41, sof wrote: > https://codereview.chromium.org/47923008/diff/1/Source/core/dom/ScriptLoader.cpp > File Source/core/dom/ScriptLoader.cpp (right): > > https://codereview.chromium.org/47923008/diff/1/Source/core/dom/ScriptLoader.cpp#newcode374 > ...
7 years, 1 month ago (2013-10-29 16:49:16 UTC) #4
sof
7 years, 1 month ago (2013-10-29 16:49:32 UTC) #5
sof
Come to think of it, the current potentially-CORS check in ResourceFetcher::canAccess(Resource *) against the origin ...
7 years, 1 month ago (2013-10-29 17:25:11 UTC) #6
abarth-chromium
Shouldn't we model CORS failures as network errors? I'm not sure why we need special ...
7 years, 1 month ago (2013-10-29 20:50:11 UTC) #7
sof
On 2013/10/29 20:50:11, abarth wrote: > Shouldn't we model CORS failures as network errors? I'm ...
7 years, 1 month ago (2013-10-29 22:31:41 UTC) #8
sof
On 2013/10/29 17:25:11, sof wrote: > Come to think of it, the current potentially-CORS check ...
7 years, 1 month ago (2013-10-29 22:35:18 UTC) #9
sof
7 years, 1 month ago (2013-10-29 22:35:38 UTC) #10
sof
If there's anything I can do to improve the shape of this change, do let ...
7 years, 1 month ago (2013-11-01 09:51:27 UTC) #11
sof
I'm keen to invigorate this patch & review -- I'll do what it takes to ...
7 years, 1 month ago (2013-11-14 15:07:24 UTC) #12
eseidel
Adam Barth is really your best reviewer for CORS related changes. He should be reachable ...
7 years, 1 month ago (2013-11-14 15:54:36 UTC) #13
abarth-chromium
https://codereview.chromium.org/47923008/diff/70002/Source/core/dom/ScriptLoader.cpp File Source/core/dom/ScriptLoader.cpp (right): https://codereview.chromium.org/47923008/diff/70002/Source/core/dom/ScriptLoader.cpp#newcode245 Source/core/dom/ScriptLoader.cpp:245: executePotentiallyCrossOriginScript(ScriptSourceCode(scriptContent(), scriptURL, position)); Does it matter that we're losing ...
7 years, 1 month ago (2013-11-14 16:34:48 UTC) #14
sof
Thanks abarth! Updated patch incoming a bit later, but wanted to follow up with some ...
7 years, 1 month ago (2013-11-14 17:12:02 UTC) #15
abarth-chromium
If we can remove the option from the struct, that would be better. It's always ...
7 years, 1 month ago (2013-11-14 18:42:17 UTC) #16
sof
https://codereview.chromium.org/47923008/diff/70002/Source/core/dom/ScriptLoader.cpp File Source/core/dom/ScriptLoader.cpp (right): https://codereview.chromium.org/47923008/diff/70002/Source/core/dom/ScriptLoader.cpp#newcode245 Source/core/dom/ScriptLoader.cpp:245: executePotentiallyCrossOriginScript(ScriptSourceCode(scriptContent(), scriptURL, position)); On 2013/11/14 17:12:03, sof wrote: > ...
7 years, 1 month ago (2013-11-15 08:05:23 UTC) #17
sof
https://codereview.chromium.org/47923008/diff/300001/Source/core/fetch/ResourceFetcher.h File Source/core/fetch/ResourceFetcher.h (right): https://codereview.chromium.org/47923008/diff/300001/Source/core/fetch/ResourceFetcher.h#newcode64 Source/core/fetch/ResourceFetcher.h:64: enum OriginRestriction { Finding appropriate names for this one ...
7 years, 1 month ago (2013-11-15 08:11:58 UTC) #18
abarth-chromium
https://codereview.chromium.org/47923008/diff/300001/Source/core/fetch/ResourceFetcher.h File Source/core/fetch/ResourceFetcher.h (right): https://codereview.chromium.org/47923008/diff/300001/Source/core/fetch/ResourceFetcher.h#newcode95 Source/core/fetch/ResourceFetcher.h:95: ResourcePtr<ImageResource> fetchImage(FetchRequest&, OriginRestriction = UseDefaultOriginRestrictionForType); On 2013/11/15 08:11:58, sof ...
7 years, 1 month ago (2013-11-15 15:47:51 UTC) #19
sof
https://codereview.chromium.org/47923008/diff/300001/Source/core/fetch/ResourceFetcher.h File Source/core/fetch/ResourceFetcher.h (right): https://codereview.chromium.org/47923008/diff/300001/Source/core/fetch/ResourceFetcher.h#newcode95 Source/core/fetch/ResourceFetcher.h:95: ResourcePtr<ImageResource> fetchImage(FetchRequest&, OriginRestriction = UseDefaultOriginRestrictionForType); On 2013/11/15 15:47:52, abarth ...
7 years, 1 month ago (2013-11-15 17:05:18 UTC) #20
abarth-chromium
lgtm This looks great. Sorry for the delay in responding. Thanks for the patch. https://codereview.chromium.org/47923008/diff/360001/Source/core/css/resolver/StyleResourceLoader.cpp ...
7 years, 1 month ago (2013-11-20 05:12:31 UTC) #21
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sigbjornf@opera.com/47923008/360001
7 years, 1 month ago (2013-11-20 05:12:38 UTC) #22
commit-bot: I haz the power
Failed to apply patch for LayoutTests/http/tests/security/script-onerror-crossorigin-same-origin.html: While running patch -p1 --forward --force --no-backup-if-mismatch; A LayoutTests/http/tests/security/script-onerror-crossorigin-same-origin.html ...
7 years, 1 month ago (2013-11-20 05:12:47 UTC) #23
sof
On 2013/11/20 05:12:47, I haz the power (commit-bot) wrote: > Failed to apply patch for ...
7 years, 1 month ago (2013-11-20 09:38:03 UTC) #24
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sigbjornf@opera.com/47923008/430001
7 years, 1 month ago (2013-11-20 09:38:23 UTC) #25
sof
Thanks abarth, do appreciate you finding the time. https://codereview.chromium.org/47923008/diff/360001/Source/core/css/resolver/StyleResourceLoader.cpp File Source/core/css/resolver/StyleResourceLoader.cpp (right): https://codereview.chromium.org/47923008/diff/360001/Source/core/css/resolver/StyleResourceLoader.cpp#newcode120 Source/core/css/resolver/StyleResourceLoader.cpp:120: shapeValue->setImage(cssImageValue->cachedImage(m_fetcher, ...
7 years, 1 month ago (2013-11-20 10:10:30 UTC) #26
commit-bot: I haz the power
Retried try job too often on linux_blink_rel for step(s) webkit_tests http://build.chromium.org/p/tryserver.chromium/buildstatus?builder=linux_blink_rel&number=13209
7 years, 1 month ago (2013-11-20 10:45:25 UTC) #27
sof
On 2013/11/20 10:10:30, sof wrote: > Thanks abarth, do appreciate you finding the time. > ...
7 years, 1 month ago (2013-11-20 12:22:55 UTC) #28
abarth-chromium
On 2013/11/20 12:22:55, sof wrote: > (I don't understand why, but the rebase caused this ...
7 years, 1 month ago (2013-11-20 17:32:33 UTC) #29
abarth-chromium
lgtm https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h File Source/core/css/CSSImageValue.h (right): https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h#newcode42 Source/core/css/CSSImageValue.h:42: StyleFetchedImage* cachedImage(ResourceFetcher* fetcher) { return cachedImage(fetcher, ResourceFetcher::defaultResourceOptions(), NotCrossOriginEnabled); ...
7 years, 1 month ago (2013-11-20 17:34:05 UTC) #30
sof
https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h File Source/core/css/CSSImageValue.h (right): https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h#newcode42 Source/core/css/CSSImageValue.h:42: StyleFetchedImage* cachedImage(ResourceFetcher* fetcher) { return cachedImage(fetcher, ResourceFetcher::defaultResourceOptions(), NotCrossOriginEnabled); } ...
7 years, 1 month ago (2013-11-20 17:49:07 UTC) #31
abarth-chromium
On 2013/11/20 17:49:07, sof wrote: > https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h > File Source/core/css/CSSImageValue.h (right): > > https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h#newcode42 > ...
7 years, 1 month ago (2013-11-20 17:50:35 UTC) #32
sof
On 2013/11/20 17:50:35, abarth wrote: > On 2013/11/20 17:49:07, sof wrote: > > > https://codereview.chromium.org/47923008/diff/610001/Source/core/css/CSSImageValue.h ...
7 years, 1 month ago (2013-11-20 18:01:08 UTC) #33
abarth-chromium
On 2013/11/20 18:01:08, sof wrote: > Certainly; shorten PotentiallyCrossOriginEnabled also? Yeah
7 years, 1 month ago (2013-11-20 18:18:41 UTC) #34
sof
On 2013/11/20 17:32:33, abarth wrote: > On 2013/11/20 12:22:55, sof wrote: > > (I don't ...
7 years, 1 month ago (2013-11-20 19:17:34 UTC) #35
sof
On 2013/11/20 18:18:41, abarth wrote: > On 2013/11/20 18:01:08, sof wrote: > > Certainly; shorten ...
7 years, 1 month ago (2013-11-20 19:20:41 UTC) #36
abarth-chromium
Thanks :)
7 years, 1 month ago (2013-11-20 20:24:36 UTC) #37
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sigbjornf@opera.com/47923008/700001
7 years, 1 month ago (2013-11-20 20:25:25 UTC) #38
commit-bot: I haz the power
Failed to apply patch for Source/core/html/HTMLImportLoader.cpp: While running patch -p1 --forward --force --no-backup-if-mismatch; patching file ...
7 years, 1 month ago (2013-11-20 20:25:54 UTC) #39
sof
Rebased and resolved straightforward HTMLImportLoader conflict (m_parent vs parent())
7 years, 1 month ago (2013-11-20 20:56:20 UTC) #40
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-status.appspot.com/cq/sigbjornf@opera.com/47923008/780001
7 years, 1 month ago (2013-11-20 20:56:53 UTC) #41
commit-bot: I haz the power
7 years, 1 month ago (2013-11-20 23:48:06 UTC) #42
Message was sent while issue was closed.
Change committed as 162417

Powered by Google App Engine
This is Rietveld 408576698