<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>68921</bug_id>
          
          <creation_ts>2011-09-27 11:44:02 -0700</creation_ts>
          <short_desc>CSP doesn&apos;t work for a wide variety of cases</short_desc>
          <delta_ts>2011-09-28 11:06:56 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebCore Misc.</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://erlend.oftedal.no/blog/csp/readiness/latest.php</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Boris Smus">smus</reporter>
          <assigned_to name="Adam Barth">abarth</assigned_to>
          <cc>abarth</cc>
    
    <cc>apf</cc>
    
    <cc>sam</cc>
    
    <cc>webkit.review.bot</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>474113</commentid>
    <comment_count>0</comment_count>
    <who name="Boris Smus">smus</who>
    <bug_when>2011-09-27 11:44:02 -0700</bug_when>
    <thetext>In my own tests, as well as in more comprehensive test suites, CSP policy is not being followed as expected. 

This test suite: http://erlend.oftedal.no/blog/csp/readiness/latest.php provides both X-Content-Security-Policy and X-WebKit-CSP headers, and uses the new syntax (&apos;default-src&apos; rather than &apos;allow&apos;), but fails for most test cases.

Do we have a CSP unit test suite?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474117</commentid>
    <comment_count>1</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2011-09-27 11:48:36 -0700</bug_when>
    <thetext>&gt; Do we have a CSP unit test suite?

Our CSP tests are here:

http://trac.webkit.org/browser/trunk/LayoutTests/http/tests/security/contentSecurityPolicy

I&apos;m not sure why we&apos;re doing so badly on the oftedal test suite.  I&apos;ll investigate.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474455</commentid>
    <comment_count>2</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-09-27 20:32:32 -0700</bug_when>
    <thetext>This looks like an issue with our port matching code in CSPSource.  In the case that the source&apos;s port is set to 0 (for no port specified) and the URL to match has no port specified (also set to 0), the code checks if 0 is the default port for the protocol. 

        int port = url.port();
        return port ? port == m_port : isDefaultPortForProtocol(m_port, url.protocol());

In this case, we should be returning true, something like this should probably work:


    bool portMatches(const KURL&amp; url) const
    {
        if (m_portHasWildcard)
            return true;
        
        int port = url.port();
        if (port == m_port)
            return true;
    
        if (!port)
            return isDefaultPortForProtocol(m_port, m_scheme);

        if (!m_port)
            return isDefaultPortForProtocol(port, m_scheme);

        return false;
    }</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474457</commentid>
    <comment_count>3</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-09-27 20:36:23 -0700</bug_when>
    <thetext>Fixing that issue, it looks like we pass all the same tests that Firefox does.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474460</commentid>
    <comment_count>4</comment_count>
    <who name="Sam Weinig">sam</who>
    <bug_when>2011-09-27 20:39:11 -0700</bug_when>
    <thetext>We probably have no tests for this case, since our testing harness requires using a non-default port :(.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474482</commentid>
    <comment_count>5</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2011-09-27 21:33:55 -0700</bug_when>
    <thetext>Ah, that makes a lot of sense.  Thanks Sam.  Are you planning to post a patch, or should I?  (Also, any thoughts on how we can test this bug?)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474826</commentid>
    <comment_count>6</comment_count>
      <attachid>109035</attachid>
    <who name="Adam Barth">abarth</who>
    <bug_when>2011-09-28 10:42:01 -0700</bug_when>
    <thetext>Created attachment 109035
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474848</commentid>
    <comment_count>7</comment_count>
      <attachid>109035</attachid>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2011-09-28 11:06:01 -0700</bug_when>
    <thetext>Comment on attachment 109035
Patch

Clearing flags on attachment: 109035

Committed r96239: &lt;http://trac.webkit.org/changeset/96239&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474849</commentid>
    <comment_count>8</comment_count>
    <who name="WebKit Review Bot">webkit.review.bot</who>
    <bug_when>2011-09-28 11:06:06 -0700</bug_when>
    <thetext>All reviewed patches have been landed.  Closing bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>474854</commentid>
    <comment_count>9</comment_count>
    <who name="Adam Barth">abarth</who>
    <bug_when>2011-09-28 11:06:56 -0700</bug_when>
    <thetext>*** Bug 67008 has been marked as a duplicate of this bug. ***</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>109035</attachid>
            <date>2011-09-28 10:42:01 -0700</date>
            <delta_ts>2011-09-28 11:06:01 -0700</delta_ts>
            <desc>Patch</desc>
            <filename>bug-68921-20110928104200.patch</filename>
            <type>text/plain</type>
            <size>1753</size>
            <attacher name="Adam Barth">abarth</attacher>
            
              <data encoding="base64">SW5kZXg6IFNvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwo9PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09Ci0tLSBTb3VyY2UvV2Vi
Q29yZS9DaGFuZ2VMb2cJKHJldmlzaW9uIDk2MjM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TEgR3lwIHJ1bGVzCkluZGV4OiBTb3Vy
Y2UvV2ViQ29yZS9wYWdlL0NvbnRlbnRTZWN1cml0eVBvbGljeS5jcHAKPT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PQotLS0g
U291cmNlL1dlYkNvcmUvcGFnZS9Db250ZW50U2VjdXJpdHlQb2xpY3kuY3BwCShyZXZpc2lvbiA5
NjIyOSkKKysrIFNvdXJjZS9XZWJDb3JlL3BhZ2UvQ29udGVudFNlY3VyaXR5UG9saWN5LmNwcAko
d29ya2luZyBjb3B5KQpAQCAtMTQ3LDggKzE0NywxOSBAQCBwcml2YXRlOgogICAgIHsKICAgICAg
ICAgaWYgKG1fcG9ydEhhc1dpbGRjYXJkKQogICAgICAgICAgICAgcmV0dXJuIHRydWU7CisKICAg
ICAgICAgaW50IHBvcnQgPSB1cmwucG9ydCgpOwotICAgICAgICByZXR1cm4gcG9ydCA/IHBvcnQg
PT0gbV9wb3J0IDogaXNEZWZhdWx0UG9ydEZvclByb3RvY29sKG1fcG9ydCwgdXJsLnByb3RvY29s
KCkpOworCisgICAgICAgIGlmIChwb3J0ID09IG1fcG9ydCkKKyAgICAgICAgICAgIHJldHVybiB0
cnVlOworCisgICAgICAgIGlmICghcG9ydCkKKyAgICAgICAgICAgIHJldHVybiBpc0RlZmF1bHRQ
b3J0Rm9yUHJvdG9jb2wobV9wb3J0LCBtX3NjaGVtZSk7CisKKyAgICAgICAgaWYgKCFtX3BvcnQp
CisgICAgICAgICAgICByZXR1cm4gaXNEZWZhdWx0UG9ydEZvclByb3RvY29sKHBvcnQsIG1fc2No
ZW1lKTsKKworICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgfQogCiAgICAgYm9vbCBpc1NjaGVt
ZU9ubHkoKSBjb25zdCB7IHJldHVybiBtX2hvc3QuaXNFbXB0eSgpOyB9Cg==
</data>

          </attachment>
      

    </bug>

</bugzilla>