Diff
Modified: trunk/LayoutTests/ChangeLog (199162 => 199163)
--- trunk/LayoutTests/ChangeLog 2016-04-07 17:59:24 UTC (rev 199162)
+++ trunk/LayoutTests/ChangeLog 2016-04-07 18:03:04 UTC (rev 199163)
@@ -1,3 +1,23 @@
+2016-04-07 Daniel Bates <[email protected]>
+
+ CSP: Should only honor CSP policy delivered in meta tag that is a descendent of <head>
+ https://bugs.webkit.org/show_bug.cgi?id=59858
+ <rdar://problem/25603538>
+
+ Reviewed by Brent Fulgham.
+
+ Add tests to ensure that we ignore the meta tags for Content-Security-Policy, Content-Security-Policy-Report-Only,
+ X-WebKit-CSP, and X-WebKit-CSP-Report-Only if it is not a descendent of <head>.
+
+ * http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head-expected.txt: Added.
+ * http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head.html: Added.
+ * http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2-expected.txt: Added.
+ * http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2.html: Added.
+ * http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head-expected.txt: Added.
+ * http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head.html: Added.
+ * http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2-expected.txt: Added.
+ * http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2.html: Added.
+
2016-04-06 Sam Weinig <[email protected]>
window.Crypto is missing
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head-expected.txt (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head-expected.txt 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1,3 @@
+This tests that a <meta http-equiv="Content-Security-Policy"> is ignored if it is not a descendent of <head>.
+
+PASS Content Security Policy was ignored.
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head.html (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head.html 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1,17 @@
+<!DOCTYPE>
+<html>
+<head>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<p>This tests that a <meta http-equiv="Content-Security-Policy"> is ignored if it is not a descendent of <head>.</p>
+<meta http-equiv="Content-Security-Policy" content="script-src 'self'">
+<p id="result">FAIL Content Security Policy should have been ignored. But was honored.</p>
+<script>
+document.getElementById("result").textContent = 'PASS Content Security Policy was ignored.';
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2-expected.txt (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2-expected.txt 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1,3 @@
+This tests that a <meta http-equiv="X-WebKit-CSP"> is ignored if it is not a descendent of <head>.
+
+PASS Content Security Policy was ignored.
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2.html (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2.html 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1,17 @@
+<!DOCTYPE>
+<html>
+<head>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<p>This tests that a <meta http-equiv="X-WebKit-CSP"> is ignored if it is not a descendent of <head>.</p>
+<meta http-equiv="X-WebKit-CSP" content="script-src 'self'">
+<p id="result">FAIL Content Security Policy should have been ignored. But was honored.</p>
+<script>
+document.getElementById("result").textContent = 'PASS Content Security Policy was ignored.';
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head-expected.txt (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head-expected.txt 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1 @@
+This tests that a <meta http-equiv="Content-Security-Policy-Report-Only"> is ignored if it is not a descendent of <head>. This test PASSED if there are no console warnings. Otherwise, it FAILED.
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head.html (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head.html 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1,16 @@
+<!DOCTYPE>
+<html>
+<head>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<p>This tests that a <meta http-equiv="Content-Security-Policy-Report-Only"> is ignored if it is not a descendent of <head>. This test PASSED if there are no console warnings. Otherwise, it FAILED.</p>
+<meta http-equiv="Content-Security-Policy-Report-Only" content="script-src 'self'">
+<script>
+// Do nothing
+</script>
+</body>
+</html>
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2-expected.txt (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2-expected.txt (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2-expected.txt 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1 @@
+This tests that a <meta http-equiv="X-WebKit-CSP-Report-Only"> is ignored if it is not a descendent of <head>. This test PASSED if there are no console warnings. Otherwise, it FAILED.
Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2.html (0 => 199163)
--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2.html (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2.html 2016-04-07 18:03:04 UTC (rev 199163)
@@ -0,0 +1,16 @@
+<!DOCTYPE>
+<html>
+<head>
+<script>
+if (window.testRunner)
+ testRunner.dumpAsText();
+</script>
+</head>
+<body>
+<p>This tests that a <meta http-equiv="X-WebKit-CSP-Report-Only"> is ignored if it is not a descendent of <head>. This test PASSED if there are no console warnings. Otherwise, it FAILED.</p>
+<meta http-equiv="X-WebKit-CSP-Report-Only" content="script-src 'self'">
+<script>
+// Do nothing
+</script>
+</body>
+</html>
Modified: trunk/Source/WebCore/ChangeLog (199162 => 199163)
--- trunk/Source/WebCore/ChangeLog 2016-04-07 17:59:24 UTC (rev 199162)
+++ trunk/Source/WebCore/ChangeLog 2016-04-07 18:03:04 UTC (rev 199163)
@@ -1,3 +1,31 @@
+2016-04-07 Daniel Bates <[email protected]>
+
+ CSP: Should only honor CSP policy delivered in meta tag that is a descendent of <head>
+ https://bugs.webkit.org/show_bug.cgi?id=59858
+ <rdar://problem/25603538>
+
+ Reviewed by Brent Fulgham.
+
+ Ignore the Content Security Policy meta tag if it is not a descendent of <head> as per
+ section HTML meta Element of the Content Security Policy Level 2 spec., <https://w3c.github.io/webappsec-csp/2/>
+ (Editor's Draft, 29 August 2015).
+
+ Tests: http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head.html
+ http/tests/security/contentSecurityPolicy/meta-tag-ignored-if-not-in-head2.html
+ http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head.html
+ http/tests/security/contentSecurityPolicy/report-only-meta-tag-ignored-if-not-in-head2.html
+
+ * dom/Document.cpp:
+ (WebCore::Document::processHttpEquiv): Modified to take a boolean argument whether the http-equiv
+ meta tag is a descendent of <head> and to parse the value of a Content Security Policy http-equiv
+ only if the http-equiv meta tag is a descendent of <head>.
+ * dom/Document.h: Add parameter isInDocument to processHttpEquiv(). Remove javadoc-style parameters
+ from processHttpEquiv() comment as we do not document parameters for non-API functions using such style.
+ Also write the comment for processHttpEquiv() using C++ style comments instead of a C-style comment.
+ * html/HTMLMetaElement.cpp:
+ (WebCore::HTMLMetaElement::process): Pass whether this element is a descendent of <head>. Additionally
+ update stale comment and move it closer to the code it refers to.
+
2016-04-07 Brent Fulgham <[email protected]>
[Win] Output WebCore.pdb to the same location as WebCore.lib
Modified: trunk/Source/WebCore/dom/Document.cpp (199162 => 199163)
--- trunk/Source/WebCore/dom/Document.cpp 2016-04-07 17:59:24 UTC (rev 199162)
+++ trunk/Source/WebCore/dom/Document.cpp 2016-04-07 18:03:04 UTC (rev 199163)
@@ -3219,9 +3219,10 @@
return authorSheets.usesStyleBasedEditability();
}
-void Document::processHttpEquiv(const String& equiv, const String& content)
+void Document::processHttpEquiv(const String& equiv, const String& content, bool isInDocumentHead)
{
- ASSERT(!equiv.isNull() && !content.isNull());
+ ASSERT(!equiv.isNull());
+ ASSERT(!content.isNull());
HttpEquivPolicy policy = httpEquivPolicy();
if (policy != HttpEquivPolicy::Enabled) {
@@ -3316,19 +3317,23 @@
break;
case HTTPHeaderName::ContentSecurityPolicy:
- contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::Enforce);
+ if (isInDocumentHead)
+ contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::Enforce);
break;
case HTTPHeaderName::ContentSecurityPolicyReportOnly:
- contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::Report);
+ if (isInDocumentHead)
+ contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::Report);
break;
case HTTPHeaderName::XWebKitCSP:
- contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::PrefixedEnforce);
+ if (isInDocumentHead)
+ contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::PrefixedEnforce);
break;
case HTTPHeaderName::XWebKitCSPReportOnly:
- contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::PrefixedReport);
+ if (isInDocumentHead)
+ contentSecurityPolicy()->processHTTPEquiv(content, ContentSecurityPolicyHeaderType::PrefixedReport);
break;
default:
Modified: trunk/Source/WebCore/dom/Document.h (199162 => 199163)
--- trunk/Source/WebCore/dom/Document.h 2016-04-07 17:59:24 UTC (rev 199162)
+++ trunk/Source/WebCore/dom/Document.h 2016-04-07 18:03:04 UTC (rev 199163)
@@ -826,16 +826,11 @@
CSSStyleDeclaration* getOverrideStyle(Element*, const String& pseudoElt);
- /**
- * Handles a HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
- * when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
- * tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
- * specified in a HTML file.
- *
- * @param equiv The http header name (value of the meta tag's "equiv" attribute)
- * @param content The header value (value of the meta tag's "content" attribute)
- */
- void processHttpEquiv(const String& equiv, const String& content);
+ // Handles an HTTP header equivalent set by a meta tag using <meta http-equiv="..." content="...">. This is called
+ // when a meta tag is encountered during document parsing, and also when a script dynamically changes or adds a meta
+ // tag. This enables scripts to use meta tags to perform refreshes and set expiry dates in addition to them being
+ // specified in an HTML file.
+ void processHttpEquiv(const String& equiv, const String& content, bool isInDocumentHead);
#if PLATFORM(IOS)
void processFormatDetection(const String&);
Modified: trunk/Source/WebCore/html/HTMLMetaElement.cpp (199162 => 199163)
--- trunk/Source/WebCore/html/HTMLMetaElement.cpp 2016-04-07 17:59:24 UTC (rev 199162)
+++ trunk/Source/WebCore/html/HTMLMetaElement.cpp 2016-04-07 18:03:04 UTC (rev 199163)
@@ -25,6 +25,7 @@
#include "Attribute.h"
#include "Document.h"
+#include "HTMLHeadElement.h"
#include "HTMLNames.h"
namespace WebCore {
@@ -64,6 +65,7 @@
void HTMLMetaElement::process()
{
+ // Changing a meta tag while it's not in the tree shouldn't have any effect on the document.
if (!inDocument())
return;
@@ -82,11 +84,9 @@
else if (equalLettersIgnoringASCIICase(name(), "referrer"))
document().processReferrerPolicy(contentValue);
- // Get the document to process the tag, but only if we're actually part of DOM tree (changing a meta tag while
- // it's not in the tree shouldn't have any effect on the document)
const AtomicString& httpEquivValue = fastGetAttribute(http_equivAttr);
if (!httpEquivValue.isNull())
- document().processHttpEquiv(httpEquivValue, contentValue);
+ document().processHttpEquiv(httpEquivValue, contentValue, isDescendantOf(document().head()));
}
const AtomicString& HTMLMetaElement::content() const