⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 99383 in webkit


Ignore:
Timestamp:
Nov 6, 2011, 1:31:45 PM (15 years ago)
Author:
abarth@webkit.org
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.
Location:
trunk
Files:
8 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r99380 r99383  
     12011-11-06  Adam Barth  <abarth@webkit.org>
     2
     3        Implement the sandbox directive for CSP
     4        https://bugs.webkit.org/show_bug.cgi?id=71604
     5
     6        Reviewed by Sam Weinig.
     7
     8        Test that the sandbox directive correctly wires up to the sandbox
     9        flags.  Also, test that the policy inherits into subframes.  These are
     10        essentially integration tests between the CSP and sandbox subsystems,
     11        which is why they don't cover all the permutations of the sandbox
     12        flags.  Those are covered in more detail via tests of the sandbox
     13        attribute.
     14
     15        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-expected.txt: Added.
     16        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe-expected.txt: Added.
     17        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html: Added.
     18        * http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html: Added.
     19        * http/tests/security/contentSecurityPolicy/sandbox-empty-expected.txt: Added.
     20        * http/tests/security/contentSecurityPolicy/sandbox-empty-subframe-expected.txt: Added.
     21        * http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html: Added.
     22        * http/tests/security/contentSecurityPolicy/sandbox-empty.html: Added.
     23
    1242011-11-06  Ryosuke Niwa  <rniwa@webkit.org>
    225
  • trunk/Source/WebCore/ChangeLog

    r99374 r99383  
     12011-11-06  Adam Barth  <abarth@webkit.org>
     2
     3        Implement the sandbox directive for CSP
     4        https://bugs.webkit.org/show_bug.cgi?id=71604
     5
     6        Reviewed by Sam Weinig.
     7
     8        At TPAC, Microsoft was pushing pretty hard to add the sandbox directive
     9        to CSP.  There's a question about whether it's going to be in CSP 1.0
     10        or CSP 1.1, but it seems to be clearly headed into the spec.
     11
     12        This patch implements the sandbox directive for CSP.  It's built on the
     13        same machinery we use for the sandbox attribute for iframe.  Now that
     14        I've done the implementation, I'm going to write up some concrete text
     15        for the spec.
     16
     17        Tests: http/tests/security/contentSecurityPolicy/sandbox-allow-scripts-subframe.html
     18               http/tests/security/contentSecurityPolicy/sandbox-allow-scripts.html
     19               http/tests/security/contentSecurityPolicy/sandbox-empty-subframe.html
     20               http/tests/security/contentSecurityPolicy/sandbox-empty.html
     21
     22        * page/ContentSecurityPolicy.cpp:
     23        (WebCore::ContentSecurityPolicy::ContentSecurityPolicy):
     24        (WebCore::ContentSecurityPolicy::applySandboxPolicy):
     25        (WebCore::ContentSecurityPolicy::addDirective):
     26        * page/ContentSecurityPolicy.h:
     27
    1282011-11-03  Filip Pizlo  <fpizlo@apple.com>
    229
  • trunk/Source/WebCore/page/ContentSecurityPolicy.cpp

    r99143 r99383  
    487487    , m_scriptExecutionContext(scriptExecutionContext)
    488488    , m_reportOnly(false)
     489    , m_haveSandboxPolicy(false)
    489490{
    490491}
     
    765766}
    766767
     768void ContentSecurityPolicy::applySandboxPolicy(const String& sandboxPolicy)
     769{
     770    ASSERT(!m_haveSandboxPolicy);
     771    m_haveSandboxPolicy = true;
     772    m_scriptExecutionContext->enforceSandboxFlags(SecurityOrigin::parseSandboxPolicy(sandboxPolicy));
     773}
     774
    767775void ContentSecurityPolicy::addDirective(const String& name, const String& value)
    768776{
     
    776784    DEFINE_STATIC_LOCAL(String, mediaSrc, ("media-src"));
    777785    DEFINE_STATIC_LOCAL(String, connectSrc, ("connect-src"));
     786    DEFINE_STATIC_LOCAL(String, sandbox, ("sandbox"));
    778787    DEFINE_STATIC_LOCAL(String, reportURI, ("report-uri"));
    779788
     
    798807    else if (!m_connectSrc && equalIgnoringCase(name, connectSrc))
    799808        m_connectSrc = createCSPDirective(name, value);
     809    else if (!m_haveSandboxPolicy && equalIgnoringCase(name, sandbox))
     810        applySandboxPolicy(value);
    800811    else if (m_reportURLs.isEmpty() && equalIgnoringCase(name, reportURI))
    801812        parseReportURI(value);
  • trunk/Source/WebCore/page/ContentSecurityPolicy.h

    r98316 r99383  
    7474    void parseReportURI(const String&);
    7575    void addDirective(const String& name, const String& value);
     76    void applySandboxPolicy(const String& sandboxPolicy);
    7677
    7778    PassOwnPtr<CSPDirective> createCSPDirective(const String& name, const String& value);
     
    101102    OwnPtr<CSPDirective> m_mediaSrc;
    102103    OwnPtr<CSPDirective> m_connectSrc;
     104    bool m_haveSandboxPolicy;
    103105    Vector<KURL> m_reportURLs;
    104106};
Note: See TracChangeset for help on using the changeset viewer.