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

Side by Side Diff: Source/core/frame/SubresourceIntegrity.cpp

Issue 803773002: SRI: Remove the restriction to HTTPS documents and resources. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase. 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 unified diff | Download patch
« no previous file with comments | « no previous file | Source/core/frame/SubresourceIntegrityTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/frame/SubresourceIntegrity.h" 6 #include "core/frame/SubresourceIntegrity.h"
7 7
8 #include "core/HTMLNames.h" 8 #include "core/HTMLNames.h"
9 #include "core/dom/Document.h" 9 #include "core/dom/Document.h"
10 #include "core/dom/Element.h" 10 #include "core/dom/Element.h"
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 bool SubresourceIntegrity::CheckSubresourceIntegrity(const Element& element, con st String& source, const KURL& resourceUrl, const String& resourceType) 85 bool SubresourceIntegrity::CheckSubresourceIntegrity(const Element& element, con st String& source, const KURL& resourceUrl, const String& resourceType)
86 { 86 {
87 if (!RuntimeEnabledFeatures::subresourceIntegrityEnabled()) 87 if (!RuntimeEnabledFeatures::subresourceIntegrityEnabled())
88 return true; 88 return true;
89 89
90 if (!element.fastHasAttribute(HTMLNames::integrityAttr)) 90 if (!element.fastHasAttribute(HTMLNames::integrityAttr))
91 return true; 91 return true;
92 92
93 Document& document = element.document(); 93 Document& document = element.document();
94 94
95 // Instead of just checking SecurityOrigin::isSecure on resourceUrl, this
96 // checks canAccessFeatureRequiringSecureOrigin so that file:// protocols
97 // and localhost resources can be allowed. These may be useful for testing
98 // and are allowed for features requiring authenticated origins, so Chrome
99 // allows them here.
100 String insecureOriginMsg = "";
101 RefPtr<SecurityOrigin> resourceSecurityOrigin = SecurityOrigin::create(resou rceUrl);
102 if (!document.securityOrigin()->canAccessFeatureRequiringSecureOrigin(insecu reOriginMsg)) {
103 UseCounter::count(document, UseCounter::SRIElementWithIntegrityAttribute AndInsecureOrigin);
104 // FIXME: This console message should probably utilize
105 // inesecureOriginMsg to give a more helpful message to the user.
106 logErrorToConsole("The 'integrity' attribute may only be used in documen ts in secure origins.", document);
107 return false;
108 }
109 if (!resourceSecurityOrigin->canAccessFeatureRequiringSecureOrigin(insecureO riginMsg)) {
110 UseCounter::count(document, UseCounter::SRIElementWithIntegrityAttribute AndInsecureResource);
111 logErrorToConsole("The 'integrity' attribute may only be used with resou rces on secure origins.", document);
112 return false;
113 }
114
115 String integrity; 95 String integrity;
116 HashAlgorithm algorithm; 96 HashAlgorithm algorithm;
117 String type; 97 String type;
118 String attribute = element.fastGetAttribute(HTMLNames::integrityAttr); 98 String attribute = element.fastGetAttribute(HTMLNames::integrityAttr);
119 if (!parseIntegrityAttribute(attribute, integrity, algorithm, type, document )) { 99 if (!parseIntegrityAttribute(attribute, integrity, algorithm, type, document )) {
120 // An error is logged to the console during parsing; we don't need to lo g one here. 100 // An error is logged to the console during parsing; we don't need to lo g one here.
121 UseCounter::count(document, UseCounter::SRIElementWithUnparsableIntegrit yAttribute); 101 UseCounter::count(document, UseCounter::SRIElementWithUnparsableIntegrit yAttribute);
122 return false; 102 return false;
123 } 103 }
124 104
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 271
292 if (!parseMimeType(position, end, type)) { 272 if (!parseMimeType(position, end, type)) {
293 logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute + "'). The content type could not be parsed.", document); 273 logErrorToConsole("Error parsing 'integrity' attribute ('" + attribute + "'). The content type could not be parsed.", document);
294 return false; 274 return false;
295 } 275 }
296 276
297 return true; 277 return true;
298 } 278 }
299 279
300 } // namespace blink 280 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | Source/core/frame/SubresourceIntegrityTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698