12012-07-19 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 NOBODY (OOPS!).
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