12018-05-06 Daniel Bates <dabates@apple.com>
2
3 CSP status-code incorrect for document blocked due to violation of its frame-ancestors directive
4 https://bugs.webkit.org/show_bug.cgi?id=185366
5
6 Reviewed by NOBODY (OOPS!).
7
8 Fixes an issue where the status-code in the sent CSP report for an HTTP document blocked because
9 its frame-ancestors directive was violated would be the status code of the previously loaded
10 document in the frame. If the previously loaded document was about:blank then this would be 0.
11
12 Currently whenever we send a CSP report we ask the document's loader (Document::loader()) for the
13 HTTP status code for the last response. Document::loader() returns the loader for the last committed
14 document its frame. For a frame-ancestors violation, a CSP report is sent before the document
15 that had the frame-ancestors directive has been committed and after it has been associate with a frame.
16 As a result we are in are in a transient transition state for the frame and hence the last response
17 for new document's loader (Document::loader()) is actually the last response of the previously loaded
18 document in the frame. Instead we need to take care to tell CSP about the HTTP status code for the
19 response associated with the document the CSP came from.
20
21 * dom/Document.cpp:
22 (WebCore::Document::processHttpEquiv):
23 (WebCore::Document::initSecurityContext):
24 Pass the HTTP status code to CSP.
25
26 * page/csp/ContentSecurityPolicy.cpp:
27 (WebCore::ContentSecurityPolicy::copyStateFrom):
28 (WebCore::ContentSecurityPolicy::responseHeaders const):
29 (WebCore::ContentSecurityPolicy::didReceiveHeaders):
30 (WebCore::ContentSecurityPolicy::didReceiveHeader):
31 (WebCore::ContentSecurityPolicy::reportViolation const):
32 * page/csp/ContentSecurityPolicy.h:
33 Modify existing functions to take the HTTP status code, store it in a instance variable,
34 and reference this variable when reporting a violation.
35
36 * page/csp/ContentSecurityPolicyResponseHeaders.cpp:
37 (WebCore::ContentSecurityPolicyResponseHeaders::ContentSecurityPolicyResponseHeaders):
38 (WebCore::ContentSecurityPolicyResponseHeaders::isolatedCopy const):
39 * page/csp/ContentSecurityPolicyResponseHeaders.h:
40 (WebCore::ContentSecurityPolicyResponseHeaders::encode const):
41 (WebCore::ContentSecurityPolicyResponseHeaders::decode):
42 Store the HTTP status code along with the response headers.
43