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

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: Rebase Created 6 years, 6 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 81
82 // CSP 1.1 Directives 82 // CSP 1.1 Directives
83 const char ContentSecurityPolicy::BaseURI[] = "base-uri"; 83 const char ContentSecurityPolicy::BaseURI[] = "base-uri";
84 const char ContentSecurityPolicy::ChildSrc[] = "child-src"; 84 const char ContentSecurityPolicy::ChildSrc[] = "child-src";
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 // Experimental Directives (post CSP 1.1)
92 const char ContentSecurityPolicy::Suborigin[] = "suborigin";
93
91 bool ContentSecurityPolicy::isDirectiveName(const String& name) 94 bool ContentSecurityPolicy::isDirectiveName(const String& name)
92 { 95 {
93 return (equalIgnoringCase(name, ConnectSrc) 96 return (equalIgnoringCase(name, ConnectSrc)
94 || equalIgnoringCase(name, DefaultSrc) 97 || equalIgnoringCase(name, DefaultSrc)
95 || equalIgnoringCase(name, FontSrc) 98 || equalIgnoringCase(name, FontSrc)
96 || equalIgnoringCase(name, FrameSrc) 99 || equalIgnoringCase(name, FrameSrc)
97 || equalIgnoringCase(name, ImgSrc) 100 || equalIgnoringCase(name, ImgSrc)
98 || equalIgnoringCase(name, MediaSrc) 101 || equalIgnoringCase(name, MediaSrc)
99 || equalIgnoringCase(name, ObjectSrc) 102 || equalIgnoringCase(name, ObjectSrc)
100 || equalIgnoringCase(name, ReportURI) 103 || equalIgnoringCase(name, ReportURI)
101 || equalIgnoringCase(name, Sandbox) 104 || equalIgnoringCase(name, Sandbox)
102 || equalIgnoringCase(name, ScriptSrc) 105 || equalIgnoringCase(name, ScriptSrc)
106 || equalIgnoringCase(name, Suborigin)
103 || equalIgnoringCase(name, StyleSrc) 107 || equalIgnoringCase(name, StyleSrc)
104 || equalIgnoringCase(name, BaseURI) 108 || equalIgnoringCase(name, BaseURI)
105 || equalIgnoringCase(name, ChildSrc) 109 || equalIgnoringCase(name, ChildSrc)
106 || equalIgnoringCase(name, FormAction) 110 || equalIgnoringCase(name, FormAction)
107 || equalIgnoringCase(name, FrameAncestors) 111 || equalIgnoringCase(name, FrameAncestors)
108 || equalIgnoringCase(name, PluginTypes) 112 || equalIgnoringCase(name, PluginTypes)
109 || equalIgnoringCase(name, ReflectedXSS) 113 || equalIgnoringCase(name, ReflectedXSS)
110 || equalIgnoringCase(name, Referrer) 114 || equalIgnoringCase(name, Referrer)
111 ); 115 );
112 } 116 }
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
539 { 543 {
540 return m_client->contextCompleteURL(url); 544 return m_client->contextCompleteURL(url);
541 } 545 }
542 546
543 void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask) const 547 void ContentSecurityPolicy::enforceSandboxFlags(SandboxFlags mask) const
544 { 548 {
545 if (Document* document = this->document()) 549 if (Document* document = this->document())
546 document->enforceSandboxFlags(mask); 550 document->enforceSandboxFlags(mask);
547 } 551 }
548 552
553 void ContentSecurityPolicy::enforceSuborigin(String name) const
abarth-chromium 2014/07/31 04:56:47 const String&
jww 2014/10/21 23:51:06 Done.
554 {
555 if (m_client->isDocument())
556 static_cast<Document*>(m_client)->enforceSuborigin(name);
557 }
558
549 static String stripURLForUseInReport(Document* document, const KURL& url) 559 static String stripURLForUseInReport(Document* document, const KURL& url)
550 { 560 {
551 if (!url.isValid()) 561 if (!url.isValid())
552 return String(); 562 return String();
553 if (!url.isHierarchical() || url.protocolIs("file")) 563 if (!url.isHierarchical() || url.protocolIs("file"))
554 return url.protocol(); 564 return url.protocol();
555 return document->securityOrigin()->canRequest(url) ? url.strippedForUseAsRef errer() : SecurityOrigin::create(url)->toString(); 565 return document->securityOrigin()->canRequest(url) ? url.strippedForUseAsRef errer() : SecurityOrigin::create(url)->toString();
556 } 566 }
557 567
558 static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventI nit& init, Document* document, const String& directiveText, const String& effect iveDirective, const KURL& blockedURL, const String& header) 568 static void gatherSecurityPolicyViolationEventData(SecurityPolicyViolationEventI nit& init, Document* document, const String& directiveText, const String& effect iveDirective, const KURL& blockedURL, const String& header)
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 else 715 else
706 message = "Invalid plugin type in 'plugin-types' Content Security Policy directive: '" + pluginType + "'.\n"; 716 message = "Invalid plugin type in 'plugin-types' Content Security Policy directive: '" + pluginType + "'.\n";
707 logToConsole(message); 717 logToConsole(message);
708 } 718 }
709 719
710 void ContentSecurityPolicy::reportInvalidSandboxFlags(const String& invalidFlags ) const 720 void ContentSecurityPolicy::reportInvalidSandboxFlags(const String& invalidFlags ) const
711 { 721 {
712 logToConsole("Error while parsing the 'sandbox' Content Security Policy dire ctive: " + invalidFlags); 722 logToConsole("Error while parsing the 'sandbox' Content Security Policy dire ctive: " + invalidFlags);
713 } 723 }
714 724
725 void ContentSecurityPolicy::reportInvalidSuboriginFlags(const String& invalidFla gs) const
726 {
727 logToConsole("Error while parsing the 'suborigin' Content Security Policy di rective: " + invalidFlags);
728 }
729
715 void ContentSecurityPolicy::reportInvalidReflectedXSS(const String& invalidValue ) const 730 void ContentSecurityPolicy::reportInvalidReflectedXSS(const String& invalidValue ) const
716 { 731 {
717 logToConsole("The 'reflected-xss' Content Security Policy directive has the invalid value \"" + invalidValue + "\". Valid values are \"allow\", \"filter\", and \"block\"."); 732 logToConsole("The 'reflected-xss' Content Security Policy directive has the invalid value \"" + invalidValue + "\". Valid values are \"allow\", \"filter\", and \"block\".");
718 } 733 }
719 734
720 void ContentSecurityPolicy::reportInvalidDirectiveValueCharacter(const String& d irectiveName, const String& value) const 735 void ContentSecurityPolicy::reportInvalidDirectiveValueCharacter(const String& d irectiveName, const String& value) const
721 { 736 {
722 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."; 737 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.";
723 logToConsole(message); 738 logToConsole(message);
724 } 739 }
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report. 792 // Collisions have no security impact, so we can save space by storing only the string's hash rather than the whole report.
778 return !m_violationReportsSent.contains(report.impl()->hash()); 793 return !m_violationReportsSent.contains(report.impl()->hash());
779 } 794 }
780 795
781 void ContentSecurityPolicy::didSendViolationReport(const String& report) 796 void ContentSecurityPolicy::didSendViolationReport(const String& report)
782 { 797 {
783 m_violationReportsSent.add(report.impl()->hash()); 798 m_violationReportsSent.add(report.impl()->hash());
784 } 799 }
785 800
786 } // namespace WebCore 801 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698