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 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 void ContentSecurityPolicy::bindToExecutionContext(ExecutionContext* executionCo
ntext) | 148 void ContentSecurityPolicy::bindToExecutionContext(ExecutionContext* executionCo
ntext) |
149 { | 149 { |
150 m_executionContext = executionContext; | 150 m_executionContext = executionContext; |
151 applyPolicySideEffectsToExecutionContext(); | 151 applyPolicySideEffectsToExecutionContext(); |
152 } | 152 } |
153 | 153 |
154 void ContentSecurityPolicy::applyPolicySideEffectsToExecutionContext() | 154 void ContentSecurityPolicy::applyPolicySideEffectsToExecutionContext() |
155 { | 155 { |
156 ASSERT(m_executionContext); | 156 ASSERT(m_executionContext); |
157 // Ensure that 'self' processes correctly. | 157 // Ensure that 'self' processes correctly. |
158 m_selfSource = adoptPtr(new CSPSource(this, securityOrigin()->protocol(), se
curityOrigin()->host(), securityOrigin()->port(), String(), CSPSource::NoWildcar
d, CSPSource::NoWildcard)); | 158 m_selfProtocol = securityOrigin()->protocol(); |
| 159 m_selfSource = adoptPtr(new CSPSource(this, m_selfProtocol, securityOrigin()
->host(), securityOrigin()->port(), String(), CSPSource::NoWildcard, CSPSource::
NoWildcard)); |
159 | 160 |
160 // If we're in a Document, set the referrer policy and sandbox flags, then d
ump all the | 161 // If we're in a Document, set the referrer policy and sandbox flags, then d
ump all the |
161 // parsing error messages, then poke at histograms. | 162 // parsing error messages, then poke at histograms. |
162 if (Document* document = this->document()) { | 163 if (Document* document = this->document()) { |
163 document->enforceSandboxFlags(m_sandboxMask); | 164 document->enforceSandboxFlags(m_sandboxMask); |
164 if (didSetReferrerPolicy()) | 165 if (didSetReferrerPolicy()) |
165 document->setReferrerPolicy(m_referrerPolicy); | 166 document->setReferrerPolicy(m_referrerPolicy); |
166 | 167 |
167 for (ConsoleMessageVector::const_iterator iter = m_consoleMessages.begin
(); iter != m_consoleMessages.end(); ++iter) | 168 for (ConsoleMessageVector::const_iterator iter = m_consoleMessages.begin
(); iter != m_consoleMessages.end(); ++iter) |
168 m_executionContext->addConsoleMessage(*iter); | 169 m_executionContext->addConsoleMessage(*iter); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
259 { | 260 { |
260 m_overrideInlineStyleAllowed = value; | 261 m_overrideInlineStyleAllowed = value; |
261 } | 262 } |
262 | 263 |
263 void ContentSecurityPolicy::setOverrideURLForSelf(const KURL& url) | 264 void ContentSecurityPolicy::setOverrideURLForSelf(const KURL& url) |
264 { | 265 { |
265 // Create a temporary CSPSource so that 'self' expressions can be resolved b
efore we bind to | 266 // Create a temporary CSPSource so that 'self' expressions can be resolved b
efore we bind to |
266 // an execution context (for 'frame-ancestor' resolution, for example). This
CSPSource will | 267 // an execution context (for 'frame-ancestor' resolution, for example). This
CSPSource will |
267 // be overwritten when we bind this object to an execution context. | 268 // be overwritten when we bind this object to an execution context. |
268 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url); | 269 RefPtr<SecurityOrigin> origin = SecurityOrigin::create(url); |
269 m_selfSource = adoptPtr(new CSPSource(this, origin->protocol(), origin->host
(), origin->port(), String(), CSPSource::NoWildcard, CSPSource::NoWildcard)); | 270 m_selfProtocol = origin->protocol(); |
| 271 m_selfSource = adoptPtr(new CSPSource(this, m_selfProtocol, origin->host(),
origin->port(), String(), CSPSource::NoWildcard, CSPSource::NoWildcard)); |
270 } | 272 } |
271 | 273 |
272 const String& ContentSecurityPolicy::deprecatedHeader() const | 274 const String& ContentSecurityPolicy::deprecatedHeader() const |
273 { | 275 { |
274 return m_policies.isEmpty() ? emptyString() : m_policies[0]->header(); | 276 return m_policies.isEmpty() ? emptyString() : m_policies[0]->header(); |
275 } | 277 } |
276 | 278 |
277 ContentSecurityPolicyHeaderType ContentSecurityPolicy::deprecatedHeaderType() co
nst | 279 ContentSecurityPolicyHeaderType ContentSecurityPolicy::deprecatedHeaderType() co
nst |
278 { | 280 { |
279 return m_policies.isEmpty() ? ContentSecurityPolicyHeaderTypeEnforce : m_pol
icies[0]->headerType(); | 281 return m_policies.isEmpty() ? ContentSecurityPolicyHeaderTypeEnforce : m_pol
icies[0]->headerType(); |
(...skipping 565 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab
led(); | 847 return RuntimeEnabledFeatures::experimentalContentSecurityPolicyFeaturesEnab
led(); |
846 } | 848 } |
847 | 849 |
848 bool ContentSecurityPolicy::urlMatchesSelf(const KURL& url) const | 850 bool ContentSecurityPolicy::urlMatchesSelf(const KURL& url) const |
849 { | 851 { |
850 return m_selfSource->matches(url); | 852 return m_selfSource->matches(url); |
851 } | 853 } |
852 | 854 |
853 bool ContentSecurityPolicy::protocolMatchesSelf(const KURL& url) const | 855 bool ContentSecurityPolicy::protocolMatchesSelf(const KURL& url) const |
854 { | 856 { |
855 String protectedResourceScheme(securityOrigin()->protocol()); | 857 if (equalIgnoringCase("http", m_selfProtocol)) |
856 if (equalIgnoringCase("http", protectedResourceScheme)) | |
857 return url.protocolIsInHTTPFamily(); | 858 return url.protocolIsInHTTPFamily(); |
858 return equalIgnoringCase(url.protocol(), protectedResourceScheme); | 859 return equalIgnoringCase(url.protocol(), m_selfProtocol); |
859 } | 860 } |
860 | 861 |
861 bool ContentSecurityPolicy::shouldBypassMainWorld(ExecutionContext* context) | 862 bool ContentSecurityPolicy::shouldBypassMainWorld(ExecutionContext* context) |
862 { | 863 { |
863 if (context && context->isDocument()) { | 864 if (context && context->isDocument()) { |
864 Document* document = toDocument(context); | 865 Document* document = toDocument(context); |
865 if (document->frame()) | 866 if (document->frame()) |
866 return document->frame()->script().shouldBypassMainWorldCSP(); | 867 return document->frame()->script().shouldBypassMainWorldCSP(); |
867 } | 868 } |
868 return false; | 869 return false; |
869 } | 870 } |
870 | 871 |
871 bool ContentSecurityPolicy::shouldSendViolationReport(const String& report) cons
t | 872 bool ContentSecurityPolicy::shouldSendViolationReport(const String& report) cons
t |
872 { | 873 { |
873 // Collisions have no security impact, so we can save space by storing only
the string's hash rather than the whole report. | 874 // Collisions have no security impact, so we can save space by storing only
the string's hash rather than the whole report. |
874 return !m_violationReportsSent.contains(report.impl()->hash()); | 875 return !m_violationReportsSent.contains(report.impl()->hash()); |
875 } | 876 } |
876 | 877 |
877 void ContentSecurityPolicy::didSendViolationReport(const String& report) | 878 void ContentSecurityPolicy::didSendViolationReport(const String& report) |
878 { | 879 { |
879 m_violationReportsSent.add(report.impl()->hash()); | 880 m_violationReportsSent.add(report.impl()->hash()); |
880 } | 881 } |
881 | 882 |
882 } // namespace blink | 883 } // namespace blink |
OLD | NEW |