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

Unified Diff: Source/core/dom/ScriptLoader.cpp

Issue 954233003: Enable SRI only for same origin and CORS content. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/dom/ScriptLoader.cpp
diff --git a/Source/core/dom/ScriptLoader.cpp b/Source/core/dom/ScriptLoader.cpp
index 47eed35b9c66d5d76acb6767b51c6b2bb20ee712..b45a7415b2fd5969ebea60b062f4bcd2c64be20e 100644
--- a/Source/core/dom/ScriptLoader.cpp
+++ b/Source/core/dom/ScriptLoader.cpp
@@ -351,9 +351,6 @@ void ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com
UseCounter::count(frame, UseCounter::BlockedSniffingImageToScript);
return;
}
-
- if (!SubresourceIntegrity::CheckSubresourceIntegrity(*m_element, sourceCode.source(), sourceCode.resource()->url(), sourceCode.resource()->mimeType()))
- return;
}
// FIXME: Can this be moved earlier in the function?
@@ -373,6 +370,15 @@ void ScriptLoader::executeScript(const ScriptSourceCode& sourceCode, double* com
if (!m_isExternalScript || (sourceCode.resource() && sourceCode.resource()->passesAccessControlCheck(&m_element->document(), m_element->document().securityOrigin())))
corsCheck = SharableCrossOrigin;
+ if (m_isExternalScript) {
+ bool canRequest = m_element->document().securityOrigin()->canRequest(sourceCode.resource()->resourceRequest().url());
+ if (!canRequest && corsCheck == NotSharableCrossOrigin && m_element->fastHasAttribute(HTMLNames::integrityAttr)) {
+ contextDocument->addConsoleMessage(ConsoleMessage::create(SecurityMessageSource, ErrorMessageLevel, "Cannot enforce integrity on non-CORS enabled resource."));
Mike West 2015/02/26 08:44:52 So we continue loading the resource if the CORS ch
jww 2015/03/06 02:16:42 You're right, I misread the algorithm (as you poin
+ } else if ((canRequest || corsCheck == SharableCrossOrigin) && !SubresourceIntegrity::CheckSubresourceIntegrity(*m_element, sourceCode.source(), sourceCode.resource()->url(), sourceCode.resource()->mimeType())) {
+ return;
+ }
+ }
+
// Create a script from the script element node, using the script
// block's source and the script block's type.
// Note: This is where the script is compiled and actually executed.

Powered by Google App Engine
This is Rietveld 408576698