Bug 104479 - CSP 1.1: Experiment with 'reflected-xss' directive.
Summary: CSP 1.1: Experiment with 'reflected-xss' directive.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mike West
URL:
Keywords:
Depends on:
Blocks: 85558
  Show dependency treegraph
 
Reported: 2012-12-09 04:16 PST by Mike West
Modified: 2016-04-13 14:09 PDT (History)
9 users (show)

See Also:


Attachments
Patch (8.66 KB, patch)
2012-12-09 04:21 PST, Mike West
no flags Details | Formatted Diff | Diff
WIP (11.06 KB, patch)
2012-12-09 09:44 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (30.86 KB, patch)
2013-01-22 02:17 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (31.30 KB, patch)
2013-01-22 02:18 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (31.18 KB, patch)
2013-02-11 05:58 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (86.82 KB, patch)
2013-02-13 07:16 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch (87.10 KB, patch)
2013-02-20 01:17 PST, Mike West
no flags Details | Formatted Diff | Diff
Patch for landing (93.89 KB, patch)
2013-02-24 12:31 PST, Mike West
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mike West 2012-12-09 04:16:18 PST
http://lists.w3.org/Archives/Public/public-webappsec/2012Nov/0061.html proposed folding 'X-XSS-Protection' into the CSP 1.1 spec. I'm looking into how hooking that up to XSSAuditor might look in WebKit.

Spec: https://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#reflected-xss--experimental
Comment 1 Mike West 2012-12-09 04:21:09 PST
Created attachment 178408 [details]
Patch
Comment 2 Build Bot 2012-12-09 09:25:52 PST
Comment on attachment 178408 [details]
Patch

Attachment 178408 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/15230235
Comment 3 Mike West 2012-12-09 09:44:15 PST
Created attachment 178424 [details]
WIP
Comment 4 Mike West 2013-01-14 05:51:21 PST
Hey Tom, could you help me put together some tests for this? I'm sure that one of the XSSAuditor tests is sufficiently minimal to serve as an on/off check, but all of them that I've spot-checked seem pretty complex. Could you point me in the right direction?
Comment 5 Thomas Sepez 2013-01-14 10:16:54 PST
I'd take a look at LayoutTests/http/tests/security/xssAuditor/resource/echo-intertag.pl, which is an XSS-vulnerable script.  I'd think you might have to add a new query parameter in this script to generate a CSP header with the reflected-xss directive when present. You'd then invoke this along the lines of LayoutTests/http/tests/security/xssAuditor/script-tag.html.
Comment 6 Mike West 2013-01-22 02:17:39 PST
Created attachment 183936 [details]
Patch
Comment 7 Mike West 2013-01-22 02:18:42 PST
Created attachment 183937 [details]
Patch
Comment 8 Mike West 2013-01-22 02:21:04 PST
(In reply to comment #5)
> I'd take a look at LayoutTests/http/tests/security/xssAuditor/resource/echo-intertag.pl, which is an XSS-vulnerable script.  I'd think you might have to add a new query parameter in this script to generate a CSP header with the reflected-xss directive when present. You'd then invoke this along the lines of LayoutTests/http/tests/security/xssAuditor/script-tag.html.

Thanks, Tom. This was really helpful.

Would you (and Adam (hi Adam!)) mind taking a look at the implementation? I want to put some more tests together to make sure the combination of X-XSS-Protection and the new CSP directive makes sense, but this is the direction that I think makes sense.

Once we agree on a method that makes sense, I'll need to update the spec to make sure the behavior is comprehensible.

Thanks!
Comment 9 Build Bot 2013-01-22 02:42:59 PST
Comment on attachment 183937 [details]
Patch

Attachment 183937 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://queues.webkit.org/results/16036503
Comment 10 Build Bot 2013-01-22 02:49:10 PST
Comment on attachment 183937 [details]
Patch

Attachment 183937 [details] did not pass mac-ews (mac):
Output: http://queues.webkit.org/results/16044469
Comment 11 Mike West 2013-02-11 05:58:35 PST
Created attachment 187553 [details]
Patch
Comment 12 Mike West 2013-02-11 06:00:07 PST
Rebased this on top of the parsing/threading work that's ongoing.

Tom, Adam: would you mind taking a look when you have a few minutes?
Comment 13 Adam Barth 2013-02-11 10:36:49 PST
Comment on attachment 187553 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=187553&action=review

> Source/WebCore/html/parser/XSSAuditor.cpp:193
> +static XSSProtectionDisposition combineXSSProtectionHeaderAndCSP(XSSProtectionDisposition xssProtection, ContentSecurityPolicy::ReflectedXSSDisposition reflectedXSS)
> +{
> +    if (xssProtection == XSSProtectionBlockEnabled || reflectedXSS == ContentSecurityPolicy::BlockReflectedXSS)
> +        return XSSProtectionBlockEnabled;
> +
> +    if (xssProtection == XSSProtectionEnabled || reflectedXSS == ContentSecurityPolicy::FilterReflectedXSS)
> +        return XSSProtectionEnabled;
> +
> +    if (xssProtection == XSSProtectionInvalid || reflectedXSS == ContentSecurityPolicy::ReflectedXSSInvalid)
> +        return XSSProtectionEnabled;
> +
> +    if (xssProtection == XSSProtectionDisabled || reflectedXSS == ContentSecurityPolicy::AllowReflectedXSS)
> +        return XSSProtectionDisabled;
> +
> +    // If neither header is set, enable XSSAuditor.
> +    return XSSProtectionEnabled;
> +}

Can we change XSSProtectionDisposition to use ContentSecurityPolicy::ReflectedXSSDisposition and the make this function into something like std::max ?
Comment 14 Thomas Sepez 2013-02-11 11:06:21 PST
> Tom, Adam: would you mind taking a look when you have a few minutes?
Mike, this seems reasonable to me.  My only question would be whether you have a test that checks for the reflected-xss clause mixed in with various other CSP clauses to make sure that it doesn't break the existing ones, or vice versa.
Comment 15 Mike West 2013-02-11 11:20:32 PST
(In reply to comment #13)
> (From update of attachment 187553 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=187553&action=review
> 
> > Source/WebCore/html/parser/XSSAuditor.cpp:193
> > +static XSSProtectionDisposition combineXSSProtectionHeaderAndCSP(XSSProtectionDisposition xssProtection, ContentSecurityPolicy::ReflectedXSSDisposition reflectedXSS)
> > +{
> > +    if (xssProtection == XSSProtectionBlockEnabled || reflectedXSS == ContentSecurityPolicy::BlockReflectedXSS)
> > +        return XSSProtectionBlockEnabled;
> > +
> > +    if (xssProtection == XSSProtectionEnabled || reflectedXSS == ContentSecurityPolicy::FilterReflectedXSS)
> > +        return XSSProtectionEnabled;
> > +
> > +    if (xssProtection == XSSProtectionInvalid || reflectedXSS == ContentSecurityPolicy::ReflectedXSSInvalid)
> > +        return XSSProtectionEnabled;
> > +
> > +    if (xssProtection == XSSProtectionDisabled || reflectedXSS == ContentSecurityPolicy::AllowReflectedXSS)
> > +        return XSSProtectionDisabled;
> > +
> > +    // If neither header is set, enable XSSAuditor.
> > +    return XSSProtectionEnabled;
> > +}
> 
> Can we change XSSProtectionDisposition to use ContentSecurityPolicy::ReflectedXSSDisposition and the make this function into something like std::max ?

We could get closer, but there's still the weirdness of wanting to enable the feature if neither is set, or if both are invalid. I'll take a look at integrating them more closely.
Comment 16 Mike West 2013-02-11 11:22:13 PST
(In reply to comment #14)
> > Tom, Adam: would you mind taking a look when you have a few minutes?
> Mike, this seems reasonable to me.  My only question would be whether you have a test that checks for the reflected-xss clause mixed in with various other CSP clauses to make sure that it doesn't break the existing ones, or vice versa.

Not yet. If you two are happy with the general direction, then I'll add that 5x5 set of tests. :)
Comment 17 Build Bot 2013-02-12 10:20:15 PST
Comment on attachment 187553 [details]
Patch

Attachment 187553 [details] did not pass mac-wk2-ews (mac-wk2):
Output: http://queues.webkit.org/results/16454346

New failing tests:
compositing/checkerboard.html
accessibility/anchor-linked-anonymous-block-crash.html
http/tests/cache/cancel-multiple-post-xhrs.html
animations/3d/state-at-end-event-transform.html
animations/animation-add-events-in-handler.html
animations/3d/replace-filling-transform.html
http/tests/cache/history-only-cached-subresource-loads.html
compositing/bounds-in-flipped-writing-mode.html
accessibility/accessibility-node-reparent.html
animations/animation-border-overflow.html
accessibility/accessibility-object-detached.html
accessibility/anonymous-render-block-in-continuation-causes-crash.html
animations/animation-controller-drt-api.html
compositing/absolute-position-changed-with-composited-parent-layer.html
compositing/absolute-position-changed-in-composited-layer.html
http/tests/cache/iframe-304-crash.html
animations/3d/transform-perspective.html
http/tests/cache/cancel-during-failure-crash.html
canvas/philip/tests/2d.clearRect+fillRect.alpha0.5.html
canvas/philip/tests/2d.clearRect.basic.html
animations/3d/transform-origin-vs-functions.html
animations/animation-css-rule-types.html
canvas/philip/tests/2d.clearRect+fillRect.basic.html
canvas/philip/tests/2d.clearRect+fillRect.alpha0.html
Comment 18 Mike West 2013-02-13 07:16:43 PST
Created attachment 188079 [details]
Patch
Comment 19 Mike West 2013-02-13 07:18:26 PST
(In reply to comment #18)
> Created an attachment (id=188079) [details]
> Patch

This patch switches XSSAuditor's internals to use ContentSecurityPolicy::ReflectedXSSDisposition to determine state, and adds a pile of tests to verify behavior when mixing X-XSS-Protection and Content-Security-Policy headers.

Would you mind taking another look, Adam and Tom?

Thanks!
Comment 20 Mike West 2013-02-19 12:07:08 PST
(In reply to comment #19)
> (In reply to comment #18)
> > Created an attachment (id=188079) [details] [details]
> > Patch
> 
> This patch switches XSSAuditor's internals to use ContentSecurityPolicy::ReflectedXSSDisposition to determine state, and adds a pile of tests to verify behavior when mixing X-XSS-Protection and Content-Security-Policy headers.
> 
> Would you mind taking another look, Adam and Tom?
> 
> Thanks!

Ping. :)
Comment 21 Thomas Sepez 2013-02-19 16:45:47 PST
Comment on attachment 188079 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=188079&action=review

> Source/WebCore/page/ContentSecurityPolicy.cpp:1632
> +            disposition = m_policies[i]->reflectedXSSDisposition();

Could this just be dispostion = std::max(disposition, m_policies[i]->reflectedXSSDisposition())

> Source/WebCore/page/ContentSecurityPolicy.h:80
> +    };

Maybe a comment about the order being important for later comparisions.
Comment 22 Thomas Sepez 2013-02-19 16:46:26 PST
The rest looks good.
Comment 23 Mike West 2013-02-20 01:17:39 PST
Created attachment 189263 [details]
Patch
Comment 24 Mike West 2013-02-20 01:18:45 PST
(In reply to comment #21)
> (From update of attachment 188079 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=188079&action=review
> 
> > Source/WebCore/page/ContentSecurityPolicy.cpp:1632
> > +            disposition = m_policies[i]->reflectedXSSDisposition();
> 
> Could this just be dispostion = std::max(disposition, m_policies[i]->reflectedXSSDisposition())
> 
> > Source/WebCore/page/ContentSecurityPolicy.h:80
> > +    };
> 
> Maybe a comment about the order being important for later comparisions.

Both good ideas, I've jammed them into the latest patch.

Thanks!
Comment 25 Adam Barth 2013-02-22 11:25:00 PST
Comment on attachment 189263 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=189263&action=review

> Source/WebCore/html/parser/XSSAuditor.cpp:177
> +static ContentSecurityPolicy::ReflectedXSSDisposition combineXSSProtectionHeaderAndCSP(ContentSecurityPolicy::ReflectedXSSDisposition xssProtection, ContentSecurityPolicy::ReflectedXSSDisposition reflectedXSS)

I might add a comment to the ReflectedXSSDisposition declaration to remind folks to check this function if they add a new disposition.

> Source/WebCore/html/parser/XSSAuditor.cpp:266
> +        m_reportURL = xssProtectionReportURL; // FIXME: Combine the two report URLs in some reasonable way.

Do we need to make a copy of this URL to handle the threaded parser case?
Comment 26 Mike West 2013-02-22 11:28:53 PST
(In reply to comment #25)
> (From update of attachment 189263 [details])
> View in context: https://bugs.webkit.org/attachment.cgi?id=189263&action=review
> 
> > Source/WebCore/html/parser/XSSAuditor.cpp:177
> > +static ContentSecurityPolicy::ReflectedXSSDisposition combineXSSProtectionHeaderAndCSP(ContentSecurityPolicy::ReflectedXSSDisposition xssProtection, ContentSecurityPolicy::ReflectedXSSDisposition reflectedXSS)
> 
> I might add a comment to the ReflectedXSSDisposition declaration to remind folks to check this function if they add a new disposition.

Makes good sense.

> > Source/WebCore/html/parser/XSSAuditor.cpp:266
> > +        m_reportURL = xssProtectionReportURL; // FIXME: Combine the two report URLs in some reasonable way.
> 
> Do we need to make a copy of this URL to handle the threaded parser case?

That sounds reasonable. Would `isolatedCopy()` be the right mechanism here?
Comment 27 Adam Barth 2013-02-22 11:42:57 PST
Comment on attachment 189263 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=189263&action=review

>>> Source/WebCore/html/parser/XSSAuditor.cpp:266
>>> +        m_reportURL = xssProtectionReportURL; // FIXME: Combine the two report URLs in some reasonable way.
>> 
>> Do we need to make a copy of this URL to handle the threaded parser case?
> 
> That sounds reasonable. Would `isolatedCopy()` be the right mechanism here?

It looks like it's ok actually because xssProtectionReportURL comes from document->completeURL, which makes a new copy anyway.  There's an ASSERT in the threaded parser that will catch it if we mess up.
Comment 28 Mike West 2013-02-24 12:31:12 PST
Created attachment 189985 [details]
Patch for landing
Comment 29 WebKit Review Bot 2013-02-24 14:42:13 PST
Comment on attachment 189985 [details]
Patch for landing

Clearing flags on attachment: 189985

Committed r143880: <http://trac.webkit.org/changeset/143880>
Comment 30 WebKit Review Bot 2013-02-24 14:42:18 PST
All reviewed patches have been landed.  Closing bug.