OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011 Google, Inc. All rights reserved. | 2 * Copyright (C) 2011 Google, Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 { ContentSecurityPolicyHashAlgorithmSha384, HashAlgorithmSha384 }, | 369 { ContentSecurityPolicyHashAlgorithmSha384, HashAlgorithmSha384 }, |
370 { ContentSecurityPolicyHashAlgorithmSha512, HashAlgorithmSha512 } | 370 { ContentSecurityPolicyHashAlgorithmSha512, HashAlgorithmSha512 } |
371 }; | 371 }; |
372 | 372 |
373 // Only bother normalizing the source/computing digests if there are any che
cks to be done. | 373 // Only bother normalizing the source/computing digests if there are any che
cks to be done. |
374 if (hashAlgorithmsUsed == ContentSecurityPolicyHashAlgorithmNone) | 374 if (hashAlgorithmsUsed == ContentSecurityPolicyHashAlgorithmNone) |
375 return false; | 375 return false; |
376 | 376 |
377 StringUTF8Adaptor normalizedSource(source, StringUTF8Adaptor::Normalize, WTF
::EntitiesForUnencodables); | 377 StringUTF8Adaptor normalizedSource(source, StringUTF8Adaptor::Normalize, WTF
::EntitiesForUnencodables); |
378 | 378 |
379 // See comment in CSPSourceList::parseHash about why we are using this sizeo
f | 379 for (const auto& algorithmMap : kAlgorithmMap) { |
380 // calculation instead of WTF_ARRAY_LENGTH. | |
381 for (size_t i = 0; i < (sizeof(kAlgorithmMap) / sizeof(kAlgorithmMap[0])); i
++) { | |
382 DigestValue digest; | 380 DigestValue digest; |
383 if (kAlgorithmMap[i].cspHashAlgorithm & hashAlgorithmsUsed) { | 381 if (algorithmMap.cspHashAlgorithm & hashAlgorithmsUsed) { |
384 bool digestSuccess = computeDigest(kAlgorithmMap[i].algorithm, norma
lizedSource.data(), normalizedSource.length(), digest); | 382 bool digestSuccess = computeDigest(algorithmMap.algorithm, normalize
dSource.data(), normalizedSource.length(), digest); |
385 if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHa
shValue(kAlgorithmMap[i].cspHashAlgorithm, digest))) | 383 if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHa
shValue(algorithmMap.cspHashAlgorithm, digest))) |
386 return true; | 384 return true; |
387 } | 385 } |
388 } | 386 } |
389 | 387 |
390 return false; | 388 return false; |
391 } | 389 } |
392 | 390 |
393 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const
WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin
gStatus) const | 391 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const
WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin
gStatus) const |
394 { | 392 { |
395 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p
olicies, contextURL, contextLine, reportingStatus); | 393 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p
olicies, contextURL, contextLine, reportingStatus); |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 // Collisions have no security impact, so we can save space by storing only
the string's hash rather than the whole report. | 872 // Collisions have no security impact, so we can save space by storing only
the string's hash rather than the whole report. |
875 return !m_violationReportsSent.contains(report.impl()->hash()); | 873 return !m_violationReportsSent.contains(report.impl()->hash()); |
876 } | 874 } |
877 | 875 |
878 void ContentSecurityPolicy::didSendViolationReport(const String& report) | 876 void ContentSecurityPolicy::didSendViolationReport(const String& report) |
879 { | 877 { |
880 m_violationReportsSent.add(report.impl()->hash()); | 878 m_violationReportsSent.add(report.impl()->hash()); |
881 } | 879 } |
882 | 880 |
883 } // namespace blink | 881 } // namespace blink |
OLD | NEW |