| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| OLD | NEW |