Changeset 123722 in webkit


Ignore:
Timestamp:
Jul 26, 2012 2:49:52 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Source/WebCore: CSP 1.1: Implement the Content Security Policy script interface.
https://bugs.webkit.org/show_bug.cgi?id=91707

Patch by Mike West <mkwst@chromium.org> on 2012-07-26
Reviewed by Adam Barth.

The CSP 1.1 editor's draft defines a script interface that gives
developers the ability to query a document regarding the restrictions
set by it's currently active content security policy[1]. This patch
exposes that API in terms of a new DOMSecurityPolicy object.

Data for the API is gathered from the existing ContentSecurityPolicy
object on the containing document. CSP's various methods have been
extended with a reportingStatus parameter which, unsurprisingly,
determines whether a violation report should be sent for blocked
resources. This allows us to reuse the same codepaths by simply using
ContentSecurityPolicy::SuppressReport when querying on behalf of the
API, and ContentSecurityPolicy::SendReport when checking resources a
page wants to load.

This feature is gated on the CSP_NEXT flag, which is currently disabled
for all ports other than Chromium.

[1]: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces--experimental

Tests: http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html

http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html
http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html

  • CMakeLists.txt:
  • DerivedSources.cpp:
  • DerivedSources.make:
  • DerivedSources.pri:
  • GNUmakefile.list.am:
  • WebCore.gypi:
  • bindings/gobject/GNUmakefile.am:
  • WebCore.xcodeproj/project.pbxproj:

We added a new object, so let's tell _everyone!_

  • dom/Document.cpp:

(WebCore::Document::securityPolicy):

Expose the SecurityPolicy object via Document, gated on CSP_NEXT.

(WebCore):

  • dom/Document.h:

(WebCore):
(Document):

  • dom/Document.idl:

Adding the SecurityPolicy object to the document, gated on CSP_NEXT.

  • page/ContentSecurityPolicy.cpp:

(CSPDirectiveList):
(WebCore::CSPDirectiveList::checkInline):
(WebCore::CSPDirectiveList::checkNonce):
(WebCore::CSPDirectiveList::checkSource):

Extracting the core checks out into separate methods.

(WebCore::CSPDirectiveList::checkEvalAndReportViolation):

Use checkEval.

(WebCore::CSPDirectiveList::checkNonceAndReportViolation):

Use checkNonce.

(WebCore::CSPDirectiveList::checkInlineAndReportViolation):

Use checkInline.

(WebCore::CSPDirectiveList::checkSourceAndReportViolation):

Use checkSource.

(WebCore::CSPDirectiveList::allowJavaScriptURLs):
(WebCore::CSPDirectiveList::allowInlineEventHandlers):
(WebCore::CSPDirectiveList::allowInlineScript):
(WebCore::CSPDirectiveList::allowInlineStyle):
(WebCore::CSPDirectiveList::allowEval):
(WebCore::CSPDirectiveList::allowScriptFromSource):
(WebCore::CSPDirectiveList::allowObjectFromSource):
(WebCore::CSPDirectiveList::allowChildFrameFromSource):
(WebCore::CSPDirectiveList::allowImageFromSource):
(WebCore::CSPDirectiveList::allowStyleFromSource):
(WebCore::CSPDirectiveList::allowFontFromSource):
(WebCore::CSPDirectiveList::allowMediaFromSource):
(WebCore::CSPDirectiveList::allowConnectToSource):

These methods now branch on reportingStatus: if SendReoport,
they call checkXAndReportViolation, otherwise, they call checkX.

(WebCore::CSPDirectiveList::gatherReportURIs):

New method that gathers the violation report URIs into a DOMStringList.

(WebCore::isAllowedByAllWithCallStack):
(WebCore::isAllowedByAllWithContext):
(WebCore::isAllowedByAllWithURL):

These now pass reportingStatus through to the various allowX methods.

(WebCore::ContentSecurityPolicy::allowJavaScriptURLs):
(WebCore::ContentSecurityPolicy::allowInlineEventHandlers):
(WebCore::ContentSecurityPolicy::allowInlineScript):
(WebCore::ContentSecurityPolicy::allowInlineStyle):
(WebCore::ContentSecurityPolicy::allowEval):
(WebCore::ContentSecurityPolicy::allowScriptFromSource):
(WebCore::ContentSecurityPolicy::allowObjectFromSource):
(WebCore::ContentSecurityPolicy::allowChildFrameFromSource):
(WebCore::ContentSecurityPolicy::allowImageFromSource):
(WebCore::ContentSecurityPolicy::allowStyleFromSource):
(WebCore::ContentSecurityPolicy::allowFontFromSource):
(WebCore::ContentSecurityPolicy::allowMediaFromSource):
(WebCore::ContentSecurityPolicy::allowConnectToSource):

These accept a new reportingStatus parameter, which is passed through
to the CSPDirectiveList methods.

(WebCore::ContentSecurityPolicy::isActive):

New method that returns true if policy is active.

(WebCore::ContentSecurityPolicy::gatherReportURIs):

New method that returns a DOMStringList of violation report URIs.

  • page/ContentSecurityPolicy.h:

(WebCore):

  • page/DOMSecurityPolicy.cpp: Added.

(WebCore::DOMSecurityPolicy::DOMSecurityPolicy):
(WebCore):
(WebCore::DOMSecurityPolicy::~DOMSecurityPolicy):
(WebCore::DOMSecurityPolicy::isActive):
(WebCore::DOMSecurityPolicy::reportURIs):
(WebCore::DOMSecurityPolicy::allowsInlineScript):
(WebCore::DOMSecurityPolicy::allowsInlineStyle):
(WebCore::DOMSecurityPolicy::allowsEval):
(WebCore::DOMSecurityPolicy::allowsConnectionTo):
(WebCore::DOMSecurityPolicy::allowsFontFrom):
(WebCore::DOMSecurityPolicy::allowsFrameFrom):
(WebCore::DOMSecurityPolicy::allowsImageFrom):
(WebCore::DOMSecurityPolicy::allowsMediaFrom):
(WebCore::DOMSecurityPolicy::allowsObjectFrom):
(WebCore::DOMSecurityPolicy::allowsScriptFrom):
(WebCore::DOMSecurityPolicy::allowsStyleFrom):

  • page/DOMSecurityPolicy.h: Added.

(WebCore):
(DOMSecurityPolicy):
(WebCore::DOMSecurityPolicy::create):

  • page/DOMSecurityPolicy.idl: Added.

LayoutTests: Implement the experimental Content Security Policy script interface.
https://bugs.webkit.org/show_bug.cgi?id=91707

Patch by Mike West <mkwst@chromium.org> on 2012-07-26
Reviewed by Adam Barth.

  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi-expected.txt: Added.
  • http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html: Added.
  • http/tests/security/contentSecurityPolicy/resources/securitypolicy-tests-base.js: Added.

(log):
(injectPolicy):

Location:
trunk
Files:
26 added
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r123720 r123722  
     12012-07-26  Mike West  <mkwst@chromium.org>
     2
     3        Implement the experimental Content Security Policy script interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=91707
     5
     6        Reviewed by Adam Barth.
     7
     8        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto-expected.txt: Added.
     9        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html: Added.
     10        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval-expected.txt: Added.
     11        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html: Added.
     12        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom-expected.txt: Added.
     13        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html: Added.
     14        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom-expected.txt: Added.
     15        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html: Added.
     16        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom-expected.txt: Added.
     17        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html: Added.
     18        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom-expected.txt: Added.
     19        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html: Added.
     20        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom-expected.txt: Added.
     21        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html: Added.
     22        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom-expected.txt: Added.
     23        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html: Added.
     24        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom-expected.txt: Added.
     25        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html: Added.
     26        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive-expected.txt: Added.
     27        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html: Added.
     28        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi-expected.txt: Added.
     29        * http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html: Added.
     30        * http/tests/security/contentSecurityPolicy/resources/securitypolicy-tests-base.js: Added.
     31        (log):
     32        (injectPolicy):
     33
    1342012-07-26  Ádám Kallai  <kadam@inf.u-szeged.hu>
    235
  • trunk/Source/WebCore/CMakeLists.txt

    r123522 r123722  
    533533    page/Coordinates.idl
    534534    page/Crypto.idl
     535    page/DOMSecurityPolicy.idl
    535536    page/DOMSelection.idl
    536537    page/DOMWindow.idl
     
    16251626    page/ContextMenuController.cpp
    16261627    page/Crypto.cpp
     1628    page/DOMSecurityPolicy.cpp
    16271629    page/DOMSelection.cpp
    16281630    page/DOMTimer.cpp
  • trunk/Source/WebCore/ChangeLog

    r123721 r123722  
     12012-07-26  Mike West  <mkwst@chromium.org>
     2
     3        CSP 1.1: Implement the Content Security Policy script interface.
     4        https://bugs.webkit.org/show_bug.cgi?id=91707
     5
     6        Reviewed by Adam Barth.
     7
     8        The CSP 1.1 editor's draft defines a script interface that gives
     9        developers the ability to query a document regarding the restrictions
     10        set by it's currently active content security policy[1]. This patch
     11        exposes that API in terms of a new DOMSecurityPolicy object.
     12
     13        Data for the API is gathered from the existing ContentSecurityPolicy
     14        object on the containing document. CSP's various methods have been
     15        extended with a `reportingStatus` parameter which, unsurprisingly,
     16        determines whether a violation report should be sent for blocked
     17        resources. This allows us to reuse the same codepaths by simply using
     18        ContentSecurityPolicy::SuppressReport when querying on behalf of the
     19        API, and ContentSecurityPolicy::SendReport when checking resources a
     20        page wants to load.
     21
     22        This feature is gated on the CSP_NEXT flag, which is currently disabled
     23        for all ports other than Chromium.
     24
     25        [1]: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces--experimental
     26
     27        Tests: http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowconnectionto.html
     28               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-alloweval.html
     29               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowfontfrom.html
     30               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowframefrom.html
     31               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowimagefrom.html
     32               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowmediafrom.html
     33               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowobjectfrom.html
     34               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowscriptfrom.html
     35               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-allowstylefrom.html
     36               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-isactive.html
     37               http/tests/security/contentSecurityPolicy/1.1/securitypolicy-reporturi.html
     38
     39        * CMakeLists.txt:
     40        * DerivedSources.cpp:
     41        * DerivedSources.make:
     42        * DerivedSources.pri:
     43        * GNUmakefile.list.am:
     44        * WebCore.gypi:
     45        * bindings/gobject/GNUmakefile.am:
     46        * WebCore.xcodeproj/project.pbxproj:
     47            We added a new object, so let's tell _everyone!_
     48        * dom/Document.cpp:
     49        (WebCore::Document::securityPolicy):
     50            Expose the SecurityPolicy object via Document, gated on CSP_NEXT.
     51        (WebCore):
     52        * dom/Document.h:
     53        (WebCore):
     54        (Document):
     55        * dom/Document.idl:
     56            Adding the SecurityPolicy object to the document, gated on CSP_NEXT.
     57        * page/ContentSecurityPolicy.cpp:
     58        (CSPDirectiveList):
     59        (WebCore::CSPDirectiveList::checkInline):
     60        (WebCore::CSPDirectiveList::checkNonce):
     61        (WebCore::CSPDirectiveList::checkSource):
     62            Extracting the core checks out into separate methods.
     63        (WebCore::CSPDirectiveList::checkEvalAndReportViolation):
     64            Use checkEval.
     65        (WebCore::CSPDirectiveList::checkNonceAndReportViolation):
     66            Use checkNonce.
     67        (WebCore::CSPDirectiveList::checkInlineAndReportViolation):
     68            Use checkInline.
     69        (WebCore::CSPDirectiveList::checkSourceAndReportViolation):
     70            Use checkSource.
     71        (WebCore::CSPDirectiveList::allowJavaScriptURLs):
     72        (WebCore::CSPDirectiveList::allowInlineEventHandlers):
     73        (WebCore::CSPDirectiveList::allowInlineScript):
     74        (WebCore::CSPDirectiveList::allowInlineStyle):
     75        (WebCore::CSPDirectiveList::allowEval):
     76        (WebCore::CSPDirectiveList::allowScriptFromSource):
     77        (WebCore::CSPDirectiveList::allowObjectFromSource):
     78        (WebCore::CSPDirectiveList::allowChildFrameFromSource):
     79        (WebCore::CSPDirectiveList::allowImageFromSource):
     80        (WebCore::CSPDirectiveList::allowStyleFromSource):
     81        (WebCore::CSPDirectiveList::allowFontFromSource):
     82        (WebCore::CSPDirectiveList::allowMediaFromSource):
     83        (WebCore::CSPDirectiveList::allowConnectToSource):
     84            These methods now branch on `reportingStatus`: if `SendReoport`,
     85            they call `checkXAndReportViolation`, otherwise, they call `checkX`.
     86        (WebCore::CSPDirectiveList::gatherReportURIs):
     87            New method that gathers the violation report URIs into a DOMStringList.
     88        (WebCore::isAllowedByAllWithCallStack):
     89        (WebCore::isAllowedByAllWithContext):
     90        (WebCore::isAllowedByAllWithURL):
     91            These now pass reportingStatus through to the various `allowX` methods.
     92        (WebCore::ContentSecurityPolicy::allowJavaScriptURLs):
     93        (WebCore::ContentSecurityPolicy::allowInlineEventHandlers):
     94        (WebCore::ContentSecurityPolicy::allowInlineScript):
     95        (WebCore::ContentSecurityPolicy::allowInlineStyle):
     96        (WebCore::ContentSecurityPolicy::allowEval):
     97        (WebCore::ContentSecurityPolicy::allowScriptFromSource):
     98        (WebCore::ContentSecurityPolicy::allowObjectFromSource):
     99        (WebCore::ContentSecurityPolicy::allowChildFrameFromSource):
     100        (WebCore::ContentSecurityPolicy::allowImageFromSource):
     101        (WebCore::ContentSecurityPolicy::allowStyleFromSource):
     102        (WebCore::ContentSecurityPolicy::allowFontFromSource):
     103        (WebCore::ContentSecurityPolicy::allowMediaFromSource):
     104        (WebCore::ContentSecurityPolicy::allowConnectToSource):
     105            These accept a new `reportingStatus` parameter, which is passed through
     106            to the CSPDirectiveList methods.
     107        (WebCore::ContentSecurityPolicy::isActive):
     108            New method that returns `true` if policy is active.
     109        (WebCore::ContentSecurityPolicy::gatherReportURIs):
     110            New method that returns a DOMStringList of violation report URIs.
     111        * page/ContentSecurityPolicy.h:
     112        (WebCore):
     113        * page/DOMSecurityPolicy.cpp: Added.
     114        (WebCore::DOMSecurityPolicy::DOMSecurityPolicy):
     115        (WebCore):
     116        (WebCore::DOMSecurityPolicy::~DOMSecurityPolicy):
     117        (WebCore::DOMSecurityPolicy::isActive):
     118        (WebCore::DOMSecurityPolicy::reportURIs):
     119        (WebCore::DOMSecurityPolicy::allowsInlineScript):
     120        (WebCore::DOMSecurityPolicy::allowsInlineStyle):
     121        (WebCore::DOMSecurityPolicy::allowsEval):
     122        (WebCore::DOMSecurityPolicy::allowsConnectionTo):
     123        (WebCore::DOMSecurityPolicy::allowsFontFrom):
     124        (WebCore::DOMSecurityPolicy::allowsFrameFrom):
     125        (WebCore::DOMSecurityPolicy::allowsImageFrom):
     126        (WebCore::DOMSecurityPolicy::allowsMediaFrom):
     127        (WebCore::DOMSecurityPolicy::allowsObjectFrom):
     128        (WebCore::DOMSecurityPolicy::allowsScriptFrom):
     129        (WebCore::DOMSecurityPolicy::allowsStyleFrom):
     130        * page/DOMSecurityPolicy.h: Added.
     131        (WebCore):
     132        (DOMSecurityPolicy):
     133        (WebCore::DOMSecurityPolicy::create):
     134        * page/DOMSecurityPolicy.idl: Added.
     135
    11362012-07-26  Gyuyoung Kim  <gyuyoung.kim@samsung.com>
    2137
  • trunk/Source/WebCore/DerivedSources.cpp

    r123522 r123722  
    9595#include "JSDOMPlugin.cpp"
    9696#include "JSDOMPluginArray.cpp"
     97#include "JSDOMSecurityPolicy.cpp"
    9798#include "JSDOMSelection.cpp"
    9899#include "JSDOMSettableTokenList.cpp"
  • trunk/Source/WebCore/DerivedSources.make

    r123522 r123722  
    412412    $(WebCore)/page/Coordinates.idl \
    413413    $(WebCore)/page/Crypto.idl \
     414    $(WebCore)/page/DOMSecurityPolicy.idl \
    414415    $(WebCore)/page/DOMSelection.idl \
    415416    $(WebCore)/page/DOMWindow.idl \
  • trunk/Source/WebCore/DerivedSources.pri

    r123522 r123722  
    416416    $$PWD/page/Coordinates.idl \
    417417    $$PWD/page/Crypto.idl \
     418    $$PWD/page/DOMSecurityPolicy.idl \
    418419    $$PWD/page/DOMSelection.idl \
    419420    $$PWD/page/DOMWindow.idl \
  • trunk/Source/WebCore/GNUmakefile.list.am

    r123627 r123722  
    143143        DerivedSources/WebCore/JSDOMPlugin.cpp \
    144144        DerivedSources/WebCore/JSDOMPlugin.h \
     145        DerivedSources/WebCore/JSDOMSecurityPolicy.cpp \
     146        DerivedSources/WebCore/JSDOMSecurityPolicy.h \
    145147        DerivedSources/WebCore/JSDOMSelection.cpp \
    146148        DerivedSources/WebCore/JSDOMSelection.h \
     
    970972        $(WebCore)/page/Coordinates.idl \
    971973        $(WebCore)/page/Crypto.idl \
     974        $(WebCore)/page/DOMSecurityPolicy.idl \
    972975        $(WebCore)/page/DOMSelection.idl \
    973976        $(WebCore)/page/DOMWindow.idl \
     
    30313034        Source/WebCore/page/Crypto.cpp \
    30323035        Source/WebCore/page/Crypto.h \
     3036        Source/WebCore/page/DOMSecurityPolicy.cpp \
     3037        Source/WebCore/page/DOMSecurityPolicy.h \
    30333038        Source/WebCore/page/DOMSelection.cpp \
    30343039        Source/WebCore/page/DOMSelection.h \
  • trunk/Source/WebCore/WebCore.gypi

    r123644 r123722  
    224224            'page/ContextMenuController.h',
    225225            'page/Coordinates.h',
     226            'page/DOMSecurityPolicy.h',
    226227            'page/DOMWindow.h',
    227228            'page/DOMWindowExtension.h',
     
    11661167            'page/Coordinates.idl',
    11671168            'page/Crypto.idl',
     1169            'page/DOMSecurityPolicy.idl',
    11681170            'page/DOMSelection.idl',
    11691171            'page/DOMWindow.idl',
     
    30483050            'page/Crypto.cpp',
    30493051            'page/Crypto.h',
     3052            'page/DOMSecurityPolicy.cpp',
    30503053            'page/DOMSelection.cpp',
    30513054            'page/DOMSelection.h',
     
    72467249            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMPluginArray.cpp',
    72477250            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMPluginArray.h',
     7251            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSecurityPolicy.cpp',
     7252            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSecurityPolicy.h',
    72487253            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSelection.cpp',
    72497254            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSDOMSelection.h',
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r123623 r123722  
    782782                2D9066060BE141D400956998 /* LayoutState.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D9066040BE141D400956998 /* LayoutState.cpp */; };
    783783                2D9066070BE141D400956998 /* LayoutState.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9066050BE141D400956998 /* LayoutState.h */; settings = {ATTRIBUTES = (Private, ); }; };
     784                2D9A246E15B9BD0000D34527 /* DOMSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9A246B15B9BBDD00D34527 /* DOMSecurityPolicy.h */; };
     785                2D9A246F15B9BD2F00D34527 /* DOMSecurityPolicy.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */; };
     786                2D9A247315B9C2D100D34527 /* DOMDOMSecurityPolicy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2D9A247215B9C2C700D34527 /* DOMDOMSecurityPolicy.mm */; };
     787                2D9A247415B9C2E300D34527 /* DOMDOMSecurityPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */; };
     788                2D9A247515B9C2E300D34527 /* DOMDOMSecurityPolicyInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 2D9A247115B9C29500D34527 /* DOMDOMSecurityPolicyInternal.h */; };
     789                2D9A247615B9C2F400D34527 /* DOMDOMSecurityPolicy.h in Copy Generated Headers */ = {isa = PBXBuildFile; fileRef = 2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */; };
    784790                2D9F0E1314FF1CBF00BA0FF7 /* linearSRGB.icc in Resources */ = {isa = PBXBuildFile; fileRef = 2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */; };
    785791                2E0888D41148848A00AF4265 /* JSDOMFormData.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2E0888D21148848A00AF4265 /* JSDOMFormData.cpp */; };
     
    65536559                        files = (
    65546560                                5DF7F5C20F01F92A00526B4B /* CSSPropertyNames.h in Copy Generated Headers */,
     6561                                2D9A247615B9C2F400D34527 /* DOMDOMSecurityPolicy.h in Copy Generated Headers */,
    65556562                                8538F0300AD71CDB006A81D1 /* DOMAbstractView.h in Copy Generated Headers */,
    65566563                                1C11CCBC0AA6093700DADB20 /* DOMAttr.h in Copy Generated Headers */,
     
    78137820                2D90660B0665D937006B6F1A /* ClipboardMac.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = ClipboardMac.h; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
    78147821                2D90660C0665D937006B6F1A /* ClipboardMac.mm */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ClipboardMac.mm; sourceTree = "<group>"; tabWidth = 8; usesTabs = 0; };
     7822                2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = DOMSecurityPolicy.cpp; sourceTree = "<group>"; };
     7823                2D9A246B15B9BBDD00D34527 /* DOMSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMSecurityPolicy.h; sourceTree = "<group>"; };
     7824                2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDOMSecurityPolicy.h; sourceTree = "<group>"; };
     7825                2D9A247115B9C29500D34527 /* DOMDOMSecurityPolicyInternal.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DOMDOMSecurityPolicyInternal.h; sourceTree = "<group>"; };
     7826                2D9A247215B9C2C700D34527 /* DOMDOMSecurityPolicy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = DOMDOMSecurityPolicy.mm; sourceTree = "<group>"; };
    78157827                2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */ = {isa = PBXFileReference; lastKnownFileType = file; path = linearSRGB.icc; sourceTree = "<group>"; };
    78167828                2E0888C3114883A900AF4265 /* DOMFormData.idl */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = DOMFormData.idl; sourceTree = "<group>"; };
     
    1560015612                        isa = PBXGroup;
    1560115613                        children = (
     15614                                2D9A246A15B9BBDD00D34527 /* DOMSecurityPolicy.cpp */,
     15615                                2D9A246B15B9BBDD00D34527 /* DOMSecurityPolicy.h */,
    1560215616                                316FE1060E6E1D8400BF6088 /* animation */,
    1560315617                                93C09A820B064F05005ABD4D /* mac */,
     
    1587315887                        isa = PBXGroup;
    1587415888                        children = (
     15889                                2D9A247215B9C2C700D34527 /* DOMDOMSecurityPolicy.mm */,
     15890                                2D9A247015B9C29500D34527 /* DOMDOMSecurityPolicy.h */,
     15891                                2D9A247115B9C29500D34527 /* DOMDOMSecurityPolicyInternal.h */,
    1587515892                                85D389B00A991A7F00282145 /* DOMAttr.h */,
    1587615893                                85D389B10A991A7F00282145 /* DOMAttr.mm */,
     
    2282522842                                8502AB9B0AD4394E00378540 /* DOMSVGFEImageElementInternal.h in Headers */,
    2282622843                                8502AB5C0AD438C000378540 /* DOMSVGFEMergeElement.h in Headers */,
     22844                                2D9A247415B9C2E300D34527 /* DOMDOMSecurityPolicy.h in Headers */,
     22845                                2D9A247515B9C2E300D34527 /* DOMDOMSecurityPolicyInternal.h in Headers */,
    2282722846                                8502AB9C0AD4394E00378540 /* DOMSVGFEMergeElementInternal.h in Headers */,
    2282822847                                8502AB5E0AD438C000378540 /* DOMSVGFEMergeNodeElement.h in Headers */,
     
    2333923358                                A81369D4097374F600D74463 /* HTMLFieldSetElement.h in Headers */,
    2334023359                                A8CFF7A60A156978000A4234 /* HTMLFontElement.h in Headers */,
     23360                                2D9A246E15B9BD0000D34527 /* DOMSecurityPolicy.h in Headers */,
    2334123361                                977B386F122883E900B81FF8 /* HTMLFormattingElementList.h in Headers */,
    2334223362                                A8DF3FCE097FA0FC0052981B /* HTMLFormCollection.h in Headers */,
     
    2565425674                        files = (
    2565525675                                FDE6860215B0A93B00BB480C /* WrapShapeFunctions.cpp in Sources */,
     25676                                2D9A247315B9C2D100D34527 /* DOMDOMSecurityPolicy.mm in Sources */,
    2565625677                                97BC69DA1505F076001B74AC /* AbstractDatabase.cpp in Sources */,
    2565725678                                41E1B1D00FF5986900576B3B /* AbstractWorker.cpp in Sources */,
     
    2611126132                                858C38A80AA8F20400B187A4 /* DOMRect.mm in Sources */,
    2611226133                                BCAEFCAE1016CE4A0040D34E /* DOMRGBColor.mm in Sources */,
     26134                                2D9A246F15B9BD2F00D34527 /* DOMSecurityPolicy.cpp in Sources */,
    2611326135                                BC5A86840C33676000EEA649 /* DOMSelection.cpp in Sources */,
    2611426136                                4ACBC0C312713CCA0094F9B2 /* DOMSettableTokenList.cpp in Sources */,
  • trunk/Source/WebCore/bindings/gobject/GNUmakefile.am

    r123434 r123722  
    4444        DerivedSources/webkit/WebKitDOMDOMPlugin.cpp \
    4545        DerivedSources/webkit/WebKitDOMDOMPluginPrivate.h \
     46        DerivedSources/webkit/WebKitDOMDOMSecurityPolicy.cpp \
     47        DerivedSources/webkit/WebKitDOMDOMSecurityPolicyPrivate.h \
    4648        DerivedSources/webkit/WebKitDOMDOMSelection.cpp \
    4749        DerivedSources/webkit/WebKitDOMDOMSelectionPrivate.h \
     
    279281        DerivedSources/webkit/WebKitDOMDOMImplementation.h \
    280282        DerivedSources/webkit/WebKitDOMDOMSettableTokenList.h \
     283        DerivedSources/webkit/WebKitDOMDOMSecurityPolicy.h \
    281284        DerivedSources/webkit/WebKitDOMDOMStringList.h \
    282285        DerivedSources/webkit/WebKitDOMDOMStringMap.h \
  • trunk/Source/WebCore/dom/Document.cpp

    r123412 r123722  
    223223#endif
    224224
     225#if ENABLE(CSP_NEXT)
     226#include "DOMSecurityPolicy.h"
     227#endif
     228
    225229using namespace std;
    226230using namespace WTF;
     
    16411645{
    16421646    dispatchEvent(Event::create(eventNames().webkitvisibilitychangeEvent, false, false));
     1647}
     1648#endif
     1649
     1650#if ENABLE(CSP_NEXT)
     1651DOMSecurityPolicy* Document::securityPolicy()
     1652{
     1653    if (!m_domSecurityPolicy)
     1654        m_domSecurityPolicy = DOMSecurityPolicy::create(this);
     1655    return m_domSecurityPolicy.get();
    16431656}
    16441657#endif
  • trunk/Source/WebCore/dom/Document.h

    r123412 r123722  
    180180#endif
    181181
     182#if ENABLE(CSP_NEXT)
     183class DOMSecurityPolicy;
     184#endif
     185
    182186typedef int ExceptionCode;
    183187
     
    417421#endif
    418422
     423#if ENABLE(CSP_NEXT)
     424    DOMSecurityPolicy* securityPolicy();
     425#endif
     426
    419427    PassRefPtr<Node> adoptNode(PassRefPtr<Node> source, ExceptionCode&);
    420428
     
    15401548    RefPtr<WebKitNamedFlowCollection> m_namedFlows;
    15411549
     1550#if ENABLE(CSP_NEXT)
     1551    RefPtr<DOMSecurityPolicy> m_domSecurityPolicy;
     1552#endif
     1553
    15421554#ifndef NDEBUG
    15431555    bool m_didDispatchViewportPropertiesChanged;
  • trunk/Source/WebCore/dom/Document.idl

    r120486 r123722  
    376376        readonly attribute [Conditional=PAGE_VISIBILITY_API] boolean webkitHidden;
    377377
     378        // Security Policy API: http://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces
     379        readonly attribute [Conditional=CSP_NEXT] DOMSecurityPolicy SecurityPolicy;
     380
    378381    };
    379382
  • trunk/Source/WebCore/page/ContentSecurityPolicy.cpp

    r122741 r123722  
    2828
    2929#include "Console.h"
     30#include "DOMStringList.h"
    3031#include "Document.h"
    3132#include "FormData.h"
     
    547548    ContentSecurityPolicy::HeaderType headerType() const { return m_reportOnly ? ContentSecurityPolicy::ReportOnly : ContentSecurityPolicy::EnforcePolicy; }
    548549
    549     bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    550     bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    551     bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    552     bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    553     bool allowEval(PassRefPtr<ScriptCallStack>) const;
     550    bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
     551    bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
     552    bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
     553    bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus) const;
     554    bool allowEval(PassRefPtr<ScriptCallStack>, ContentSecurityPolicy::ReportingStatus) const;
    554555    bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL&) const;
    555556
    556     bool allowScriptFromSource(const KURL&) const;
    557     bool allowObjectFromSource(const KURL&) const;
    558     bool allowChildFrameFromSource(const KURL&) const;
    559     bool allowImageFromSource(const KURL&) const;
    560     bool allowStyleFromSource(const KURL&) const;
    561     bool allowFontFromSource(const KURL&) const;
    562     bool allowMediaFromSource(const KURL&) const;
    563     bool allowConnectToSource(const KURL&) const;
     557    bool allowScriptFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     558    bool allowObjectFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     559    bool allowChildFrameFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     560    bool allowImageFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     561    bool allowStyleFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     562    bool allowFontFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     563    bool allowMediaFromSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     564    bool allowConnectToSource(const KURL&, ContentSecurityPolicy::ReportingStatus) const;
     565
     566    void gatherReportURIs(DOMStringList&) const;
    564567
    565568private:
     
    581584    void logDuplicateDirective(const String& name) const;
    582585    void logInvalidNonce(const String& nonce) const;
     586
    583587    bool checkEval(CSPDirective*) const;
    584 
     588    bool checkInline(CSPDirective*) const;
     589    bool checkNonce(const String&) const;
     590    bool checkSource(CSPDirective*, const KURL&) const;
     591
     592    bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
    585593    bool checkInlineAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    586594    bool checkNonceAndReportViolation(const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    587     bool checkEvalAndReportViolation(CSPDirective*, const String& consoleMessage, const String& contextURL = String(), const WTF::OrdinalNumber& contextLine = WTF::OrdinalNumber::beforeFirst(), PassRefPtr<ScriptCallStack> = 0) const;
    588595    bool checkSourceAndReportViolation(CSPDirective*, const KURL&, const String& type) const;
    589596
     
    708715}
    709716
     717bool CSPDirectiveList::checkInline(CSPDirective* directive) const
     718{
     719    return !directive || directive->allowInline();
     720}
     721
     722bool CSPDirectiveList::checkNonce(const String& nonce) const
     723{
     724    return (m_scriptNonce.isNull()
     725            || (!m_scriptNonce.isEmpty()
     726                && nonce.stripWhiteSpace() == m_scriptNonce));
     727}
     728
     729bool CSPDirectiveList::checkSource(CSPDirective* directive, const KURL& url) const
     730{
     731    return !directive || directive->allows(url);
     732}
     733
    710734CSPDirective* CSPDirectiveList::operativeDirective(CSPDirective* directive) const
    711735{
     
    713737}
    714738
     739bool CSPDirectiveList::checkEvalAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, PassRefPtr<ScriptCallStack> callStack) const
     740{
     741    if (checkEval(directive))
     742        return true;
     743    reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine, callStack);
     744    return denyIfEnforcingPolicy();
     745}
     746
     747bool CSPDirectiveList::checkNonceAndReportViolation(const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
     748{
     749    if (checkNonce(nonce))
     750        return true;
     751    reportViolation(m_scriptNonce, consoleMessage + "\"script-nonce " + m_scriptNonce + "\".\n", KURL(), contextURL, contextLine);
     752    return denyIfEnforcingPolicy();
     753}
     754
    715755bool CSPDirectiveList::checkInlineAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
    716756{
    717     if (!directive || directive->allowInline())
     757    if (checkInline(directive))
    718758        return true;
    719759    reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine);
     
    721761}
    722762
    723 bool CSPDirectiveList::checkNonceAndReportViolation(const String& nonce, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine) const
    724 {
    725     if (m_scriptNonce.isNull() || (!m_scriptNonce.isEmpty() && nonce.stripWhiteSpace() == m_scriptNonce))
    726         return true;
    727     reportViolation(m_scriptNonce, consoleMessage + "\"script-nonce " + m_scriptNonce + "\".\n", KURL(), contextURL, contextLine);
    728     return denyIfEnforcingPolicy();
    729 }
    730 
    731 bool CSPDirectiveList::checkEvalAndReportViolation(CSPDirective* directive, const String& consoleMessage, const String& contextURL, const WTF::OrdinalNumber& contextLine, PassRefPtr<ScriptCallStack> callStack) const
    732 {
    733     if (checkEval(directive))
    734         return true;
    735     reportViolation(directive->text(), consoleMessage + "\"" + directive->text() + "\".\n", KURL(), contextURL, contextLine, callStack);
    736     return denyIfEnforcingPolicy();
    737 }
    738 
    739763bool CSPDirectiveList::checkSourceAndReportViolation(CSPDirective* directive, const KURL& url, const String& type) const
    740764{
    741     if (!directive || directive->allows(url))
     765    if (checkSource(directive, url))
    742766        return true;
    743767    String verb = type == "connect" ? "connect to" : "load the";
     
    746770}
    747771
    748 bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
     772bool CSPDirectiveList::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    749773{
    750774    DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute JavaScript URL because it violates the following Content Security Policy directive: "));
    751     return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
    752             && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
    753 }
    754 
    755 bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
     775    if (reportingStatus == ContentSecurityPolicy::SendReport) {
     776        return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
     777                && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
     778    } else {
     779        return (checkInline(operativeDirective(m_scriptSrc.get()))
     780                && checkNonce(String()));
     781    }
     782}
     783
     784bool CSPDirectiveList::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    756785{
    757786    DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute inline event handler because it violates the following Content Security Policy directive: "));
    758     return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
    759             && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
    760 }
    761 
    762 bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
     787    if (reportingStatus == ContentSecurityPolicy::SendReport) {
     788        return (checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine)
     789                && checkNonceAndReportViolation(String(), consoleMessage, contextURL, contextLine));
     790    } else {
     791        return (checkInline(operativeDirective(m_scriptSrc.get()))
     792                && checkNonce(String()));
     793    }
     794}
     795
     796bool CSPDirectiveList::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    763797{
    764798    DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to execute inline script because it violates the following Content Security Policy directive: "));
    765     return checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine);
    766 }
    767 
    768 bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
     799    return reportingStatus == ContentSecurityPolicy::SendReport ?
     800        checkInlineAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, contextURL, contextLine) :
     801        checkInline(operativeDirective(m_scriptSrc.get()));
     802}
     803
     804bool CSPDirectiveList::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    769805{
    770806    DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to apply inline style because it violates the following Content Security Policy directive: "));
    771     return checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine);
    772 }
    773 
    774 bool CSPDirectiveList::allowEval(PassRefPtr<ScriptCallStack> callStack) const
     807    return reportingStatus == ContentSecurityPolicy::SendReport ?
     808        checkInlineAndReportViolation(operativeDirective(m_styleSrc.get()), consoleMessage, contextURL, contextLine) :
     809        checkInline(operativeDirective(m_styleSrc.get()));
     810}
     811
     812bool CSPDirectiveList::allowEval(PassRefPtr<ScriptCallStack> callStack, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    775813{
    776814    DEFINE_STATIC_LOCAL(String, consoleMessage, ("Refused to evaluate script because it violates the following Content Security Policy directive: "));
    777     return checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, String(), WTF::OrdinalNumber::beforeFirst(), callStack);
     815    return reportingStatus == ContentSecurityPolicy::SendReport ?
     816        checkEvalAndReportViolation(operativeDirective(m_scriptSrc.get()), consoleMessage, String(), WTF::OrdinalNumber::beforeFirst(), callStack) :
     817        checkEval(operativeDirective(m_scriptSrc.get()));
    778818}
    779819
     
    786826}
    787827
    788 bool CSPDirectiveList::allowScriptFromSource(const KURL& url) const
     828bool CSPDirectiveList::allowScriptFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    789829{
    790830    DEFINE_STATIC_LOCAL(String, type, ("script"));
    791     return checkSourceAndReportViolation(operativeDirective(m_scriptSrc.get()), url, type);
    792 }
    793 
    794 bool CSPDirectiveList::allowObjectFromSource(const KURL& url) const
     831    return reportingStatus == ContentSecurityPolicy::SendReport ?
     832        checkSourceAndReportViolation(operativeDirective(m_scriptSrc.get()), url, type) :
     833        checkSource(operativeDirective(m_scriptSrc.get()), url);
     834}
     835
     836bool CSPDirectiveList::allowObjectFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    795837{
    796838    DEFINE_STATIC_LOCAL(String, type, ("object"));
    797839    if (url.isBlankURL())
    798840        return true;
    799     return checkSourceAndReportViolation(operativeDirective(m_objectSrc.get()), url, type);
    800 }
    801 
    802 bool CSPDirectiveList::allowChildFrameFromSource(const KURL& url) const
     841    return reportingStatus == ContentSecurityPolicy::SendReport ?
     842        checkSourceAndReportViolation(operativeDirective(m_objectSrc.get()), url, type) :
     843        checkSource(operativeDirective(m_objectSrc.get()), url);
     844}
     845
     846bool CSPDirectiveList::allowChildFrameFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    803847{
    804848    DEFINE_STATIC_LOCAL(String, type, ("frame"));
    805849    if (url.isBlankURL())
    806850        return true;
    807     return checkSourceAndReportViolation(operativeDirective(m_frameSrc.get()), url, type);
    808 }
    809 
    810 bool CSPDirectiveList::allowImageFromSource(const KURL& url) const
     851    return reportingStatus == ContentSecurityPolicy::SendReport ?
     852        checkSourceAndReportViolation(operativeDirective(m_frameSrc.get()), url, type) :
     853        checkSource(operativeDirective(m_frameSrc.get()), url);
     854}
     855
     856bool CSPDirectiveList::allowImageFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    811857{
    812858    DEFINE_STATIC_LOCAL(String, type, ("image"));
    813     return checkSourceAndReportViolation(operativeDirective(m_imgSrc.get()), url, type);
    814 }
    815 
    816 bool CSPDirectiveList::allowStyleFromSource(const KURL& url) const
     859    return reportingStatus == ContentSecurityPolicy::SendReport ?
     860        checkSourceAndReportViolation(operativeDirective(m_imgSrc.get()), url, type) :
     861        checkSource(operativeDirective(m_imgSrc.get()), url);
     862}
     863
     864bool CSPDirectiveList::allowStyleFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    817865{
    818866    DEFINE_STATIC_LOCAL(String, type, ("style"));
    819     return checkSourceAndReportViolation(operativeDirective(m_styleSrc.get()), url, type);
    820 }
    821 
    822 bool CSPDirectiveList::allowFontFromSource(const KURL& url) const
     867    return reportingStatus == ContentSecurityPolicy::SendReport ?
     868        checkSourceAndReportViolation(operativeDirective(m_styleSrc.get()), url, type) :
     869        checkSource(operativeDirective(m_styleSrc.get()), url);
     870}
     871
     872bool CSPDirectiveList::allowFontFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    823873{
    824874    DEFINE_STATIC_LOCAL(String, type, ("font"));
    825     return checkSourceAndReportViolation(operativeDirective(m_fontSrc.get()), url, type);
    826 }
    827 
    828 bool CSPDirectiveList::allowMediaFromSource(const KURL& url) const
     875    return reportingStatus == ContentSecurityPolicy::SendReport ?
     876        checkSourceAndReportViolation(operativeDirective(m_fontSrc.get()), url, type) :
     877        checkSource(operativeDirective(m_fontSrc.get()), url);
     878}
     879
     880bool CSPDirectiveList::allowMediaFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    829881{
    830882    DEFINE_STATIC_LOCAL(String, type, ("media"));
    831     return checkSourceAndReportViolation(operativeDirective(m_mediaSrc.get()), url, type);
    832 }
    833 
    834 bool CSPDirectiveList::allowConnectToSource(const KURL& url) const
     883    return reportingStatus == ContentSecurityPolicy::SendReport ?
     884        checkSourceAndReportViolation(operativeDirective(m_mediaSrc.get()), url, type) :
     885        checkSource(operativeDirective(m_mediaSrc.get()), url);
     886}
     887
     888bool CSPDirectiveList::allowConnectToSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    835889{
    836890    DEFINE_STATIC_LOCAL(String, type, ("connect"));
    837     return checkSourceAndReportViolation(operativeDirective(m_connectSrc.get()), url, type);
     891    return reportingStatus == ContentSecurityPolicy::SendReport ?
     892        checkSourceAndReportViolation(operativeDirective(m_connectSrc.get()), url, type) :
     893        checkSource(operativeDirective(m_connectSrc.get()), url);
     894}
     895
     896void CSPDirectiveList::gatherReportURIs(DOMStringList& list) const
     897{
     898    for (size_t i = 0; i < m_reportURIs.size(); ++i)
     899        list.append(m_reportURIs[i].string());
    838900}
    839901
     
    10831145}
    10841146
    1085 template<bool (CSPDirectiveList::*allowed)(PassRefPtr<ScriptCallStack>) const>
    1086 bool isAllowedByAllWithCallStack(const CSPDirectiveListVector& policies, PassRefPtr<ScriptCallStack> callStack)
     1147template<bool (CSPDirectiveList::*allowed)(PassRefPtr<ScriptCallStack>, ContentSecurityPolicy::ReportingStatus) const>
     1148bool isAllowedByAllWithCallStack(const CSPDirectiveListVector& policies, PassRefPtr<ScriptCallStack> callStack, ContentSecurityPolicy::ReportingStatus reportingStatus)
    10871149{
    10881150    for (size_t i = 0; i < policies.size(); ++i) {
    1089         if (!(policies[i].get()->*allowed)(callStack))
     1151        if (!(policies[i].get()->*allowed)(callStack, reportingStatus))
    10901152            return false;
    10911153    }
     
    10931155}
    10941156
    1095 template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumber&) const>
    1096 bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const String& contextURL, const WTF::OrdinalNumber& contextLine)
     1157template<bool (CSPDirectiveList::*allowed)(const String&, const WTF::OrdinalNumber&, ContentSecurityPolicy::ReportingStatus) const>
     1158bool isAllowedByAllWithContext(const CSPDirectiveListVector& policies, const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus)
    10971159{
    10981160    for (size_t i = 0; i < policies.size(); ++i) {
    1099         if (!(policies[i].get()->*allowed)(contextURL, contextLine))
     1161        if (!(policies[i].get()->*allowed)(contextURL, contextLine, reportingStatus))
    11001162            return false;
    11011163    }
     
    11131175}
    11141176
    1115 template<bool (CSPDirectiveList::*allowFromURL)(const KURL&) const>
    1116 bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& url)
     1177template<bool (CSPDirectiveList::*allowFromURL)(const KURL&, ContentSecurityPolicy::ReportingStatus) const>
     1178bool isAllowedByAllWithURL(const CSPDirectiveListVector& policies, const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus)
    11171179{
    11181180    if (SchemeRegistry::schemeShouldBypassContentSecurityPolicy(url.protocol()))
     
    11201182
    11211183    for (size_t i = 0; i < policies.size(); ++i) {
    1122         if (!(policies[i].get()->*allowFromURL)(url))
     1184        if (!(policies[i].get()->*allowFromURL)(url, reportingStatus))
    11231185            return false;
    11241186    }
     
    11261188}
    11271189
    1128 bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
    1129 {
    1130     return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_policies, contextURL, contextLine);
    1131 }
    1132 
    1133 bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
    1134 {
    1135     return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers>(m_policies, contextURL, contextLine);
    1136 }
    1137 
    1138 bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
    1139 {
    1140     return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineScript>(m_policies, contextURL, contextLine);
    1141 }
    1142 
    1143 bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const
     1190bool ContentSecurityPolicy::allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1191{
     1192    return isAllowedByAllWithContext<&CSPDirectiveList::allowJavaScriptURLs>(m_policies, contextURL, contextLine, reportingStatus);
     1193}
     1194
     1195bool ContentSecurityPolicy::allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1196{
     1197    return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineEventHandlers>(m_policies, contextURL, contextLine, reportingStatus);
     1198}
     1199
     1200bool ContentSecurityPolicy::allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1201{
     1202    return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineScript>(m_policies, contextURL, contextLine, reportingStatus);
     1203}
     1204
     1205bool ContentSecurityPolicy::allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ContentSecurityPolicy::ReportingStatus reportingStatus) const
    11441206{
    11451207    if (m_overrideInlineStyleAllowed)
    11461208        return true;
    1147     return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_policies, contextURL, contextLine);
    1148 }
    1149 
    1150 bool ContentSecurityPolicy::allowEval(PassRefPtr<ScriptCallStack> callStack) const
    1151 {
    1152     return isAllowedByAllWithCallStack<&CSPDirectiveList::allowEval>(m_policies, callStack);
     1209    return isAllowedByAllWithContext<&CSPDirectiveList::allowInlineStyle>(m_policies, contextURL, contextLine, reportingStatus);
     1210}
     1211
     1212bool ContentSecurityPolicy::allowEval(PassRefPtr<ScriptCallStack> callStack, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1213{
     1214    return isAllowedByAllWithCallStack<&CSPDirectiveList::allowEval>(m_policies, callStack, reportingStatus);
    11531215}
    11541216
     
    11581220}
    11591221
    1160 bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url) const
    1161 {
    1162     return isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_policies, url);
    1163 }
    1164 
    1165 bool ContentSecurityPolicy::allowObjectFromSource(const KURL& url) const
    1166 {
    1167     return isAllowedByAllWithURL<&CSPDirectiveList::allowObjectFromSource>(m_policies, url);
    1168 }
    1169 
    1170 bool ContentSecurityPolicy::allowChildFrameFromSource(const KURL& url) const
    1171 {
    1172     return isAllowedByAllWithURL<&CSPDirectiveList::allowChildFrameFromSource>(m_policies, url);
    1173 }
    1174 
    1175 bool ContentSecurityPolicy::allowImageFromSource(const KURL& url) const
    1176 {
    1177     return isAllowedByAllWithURL<&CSPDirectiveList::allowImageFromSource>(m_policies, url);
    1178 }
    1179 
    1180 bool ContentSecurityPolicy::allowStyleFromSource(const KURL& url) const
    1181 {
    1182     return isAllowedByAllWithURL<&CSPDirectiveList::allowStyleFromSource>(m_policies, url);
    1183 }
    1184 
    1185 bool ContentSecurityPolicy::allowFontFromSource(const KURL& url) const
    1186 {
    1187     return isAllowedByAllWithURL<&CSPDirectiveList::allowFontFromSource>(m_policies, url);
    1188 }
    1189 
    1190 bool ContentSecurityPolicy::allowMediaFromSource(const KURL& url) const
    1191 {
    1192     return isAllowedByAllWithURL<&CSPDirectiveList::allowMediaFromSource>(m_policies, url);
    1193 }
    1194 
    1195 bool ContentSecurityPolicy::allowConnectToSource(const KURL& url) const
    1196 {
    1197     return isAllowedByAllWithURL<&CSPDirectiveList::allowConnectToSource>(m_policies, url);
    1198 }
    1199 
    1200 }
     1222bool ContentSecurityPolicy::allowScriptFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1223{
     1224    return isAllowedByAllWithURL<&CSPDirectiveList::allowScriptFromSource>(m_policies, url, reportingStatus);
     1225}
     1226
     1227bool ContentSecurityPolicy::allowObjectFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1228{
     1229    return isAllowedByAllWithURL<&CSPDirectiveList::allowObjectFromSource>(m_policies, url, reportingStatus);
     1230}
     1231
     1232bool ContentSecurityPolicy::allowChildFrameFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1233{
     1234    return isAllowedByAllWithURL<&CSPDirectiveList::allowChildFrameFromSource>(m_policies, url, reportingStatus);
     1235}
     1236
     1237bool ContentSecurityPolicy::allowImageFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1238{
     1239    return isAllowedByAllWithURL<&CSPDirectiveList::allowImageFromSource>(m_policies, url, reportingStatus);
     1240}
     1241
     1242bool ContentSecurityPolicy::allowStyleFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1243{
     1244    return isAllowedByAllWithURL<&CSPDirectiveList::allowStyleFromSource>(m_policies, url, reportingStatus);
     1245}
     1246
     1247bool ContentSecurityPolicy::allowFontFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1248{
     1249    return isAllowedByAllWithURL<&CSPDirectiveList::allowFontFromSource>(m_policies, url, reportingStatus);
     1250}
     1251
     1252bool ContentSecurityPolicy::allowMediaFromSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1253{
     1254    return isAllowedByAllWithURL<&CSPDirectiveList::allowMediaFromSource>(m_policies, url, reportingStatus);
     1255}
     1256
     1257bool ContentSecurityPolicy::allowConnectToSource(const KURL& url, ContentSecurityPolicy::ReportingStatus reportingStatus) const
     1258{
     1259    return isAllowedByAllWithURL<&CSPDirectiveList::allowConnectToSource>(m_policies, url, reportingStatus);
     1260}
     1261
     1262bool ContentSecurityPolicy::isActive() const
     1263{
     1264    return !m_policies.isEmpty();
     1265}
     1266
     1267void ContentSecurityPolicy::gatherReportURIs(DOMStringList& list) const
     1268{
     1269    for (size_t i = 0; i < m_policies.size(); ++i)
     1270        m_policies[i].get()->gatherReportURIs(list);
     1271}
     1272
     1273}
  • trunk/Source/WebCore/page/ContentSecurityPolicy.h

    r121883 r123722  
    4141class CSPDirectiveList;
    4242class ScriptCallStack;
     43class DOMStringList;
    4344class ScriptExecutionContext;
    4445
     
    6061    };
    6162
     63    enum ReportingStatus {
     64        SendReport,
     65        SuppressReport
     66    };
     67
    6268    void didReceiveHeader(const String&, HeaderType);
    6369
    64     // These functions are wrong becuase they assume that there is only one header.
     70    // These functions are wrong because they assume that there is only one header.
    6571    // FIXME: Replace them with functions that return vectors.
    6672    const String& deprecatedHeader() const;
    6773    HeaderType deprecatedHeaderType() const;
    6874
    69     bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    70     bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    71     bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    72     bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine) const;
    73     bool allowEval(PassRefPtr<ScriptCallStack>) const;
     75    bool allowJavaScriptURLs(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
     76    bool allowInlineEventHandlers(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
     77    bool allowInlineScript(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
     78    bool allowInlineStyle(const String& contextURL, const WTF::OrdinalNumber& contextLine, ReportingStatus = SendReport) const;
     79    bool allowEval(PassRefPtr<ScriptCallStack>, ReportingStatus = SendReport) const;
    7480    bool allowScriptNonce(const String& nonce, const String& contextURL, const WTF::OrdinalNumber& contextLine, const KURL& = KURL()) const;
    7581
    76     bool allowScriptFromSource(const KURL&) const;
    77     bool allowObjectFromSource(const KURL&) const;
    78     bool allowChildFrameFromSource(const KURL&) const;
    79     bool allowImageFromSource(const KURL&) const;
    80     bool allowStyleFromSource(const KURL&) const;
    81     bool allowFontFromSource(const KURL&) const;
    82     bool allowMediaFromSource(const KURL&) const;
    83     bool allowConnectToSource(const KURL&) const;
     82    bool allowScriptFromSource(const KURL&, ReportingStatus = SendReport) const;
     83    bool allowObjectFromSource(const KURL&, ReportingStatus = SendReport) const;
     84    bool allowChildFrameFromSource(const KURL&, ReportingStatus = SendReport) const;
     85    bool allowImageFromSource(const KURL&, ReportingStatus = SendReport) const;
     86    bool allowStyleFromSource(const KURL&, ReportingStatus = SendReport) const;
     87    bool allowFontFromSource(const KURL&, ReportingStatus = SendReport) const;
     88    bool allowMediaFromSource(const KURL&, ReportingStatus = SendReport) const;
     89    bool allowConnectToSource(const KURL&, ReportingStatus = SendReport) const;
    8490
    8591    void setOverrideAllowInlineStyle(bool);
     92
     93    bool isActive() const;
     94    void gatherReportURIs(DOMStringList&) const;
    8695
    8796private:
Note: See TracChangeset for help on using the changeset viewer.