<?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>270784</bug_id>
          
          <creation_ts>2024-03-11 03:46:39 -0700</creation_ts>
          <short_desc>CSP: External script with matching SRI hash is blocked when &apos;strict-dynamic&apos; is present in script-src</short_desc>
          <delta_ts>2024-08-21 14:14:37 -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>Safari 17</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 14</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=175277</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</reporter>
          <assigned_to name="Luke Warlow">lwarlow</assigned_to>
          <cc>bfulgham</cc>
    
    <cc>karlcow</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wilander</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2020034</commentid>
    <comment_count>0</comment_count>
      <attachid>470284</attachid>
    <who name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</who>
    <bug_when>2024-03-11 03:46:39 -0700</bug_when>
    <thetext>Created attachment 470284
HTML file that loads an external script with SRI hash

When `script-src &apos;strict-dynamic&apos;` is present in a CSP, external scripts with matching SRI hashes (via `integrity`) are blocked.
If &apos;strict-dynamic&apos; is removed, then scripts with a matching SRI are allowed (subject to the regular CSP hash checks).

We recently ran into this at wolt.com, when migrating to a new CSP design. We rely on &apos;strict-dynamic&apos; with external script SRI hashes for our script loading. This works as expected on Firefox and Chrome, but I admit that I am not super familiar with the spec, to make a call either way :)

At the moment, we have to use user agent sniffing to avoid the scripts getting blocked on Safari, which is not ideal. We would like to understand whether this blocking is intended or incidental.

CSP for external script SRI hashes was implemented at https://bugs.webkit.org/show_bug.cgi?id=233911, but it does not specifically address &apos;strict-dynamic&apos;, as far as I can tell.

I have a reproduction at https://github.com/fpapado/csp-strict-dynamic-external-script-hash and a PR for WPT, if that runner is more familiar https://github.com/web-platform-tests/wpt/pull/44769. I am also attaching an index.html file, but there is a single attachment limit, so it is not useful by itself.

Please let me know if there is any other information that I can provide, and I will get back to you promptly! It&apos;s likely I missed something.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2020035</commentid>
    <comment_count>1</comment_count>
      <attachid>470285</attachid>
    <who name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</who>
    <bug_when>2024-03-11 03:47:25 -0700</bug_when>
    <thetext>Created attachment 470285
External script file</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2020255</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-03-11 15:16:49 -0700</bug_when>
    <thetext>&lt;rdar://problem/124410909&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2027294</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-04-09 17:46:26 -0700</bug_when>
    <thetext>Maybe it would be worth to create additional WPT tests for this. 
https://wpt.fyi/results/content-security-policy?label=master&amp;label=experimental&amp;aligned&amp;q=safari%3Afail%20firefox%3Apass%20chrome%3Apass</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2027416</commentid>
    <comment_count>4</comment_count>
    <who name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</who>
    <bug_when>2024-04-10 05:53:01 -0700</bug_when>
    <thetext>(In reply to Karl Dubost from comment #3)
&gt; Maybe it would be worth to create additional WPT tests for this. 
&gt; https://wpt.fyi/results/content-security-
&gt; policy?label=master&amp;label=experimental&amp;aligned&amp;q=safari%3Afail%20firefox%3Apa
&gt; ss%20chrome%3Apass

Definitely, if I am reading it right, there is a gap for this case in WPT at the moment.

I made a start in this PR https://github.com/web-platform-tests/wpt/pull/44769, adding a case to the existing content-security-policy/script-src/script-src-strict_dynamic_hashes tests. I am not super familiar with authoring WPT though, so I might have missed more idiomatic ways of making those assertions :)

Here is the deployed preview branch from WPT&apos;s CI: https://wpt.fyi/results/content-security-policy/script-src/script-src-strict_dynamic_hashes.html?label=pr_head&amp;max-count=1&amp;pr=44769</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2027679</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-04-10 22:33:29 -0700</bug_when>
    <thetext>Fotis,

Anne
left a comment on https://github.com/web-platform-tests/wpt/pull/44769#issuecomment-2048945493
and opened https://github.com/w3c/webappsec-csp/issues/653</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2028705</commentid>
    <comment_count>6</comment_count>
    <who name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</who>
    <bug_when>2024-04-15 21:51:27 -0700</bug_when>
    <thetext>Hi Karl! Thank you and Anne for the help with this. 

The spec has now been changed to clarify this behaviour (https://github.com/w3c/webappsec-csp/issues/653) and the WPT test is merged (relevant view: https://wpt.fyi/results/content-security-policy/script-src/script-src-strict_dynamic_hashes.html?label=master&amp;label=experimental&amp;aligned&amp;q=safari%3Afail%20firefox%3Apass%20chrome%3Apass).

Please let me know if there is anything else I can do on my side. Otherwise, happy to leave this to you all. Thanks again :)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2028712</commentid>
    <comment_count>7</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-04-15 22:10:31 -0700</bug_when>
    <thetext>Thanks a lot Fotis. This is super helpful.
This is being tracked internally too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2053608</commentid>
    <comment_count>8</comment_count>
    <who name="Yesudeep Mangalapilly">yesudeep</who>
    <bug_when>2024-08-18 16:51:51 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/32365</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2054035</commentid>
    <comment_count>9</comment_count>
    <who name="Luke Warlow">lwarlow</who>
    <bug_when>2024-08-20 03:04:04 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/32449</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2054507</commentid>
    <comment_count>10</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-08-21 14:14:35 -0700</bug_when>
    <thetext>Committed 282577@main (88833ba4cdcb): &lt;https://commits.webkit.org/282577@main&gt;

Reviewed commits have been landed. Closing PR #32449 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>470284</attachid>
            <date>2024-03-11 03:46:39 -0700</date>
            <delta_ts>2024-03-11 03:46:39 -0700</delta_ts>
            <desc>HTML file that loads an external script with SRI hash</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>916</size>
            <attacher name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIEhUTUw+CjxodG1sPgoKPGhlYWQ+CiAgICA8dGl0bGU+YHN0cmljdC1keW5hbWlj
YCBhbGxvd3Mgc2NyaXB0cyBtYXRjaGluZyBoYXNoZXMgcHJlc2VudCBpbiB0aGUgcG9saWN5Ljwv
dGl0bGU+CiAgICA8bWV0YSBodHRwLWVxdWl2PSJDb250ZW50LVNlY3VyaXR5LVBvbGljeSIgY29u
dGVudD0ic2NyaXB0LXNyYyAnc3RyaWN0LWR5bmFtaWMnICdub25jZS1kdW1teScgJ3NoYTI1Ni13
SWMzS3RxT3VURkV1NnQxN3NJQnVPc3dna1Y0MDZWSnZoU2s3OUd3NlUwPSciPgo8L2hlYWQ+Cgo8
Ym9keT4KICAgIDxoMT5gc3RyaWN0LWR5bmFtaWNgIGFsbG93cyBzY3JpcHRzIG1hdGNoaW5nIGhh
c2hlcyBwcmVzZW50IGluIHRoZSBwb2xpY3kuPC9oMT4KICAgIDxwPklmIHRoZSB0ZXN0IHN1Y2Nl
ZWRzLCBub3RoaW5nIHdpbGwgYmUgbG9nZ2VkIGJlbG93LjwvcD4KICAgIDxkaXYgaWQ9J2xvZyc+
PC9kaXY+CgogICAgPHNjcmlwdCBub25jZT0nZHVtbXknPgogICAgICAgIHdpbmRvdy5hZGRFdmVu
dExpc3RlbmVyKCdzZWN1cml0eXBvbGljeXZpb2xhdGlvbicsIGZ1bmN0aW9uKGUpIHsKICAgICAg
ICAgICAgZG9jdW1lbnQuZ2V0RWxlbWVudEJ5SWQoJ2xvZycpLmFwcGVuZCgndW5leHBlY3RlZCBD
U1AgdmlvbGF0aW9uIHJlcG9ydCcpCiAgICAgICAgICAgIGNvbnNvbGUuZXJyb3IoZSkKICAgICAg
ICB9KTsKICAgIDwvc2NyaXB0PgoKICAgIDxzY3JpcHQgbm9uY2U9J2R1bW15Jz4KICAgICAgICB2
YXIgZXh0ZXJuYWxSYW4gPSBmYWxzZTsKICAgIDwvc2NyaXB0PgogICAgPHNjcmlwdCBzcmM9Jy4v
ZXh0ZXJuYWxTY3JpcHQuanMnCiAgICAgICAgaW50ZWdyaXR5PSJzaGEyNTYtd0ljM0t0cU91VEZF
dTZ0MTdzSUJ1T3N3Z2tWNDA2Vkp2aFNrNzlHdzZVMD0iPjwvc2NyaXB0Pgo8L2JvZHk+Cgo8L2h0
bWw+Cg==
</data>

          </attachment>
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>470285</attachid>
            <date>2024-03-11 03:47:25 -0700</date>
            <delta_ts>2024-03-11 03:47:25 -0700</delta_ts>
            <desc>External script file</desc>
            <filename>externalScript.js</filename>
            <type>text/javascript</type>
            <size>19</size>
            <attacher name="Fotis Papadogeorgopoulos">fotis.papadogeorgopoulos</attacher>
            
              <data encoding="base64">ZXh0ZXJuYWxSYW4gPSB0cnVlOw==
</data>

          </attachment>
      

    </bug>

</bugzilla>