Title: [99383] trunk
Revision
99383
Author
[email protected]
Date
2011-11-06 13:31:45 -0800 (Sun, 06 Nov 2011)

Log Message

Implement the sandbox directive for CSP
https://bugs.webkit.org/show_bug.cgi?id=71604

Reviewed by Sam Weinig.

Source/WebCore:

At TPAC, Microsoft was pushing pretty hard to add the sandbox directive
to CSP.  There's a question about whether it's going to be in CSP 1.0
or CSP 1.1, but it seems to be clearly headed into the spec.

This patch implements the sandbox directive for CSP.  It's built on the
same machinery we use for the sandbox attribute for iframe.  Now that
I've done the implementation, I'm going to write up some concrete text
for the spec.

Tests: http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html
       http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html
       http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html
       http/tests/security/contentSecurityPolicy/sandbox-empty.html

* page/ContentSecurityPolicy.cpp:
(WebCore::ContentSecurityPolicy::ContentSecurityPolicy):
(WebCore::ContentSecurityPolicy::applySandboxPolicy):
(WebCore::ContentSecurityPolicy::addDirective):
* page/ContentSecurityPolicy.h:

LayoutTests:

Test that the sandbox directive correctly wires up to the sandbox
flags.  Also, test that the policy inherits into subframes.  These are
essentially integration tests between the CSP and sandbox subsystems,
which is why they don't cover all the permutations of the sandbox
flags.  Those are covered in more detail via tests of the sandbox
attribute.

* http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html: Added.
* http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html: Added.
* http/tests/security/contentSecurityPolicy/sandbox-empty-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/sandbox-empty-subframe-expected.txt: Added.
* http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html: Added.
* http/tests/security/contentSecurityPolicy/sandbox-empty.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (99382 => 99383)


--- trunk/LayoutTests/ChangeLog	2011-11-06 21:29:52 UTC (rev 99382)
+++ trunk/LayoutTests/ChangeLog	2011-11-06 21:31:45 UTC (rev 99383)
@@ -1,3 +1,26 @@
+2011-11-06  Adam Barth  <[email protected]>
+
+        Implement the sandbox directive for CSP
+        https://bugs.webkit.org/show_bug.cgi?id=71604
+
+        Reviewed by Sam Weinig.
+
+        Test that the sandbox directive correctly wires up to the sandbox
+        flags.  Also, test that the policy inherits into subframes.  These are
+        essentially integration tests between the CSP and sandbox subsystems,
+        which is why they don't cover all the permutations of the sandbox
+        flags.  Those are covered in more detail via tests of the sandbox
+        attribute.
+
+        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-empty-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-empty-subframe-expected.txt: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html: Added.
+        * http/tests/security/contentSecurityPolicy/sandbox-empty.html: Added.
+
 2011-11-06  Ryosuke Niwa  <[email protected]>
 
         Add a crash expectation for platform/mac/accessibility/select-element-selection-with-optgroups.html on Mac.

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-expected.txt (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-expected.txt	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1,2 @@
+ALERT: PASS
+This test passes if it does alert pass.

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe-expected.txt (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe-expected.txt	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1,2 @@
+ALERT: PASS
+This test passes if it does alert pass. 

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1,7 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<meta http-equiv="X-WebKit-CSP" content="sandbox allow-scripts">
+This test passes if it does alert pass.
+<iframe src=""

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1,9 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<meta http-equiv="X-WebKit-CSP" content="sandbox allow-scripts">
+This test passes if it does alert pass.
+<script>
+alert('PASS');
+</script>

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-expected.txt (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-expected.txt	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1 @@
+This test passes if it doesn't alert fail.

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-subframe-expected.txt (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-subframe-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-subframe-expected.txt	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1 @@
+This test passes if it doesn't alert fail. 

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1,7 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<meta http-equiv="X-WebKit-CSP" content="sandbox">
+This test passes if it doesn't alert fail.
+<iframe src=""

Added: trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty.html (0 => 99383)


--- trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty.html	                        (rev 0)
+++ trunk/LayoutTests/http/tests/security/contentSecurityPolicy/sandbox-empty.html	2011-11-06 21:31:45 UTC (rev 99383)
@@ -0,0 +1,9 @@
+<script>
+if (window.layoutTestController)
+    layoutTestController.dumpAsText();
+</script>
+<meta http-equiv="X-WebKit-CSP" content="sandbox">
+This test passes if it doesn't alert fail.
+<script>
+alert('FAIL');
+</script>

Modified: trunk/Source/WebCore/ChangeLog (99382 => 99383)


--- trunk/Source/WebCore/ChangeLog	2011-11-06 21:29:52 UTC (rev 99382)
+++ trunk/Source/WebCore/ChangeLog	2011-11-06 21:31:45 UTC (rev 99383)
@@ -1,3 +1,30 @@
+2011-11-06  Adam Barth  <[email protected]>
+
+        Implement the sandbox directive for CSP
+        https://bugs.webkit.org/show_bug.cgi?id=71604
+
+        Reviewed by Sam Weinig.
+
+        At TPAC, Microsoft was pushing pretty hard to add the sandbox directive
+        to CSP.  There's a question about whether it's going to be in CSP 1.0
+        or CSP 1.1, but it seems to be clearly headed into the spec.
+
+        This patch implements the sandbox directive for CSP.  It's built on the
+        same machinery we use for the sandbox attribute for iframe.  Now that
+        I've done the implementation, I'm going to write up some concrete text
+        for the spec.
+
+        Tests: http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html
+               http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html
+               http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html
+               http/tests/security/contentSecurityPolicy/sandbox-empty.html
+
+        * page/ContentSecurityPolicy.cpp:
+        (WebCore::ContentSecurityPolicy::ContentSecurityPolicy):
+        (WebCore::ContentSecurityPolicy::applySandboxPolicy):
+        (WebCore::ContentSecurityPolicy::addDirective):
+        * page/ContentSecurityPolicy.h:
+
 2011-11-03  Filip Pizlo  <[email protected]>
 
         JSC should be able to sample itself in a more flexible way than just sampling flags

Modified: trunk/Source/WebCore/page/ContentSecurityPolicy.cpp (99382 => 99383)


--- trunk/Source/WebCore/page/ContentSecurityPolicy.cpp	2011-11-06 21:29:52 UTC (rev 99382)
+++ trunk/Source/WebCore/page/ContentSecurityPolicy.cpp	2011-11-06 21:31:45 UTC (rev 99383)
@@ -486,6 +486,7 @@
     : m_havePolicy(false)
     , m_scriptExecutionContext(scriptExecutionContext)
     , m_reportOnly(false)
+    , m_haveSandboxPolicy(false)
 {
 }
 
@@ -764,6 +765,13 @@
     return adoptPtr(new CSPDirective(name, value, m_scriptExecutionContext));
 }
 
+void ContentSecurityPolicy::applySandboxPolicy(const String& sandboxPolicy)
+{
+    ASSERT(!m_haveSandboxPolicy);
+    m_haveSandboxPolicy = true;
+    m_scriptExecutionContext->enforceSandboxFlags(SecurityOrigin::parseSandboxPolicy(sandboxPolicy));
+}
+
 void ContentSecurityPolicy::addDirective(const String& name, const String& value)
 {
     DEFINE_STATIC_LOCAL(String, defaultSrc, ("default-src"));
@@ -775,6 +783,7 @@
     DEFINE_STATIC_LOCAL(String, fontSrc, ("font-src"));
     DEFINE_STATIC_LOCAL(String, mediaSrc, ("media-src"));
     DEFINE_STATIC_LOCAL(String, connectSrc, ("connect-src"));
+    DEFINE_STATIC_LOCAL(String, sandbox, ("sandbox"));
     DEFINE_STATIC_LOCAL(String, reportURI, ("report-uri"));
 
     ASSERT(!name.isEmpty());
@@ -797,6 +806,8 @@
         m_mediaSrc = createCSPDirective(name, value);
     else if (!m_connectSrc && equalIgnoringCase(name, connectSrc))
         m_connectSrc = createCSPDirective(name, value);
+    else if (!m_haveSandboxPolicy && equalIgnoringCase(name, sandbox))
+        applySandboxPolicy(value);
     else if (m_reportURLs.isEmpty() && equalIgnoringCase(name, reportURI))
         parseReportURI(value);
     else

Modified: trunk/Source/WebCore/page/ContentSecurityPolicy.h (99382 => 99383)


--- trunk/Source/WebCore/page/ContentSecurityPolicy.h	2011-11-06 21:29:52 UTC (rev 99382)
+++ trunk/Source/WebCore/page/ContentSecurityPolicy.h	2011-11-06 21:31:45 UTC (rev 99383)
@@ -73,6 +73,7 @@
     bool parseDirective(const UChar* begin, const UChar* end, String& name, String& value);
     void parseReportURI(const String&);
     void addDirective(const String& name, const String& value);
+    void applySandboxPolicy(const String& sandboxPolicy);
 
     PassOwnPtr<CSPDirective> createCSPDirective(const String& name, const String& value);
 
@@ -100,6 +101,7 @@
     OwnPtr<CSPDirective> m_fontSrc;
     OwnPtr<CSPDirective> m_mediaSrc;
     OwnPtr<CSPDirective> m_connectSrc;
+    bool m_haveSandboxPolicy;
     Vector<KURL> m_reportURLs;
 };
 
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to