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

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

Issue 27073003: CSP Suborigins Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Address abarth's comments Created 6 years, 2 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 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 const char ContentSecurityPolicy::FormAction[] = "form-action"; 85 const char ContentSecurityPolicy::FormAction[] = "form-action";
86 const char ContentSecurityPolicy::FrameAncestors[] = "frame-ancestors"; 86 const char ContentSecurityPolicy::FrameAncestors[] = "frame-ancestors";
87 const char ContentSecurityPolicy::PluginTypes[] = "plugin-types"; 87 const char ContentSecurityPolicy::PluginTypes[] = "plugin-types";
88 const char ContentSecurityPolicy::ReflectedXSS[] = "reflected-xss"; 88 const char ContentSecurityPolicy::ReflectedXSS[] = "reflected-xss";
89 const char ContentSecurityPolicy::Referrer[] = "referrer"; 89 const char ContentSecurityPolicy::Referrer[] = "referrer";
90 90
91 // Manifest Directives 91 // Manifest Directives
92 // https://w3c.github.io/manifest/#content-security-policy 92 // https://w3c.github.io/manifest/#content-security-policy
93 const char ContentSecurityPolicy::ManifestSrc[] = "manifest-src"; 93 const char ContentSecurityPolicy::ManifestSrc[] = "manifest-src";
94 94
95 // Experimental Directives (post CSP 1.1)
Mike West 2014/10/23 12:59:20 Nit: Since we changed the name, can you change bot
jww 2015/03/20 22:50:03 I ended up putting a "Suborigin" comment above it
96 const char ContentSecurityPolicy::Suborigin[] = "suborigin";
97
95 bool ContentSecurityPolicy::isDirectiveName(const String& name) 98 bool ContentSecurityPolicy::isDirectiveName(const String& name)
96 { 99 {
97 return (equalIgnoringCase(name, ConnectSrc) 100 return (equalIgnoringCase(name, ConnectSrc)
98 || equalIgnoringCase(name, DefaultSrc) 101 || equalIgnoringCase(name, DefaultSrc)
99 || equalIgnoringCase(name, FontSrc) 102 || equalIgnoringCase(name, FontSrc)
100 || equalIgnoringCase(name, FrameSrc) 103 || equalIgnoringCase(name, FrameSrc)
101 || equalIgnoringCase(name, ImgSrc) 104 || equalIgnoringCase(name, ImgSrc)
102 || equalIgnoringCase(name, MediaSrc) 105 || equalIgnoringCase(name, MediaSrc)
103 || equalIgnoringCase(name, ObjectSrc) 106 || equalIgnoringCase(name, ObjectSrc)
104 || equalIgnoringCase(name, ReportURI) 107 || equalIgnoringCase(name, ReportURI)
105 || equalIgnoringCase(name, Sandbox) 108 || equalIgnoringCase(name, Sandbox)
109 || equalIgnoringCase(name, Suborigin)
106 || equalIgnoringCase(name, ScriptSrc) 110 || equalIgnoringCase(name, ScriptSrc)
107 || equalIgnoringCase(name, StyleSrc) 111 || equalIgnoringCase(name, StyleSrc)
108 || equalIgnoringCase(name, BaseURI) 112 || equalIgnoringCase(name, BaseURI)
109 || equalIgnoringCase(name, ChildSrc) 113 || equalIgnoringCase(name, ChildSrc)
110 || equalIgnoringCase(name, FormAction) 114 || equalIgnoringCase(name, FormAction)
111 || equalIgnoringCase(name, FrameAncestors) 115 || equalIgnoringCase(name, FrameAncestors)
112 || equalIgnoringCase(name, PluginTypes) 116 || equalIgnoringCase(name, PluginTypes)
113 || equalIgnoringCase(name, ReflectedXSS) 117 || equalIgnoringCase(name, ReflectedXSS)
114 || equalIgnoringCase(name, Referrer) 118 || equalIgnoringCase(name, Referrer)
115 || equalIgnoringCase(name, ManifestSrc) 119 || equalIgnoringCase(name, ManifestSrc)
(...skipping 18 matching lines...) Expand all
134 return ReferrerPolicyNever; 138 return ReferrerPolicyNever;
135 return a; 139 return a;
136 } 140 }
137 141
138 ContentSecurityPolicy::ContentSecurityPolicy() 142 ContentSecurityPolicy::ContentSecurityPolicy()
139 : m_executionContext(nullptr) 143 : m_executionContext(nullptr)
140 , m_overrideInlineStyleAllowed(false) 144 , m_overrideInlineStyleAllowed(false)
141 , m_scriptHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone) 145 , m_scriptHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone)
142 , m_styleHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone) 146 , m_styleHashAlgorithmsUsed(ContentSecurityPolicyHashAlgorithmNone)
143 , m_sandboxMask(0) 147 , m_sandboxMask(0)
148 , m_suboriginName(String())
144 , m_referrerPolicy(ReferrerPolicyDefault) 149 , m_referrerPolicy(ReferrerPolicyDefault)
145 { 150 {
146 } 151 }
147 152
148 void ContentSecurityPolicy::bindToExecutionContext(ExecutionContext* executionCo ntext) 153 void ContentSecurityPolicy::bindToExecutionContext(ExecutionContext* executionCo ntext)
149 { 154 {
150 m_executionContext = executionContext; 155 m_executionContext = executionContext;
151 applyPolicySideEffectsToExecutionContext(); 156 applyPolicySideEffectsToExecutionContext();
152 } 157 }
153 158
154 void ContentSecurityPolicy::applyPolicySideEffectsToExecutionContext() 159 void ContentSecurityPolicy::applyPolicySideEffectsToExecutionContext()
155 { 160 {
156 ASSERT(m_executionContext); 161 ASSERT(m_executionContext);
157 // Ensure that 'self' processes correctly. 162 // Ensure that 'self' processes correctly.
158 m_selfProtocol = securityOrigin()->protocol(); 163 m_selfProtocol = securityOrigin()->protocol();
159 m_selfSource = adoptPtr(new CSPSource(this, m_selfProtocol, securityOrigin() ->host(), securityOrigin()->port(), String(), CSPSource::NoWildcard, CSPSource:: NoWildcard)); 164 m_selfSource = adoptPtr(new CSPSource(this, m_selfProtocol, securityOrigin() ->host(), securityOrigin()->port(), String(), CSPSource::NoWildcard, CSPSource:: NoWildcard));
160 165
161 // If we're in a Document, set the referrer policy and sandbox flags, then d ump all the 166 // If we're in a Document, set the referrer policy and sandbox flags, then d ump all the
162 // parsing error messages, then poke at histograms. 167 // parsing error messages, then poke at histograms.
163 if (Document* document = this->document()) { 168 if (Document* document = this->document()) {
164 document->enforceSandboxFlags(m_sandboxMask); 169 document->enforceSandboxFlags(m_sandboxMask);
170 if (experimentalFeaturesEnabled())
Mike West 2014/10/23 12:59:20 `&& hasSuborigin`?
jww 2015/03/20 22:50:03 Enforce only "turns on" Suborigins if the Suborigi
171 document->enforceSuborigin(m_suboriginName);
165 if (didSetReferrerPolicy()) 172 if (didSetReferrerPolicy())
166 document->setReferrerPolicy(m_referrerPolicy); 173 document->setReferrerPolicy(m_referrerPolicy);
167 174
168 for (const auto& consoleMessage : m_consoleMessages) 175 for (const auto& consoleMessage : m_consoleMessages)
169 m_executionContext->addConsoleMessage(consoleMessage); 176 m_executionContext->addConsoleMessage(consoleMessage);
170 m_consoleMessages.clear(); 177 m_consoleMessages.clear();
171 178
172 for (const auto& policy : m_policies) 179 for (const auto& policy : m_policies)
173 UseCounter::count(*document, getUseCounterType(policy->headerType()) ); 180 UseCounter::count(*document, getUseCounterType(policy->headerType()) );
174 } 181 }
(...skipping 419 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 KURL ContentSecurityPolicy::completeURL(const String& url) const 601 KURL ContentSecurityPolicy::completeURL(const String& url) const
595 { 602 {
596 return m_executionContext->contextCompleteURL(url); 603 return m_executionContext->contextCompleteURL(url);
597 } 604 }
598 605
599 void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask) 606 void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask)
600 { 607 {
601 m_sandboxMask |= mask; 608 m_sandboxMask |= mask;
602 } 609 }
603 610
611 void ContentSecurityPolicy::enforceSuborigin(const String& name)
612 {
613 m_suboriginName = name;
614 }
615
604 static String stripURLForUseInReport(Document* document, const KURL& url) 616 static String stripURLForUseInReport(Document* document, const KURL& url)
605 { 617 {
606 if (!url.isValid()) 618 if (!url.isValid())
607 return String(); 619 return String();
608 if (!url.isHierarchical() || url.protocolIs("file")) 620 if (!url.isHierarchical() || url.protocolIs("file"))
609 return url.protocol(); 621 return url.protocol();
610 return document->securityOrigin()->canRequest(url) ? url.strippedForUseAsRef errer() : SecurityOrigin::create(url)->toString(); 622 return document->securityOrigin()->canRequest(url) ? url.strippedForUseAsRef errer() : SecurityOrigin::create(url)->toString();
611 } 623 }
612 624
613 static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventI nit& init, Document* document, const String& directiveText, const String& effect iveDirective, const KURL& blockedURL, const String& header) 625 static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventI nit& init, Document* document, const String& directiveText, const String& effect iveDirective, const KURL& blockedURL, const String& header)
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 else 792 else
781 message = "Invalid plugin type in 'plugin-types' Content Security Policy directive: '" + pluginType + "'.\n"; 793 message = "Invalid plugin type in 'plugin-types' Content Security Policy directive: '" + pluginType + "'.\n";
782 logToConsole(message); 794 logToConsole(message);
783 } 795 }
784 796
785 void ContentSecurityPolicy::reportInvalidSandboxFlags(const String& invalidFlags ) 797 void ContentSecurityPolicy::reportInvalidSandboxFlags(const String& invalidFlags )
786 { 798 {
787 logToConsole("Error while parsing the 'sandbox' Content Security Policy dire ctive: " + invalidFlags); 799 logToConsole("Error while parsing the 'sandbox' Content Security Policy dire ctive: " + invalidFlags);
788 } 800 }
789 801
802 void ContentSecurityPolicy::reportInvalidSuboriginFlags(const String& invalidFla gs)
803 {
804 logToConsole("Error while parsing the 'suborigin' Content Security Policy di rective: " + invalidFlags);
805 }
806
790 void ContentSecurityPolicy::reportInvalidReflectedXSS(const String& invalidValue ) 807 void ContentSecurityPolicy::reportInvalidReflectedXSS(const String& invalidValue )
791 { 808 {
792 logToConsole("The 'reflected-xss' Content Security Policy directive has the invalid value \"" + invalidValue + "\". Valid values are \"allow\", \"filter\", and \"block\"."); 809 logToConsole("The 'reflected-xss' Content Security Policy directive has the invalid value \"" + invalidValue + "\". Valid values are \"allow\", \"filter\", and \"block\".");
793 } 810 }
794 811
795 void ContentSecurityPolicy::reportInvalidDirectiveValueCharacter(const String& d irectiveName, const String& value) 812 void ContentSecurityPolicy::reportInvalidDirectiveValueCharacter(const String& d irectiveName, const String& value)
796 { 813 {
797 String message = "The value for Content Security Policy directive '" + direc tiveName + "' contains an invalid character: '" + value + "'. Non-whitespace cha racters outside ASCII 0x21-0x7E must be percent-encoded, as described in RFC 398 6, section 2.1: http://tools.ietf.org/html/rfc3986#section-2.1."; 814 String message = "The value for Content Security Policy directive '" + direc tiveName + "' contains an invalid character: '" + value + "'. Non-whitespace cha racters outside ASCII 0x21-0x7E must be percent-encoded, as described in RFC 398 6, section 2.1: http://tools.ietf.org/html/rfc3986#section-2.1.";
798 logToConsole(message); 815 logToConsole(message);
799 } 816 }
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. 891 // 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()); 892 return !m_violationReportsSent.contains(report.impl()->hash());
876 } 893 }
877 894
878 void ContentSecurityPolicy::didSendViolationReport(const String& report) 895 void ContentSecurityPolicy::didSendViolationReport(const String& report)
879 { 896 {
880 m_violationReportsSent.add(report.impl()->hash()); 897 m_violationReportsSent.add(report.impl()->hash());
881 } 898 }
882 899
883 } // namespace blink 900 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698