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

Side by Side Diff: Source/core/frame/csp/ContentSecurityPolicy.cpp

Issue 1009583003: Add CSP header for resources with an active policy (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: test tweaks Created 5 years, 9 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
OLDNEW
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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 if (algorithmMap.cspHashAlgorithm & hashAlgorithmsUsed) { 414 if (algorithmMap.cspHashAlgorithm & hashAlgorithmsUsed) {
415 bool digestSuccess = computeDigest(algorithmMap.algorithm, normalize dSource.data(), normalizedSource.length(), digest); 415 bool digestSuccess = computeDigest(algorithmMap.algorithm, normalize dSource.data(), normalizedSource.length(), digest);
416 if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHa shValue(algorithmMap.cspHashAlgorithm, digest))) 416 if (digestSuccess && isAllowedByAllWithHash<allowed>(policies, CSPHa shValue(algorithmMap.cspHashAlgorithm, digest)))
417 return true; 417 return true;
418 } 418 }
419 } 419 }
420 420
421 return false; 421 return false;
422 } 422 }
423 423
424 template <bool (CSPDirectiveList::*hasPolicy)() const>
425 bool hasAnyPolicy(const CSPDirectiveListVector& policies)
426 {
427 for (const auto& policy : policies) {
428 if ((policy.get()->*hasPolicy)())
429 return true;
430 }
431 return false;
432 }
433
424 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin gStatus) const 434 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportin gStatus) const
425 { 435 {
426 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p olicies, contextURL, contextLine, reportingStatus); 436 return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_p olicies, contextURL, contextLine, reportingStatus);
427 } 437 }
428 438
429 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, c onst WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus rep ortingStatus) const 439 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, c onst WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus rep ortingStatus) const
430 { 440 {
431 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers >(m_policies, contextURL, contextLine, reportingStatus); 441 return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers >(m_policies, contextURL, contextLine, reportingStatus);
432 } 442 }
433 443
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
893 void ContentSecurityPolicy::reportBlockedScriptExecutionToInspector(const String & directiveText) const 903 void ContentSecurityPolicy::reportBlockedScriptExecutionToInspector(const String & directiveText) const
894 { 904 {
895 m_executionContext->reportBlockedScriptExecutionToInspector(directiveText); 905 m_executionContext->reportBlockedScriptExecutionToInspector(directiveText);
896 } 906 }
897 907
898 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const 908 bool ContentSecurityPolicy::experimentalFeaturesEnabled() const
899 { 909 {
900 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab led(); 910 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab led();
901 } 911 }
902 912
913 bool ContentSecurityPolicy::hasScriptPolicy() const
914 {
915 return hasAnyPolicy<&CSPDirectiveList::hasScriptPolicy>(m_policies);
916 }
917
918 bool ContentSecurityPolicy::hasStylePolicy() const
919 {
920 return hasAnyPolicy<&CSPDirectiveList::hasStylePolicy>(m_policies);
921 }
922
923 bool ContentSecurityPolicy::hasImagePolicy() const
924 {
925 return hasAnyPolicy<&CSPDirectiveList::hasImagePolicy>(m_policies);
926 }
927
928 bool ContentSecurityPolicy::hasFontPolicy() const
929 {
930 return hasAnyPolicy<&CSPDirectiveList::hasFontPolicy>(m_policies);
931 }
932
933 bool ContentSecurityPolicy::hasMediaPolicy() const
934 {
935 return hasAnyPolicy<&CSPDirectiveList::hasMediaPolicy>(m_policies);
936 }
937
938 bool ContentSecurityPolicy::hasPluginPolicy() const
939 {
940 return hasAnyPolicy<&CSPDirectiveList::hasPluginPolicy>(m_policies);
941 }
942
903 bool ContentSecurityPolicy::urlMatchesSelf(const KURL& url) const 943 bool ContentSecurityPolicy::urlMatchesSelf(const KURL& url) const
904 { 944 {
905 return m_selfSource->matches(url, DidNotRedirect); 945 return m_selfSource->matches(url, DidNotRedirect);
906 } 946 }
907 947
908 bool ContentSecurityPolicy::protocolMatchesSelf(const KURL& url) const 948 bool ContentSecurityPolicy::protocolMatchesSelf(const KURL& url) const
909 { 949 {
910 if (equalIgnoringCase("http", m_selfProtocol)) 950 if (equalIgnoringCase("http", m_selfProtocol))
911 return url.protocolIsInHTTPFamily(); 951 return url.protocolIsInHTTPFamily();
912 return equalIgnoringCase(url.protocol(), m_selfProtocol); 952 return equalIgnoringCase(url.protocol(), m_selfProtocol);
(...skipping 14 matching lines...) Expand all
927 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. 967 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report.
928 return !m_violationReportsSent.contains(report.impl()->hash()); 968 return !m_violationReportsSent.contains(report.impl()->hash());
929 } 969 }
930 970
931 void ContentSecurityPolicy::didSendViolationReport(const String& report) 971 void ContentSecurityPolicy::didSendViolationReport(const String& report)
932 { 972 {
933 m_violationReportsSent.add(report.impl()->hash()); 973 m_violationReportsSent.add(report.impl()->hash());
934 } 974 }
935 975
936 } // namespace blink 976 } // namespace blink
OLDNEW
« Source/core/frame/csp/CSPDirectiveList.cpp ('K') | « Source/core/frame/csp/ContentSecurityPolicy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698