12013-02-13 Mike West <mkwst@chromium.org>
2
3 CSP 1.1: Experiment with 'reflected-xss' directive.
4 https://bugs.webkit.org/show_bug.cgi?id=104479
5
6 Reviewed by NOBODY (OOPS!).
7
8 Content Security Policy 1.1 defines a 'reflected-xss' directive that
9 works in much the same way as WebKit's current 'X-XSS-Protection'
10 header[1]. This patch implements the new directive by parsing it
11 inside ContentSecurityPolicy, and exposing that state to XSSAuditor.
12
13 XSSAuditor now grabs the CSP directive's state, and mixes it with the
14 X-XSS-Protection header's state to determine how the page should be
15 handled. Moreover, both headers' states are now expressed in terms of
16 ContentSecurityPolicy::ReflectedXSSDisposition.
17
18 [1]: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#reflected-xss--experimental
19
20 Tests: http/tests/security/contentSecurityPolicy/1.1/reflected-xss-allow.html
21 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-allow-allow.html
22 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-allow-block.html
23 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-allow-filter.html
24 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-allow-invalid.html
25 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-allow-unset.html
26 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-block-allow.html
27 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-block-block.html
28 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-block-filter.html
29 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-block-invalid.html
30 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-block-unset.html
31 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-filter-allow.html
32 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-filter-block.html
33 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-filter-filter.html
34 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-filter-invalid.html
35 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-filter-unset.html
36 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-invalid-allow.html
37 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-invalid-block.html
38 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-invalid-filter.html
39 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-invalid-invalid.html
40 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-invalid-unset.html
41 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-unset-allow.html
42 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-unset-block.html
43 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-unset-filter.html
44 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-unset-invalid.html
45 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-and-xss-protection-unset-unset.html
46 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-block.html
47 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-empty.html
48 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-filter.html
49 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-invalid.html
50 http/tests/security/contentSecurityPolicy/1.1/reflected-xss-parsing.html
51
52 * html/parser/XSSAuditor.cpp:
53 (WebCore::combineXSSProtectionHeaderAndCSP):
54 Given both headers' states, return the state which the XSSAuditor
55 should use when parsing a page. Blocking overrides filtering, which
56 overrides disabling.
57 (WebCore):
58 (WebCore::XSSAuditor::init):
59 Process the 'X-XSS-Protection' header before grabbing the CSP
60 header's state. Both are passed into the new
61 combineXSSProtectionHeaderAndCSP method to generate the final
62 state that ought to be used.
63 (WebCore::XSSAuditor::XSSAuditor):
64 (WebCore::XSSAuditor::filterToken):
65 * html/parser/XSSAuditor.h:
66 Switch to ContentSecurityPolicy::ReflectedXSSDisposition internally
67 in XSSAuditor.
68 * page/ContentSecurityPolicy.cpp:
69 (WebCore::CSPDirectiveList::reflectedXSSDisposition):
70 Enum defining the possible state of the 'reflected-xss' CSP directive.
71 (CSPDirectiveList):
72 (WebCore::CSPDirectiveList::CSPDirectiveList):
73 (WebCore::CSPDirectiveList::parseReflectedXSS):
74 Given a 'reflected-xss' directive's value, set the
75 ReflectedXSSDisposition into a new property on the CSPDirectiveList.
76 (WebCore):
77 (WebCore::CSPDirectiveList::addDirective):
78 Accept 'reflected-xss' as a valid directive if we're in
79 experimental mode.
80 (WebCore::ContentSecurityPolicy::reflectedXSSDisposition):
81 Expose the directive's state via the public API.
82 (WebCore::ContentSecurityPolicy::reportInvalidReflectedXSS):
83 Generate console errors when invalid reflected-xss directive values
84 are encounted during parsing.
85 * page/ContentSecurityPolicy.h:
86 * platform/network/HTTPParsers.cpp:
87 (WebCore::parseXSSProtectionHeader):
88 * platform/network/HTTPParsers.h:
89 (WebCore):
90 Start using ContentSecurityPolicy::ReflectedXSSDisposition rather
91 than the XSSProtectionDisposition enum.
92