<?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>222484</bug_id>
          
          <creation_ts>2021-02-26 11:44:42 -0800</creation_ts>
          <short_desc>CSP: Link header with rel=preload does not recognize nonces</short_desc>
          <delta_ts>2025-08-22 12:49:17 -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>WebKit Misc.</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=238014</see_also>
    
    <see_also>https://github.com/web-platform-tests/wpt/pull/54454</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="Aaron Shim">aaronshim</reporter>
          <assigned_to name="Ryan Reno">rreno</assigned_to>
          <cc>achristensen</cc>
    
    <cc>ahmad.saleem792</cc>
    
    <cc>beidson</cc>
    
    <cc>bfulgham</cc>
    
    <cc>rreno</cc>
    
    <cc>smoley</cc>
    
    <cc>tao.zhou</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1733896</commentid>
    <comment_count>0</comment_count>
    <who name="Aaron Shim">aaronshim</who>
    <bug_when>2021-02-26 11:44:42 -0800</bug_when>
    <thetext>Safari does not recognize CSP nonces that are sent as a part of the Link header.

### Observed Behavior ###

Visit https://cloud.arturjanc.com/s/safari-link-nonce/link-header.

Following headers are sent:

Link: &lt;https://arturjanc.com/foo2.js&gt;; rel=preload; as=script; nonce=123
Content-Security-Policy: script-src &apos;nonce-123&apos;; object-src &apos;none&apos;; report-uri /foo

No script is run.


### Expected Behavior ###

Script is run. Chrome and Firefox runs the script.

Interestingly, Safari will run the script if the preload Link is included as an HTML tag rather than a header (https://cloud.arturjanc.com/s/safari-link-nonce/link-element).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1736043</commentid>
    <comment_count>1</comment_count>
    <who name="Smoley">smoley</who>
    <bug_when>2021-03-04 15:17:02 -0800</bug_when>
    <thetext>Thanks for filing, I can reproduce this on Safari 13.1.3 as well as STP 121 (14.2).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1736044</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2021-03-04 15:17:14 -0800</bug_when>
    <thetext>&lt;rdar://problem/75060055&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2003077</commentid>
    <comment_count>3</comment_count>
    <who name="Ahmad Saleem">ahmad.saleem792</who>
    <bug_when>2024-01-04 18:03:45 -0800</bug_when>
    <thetext>Console Error in Safari 17.2.1 &amp; Safari Technology Preview 185: 

Refused to execute a script because its hash, its nonce, or &apos;unsafe-inline&apos; does not appear in the script-src directive of the Content Security Policy.

Refused to load blob:https://cloud.arturjanc.com/f772cb40-5898-4465-8838-1595ffc71648 because it does not appear in the script-src directive of the Content Security Policy.

___

Chrome Canary 122 &amp; Firefox Nightly 123 - no console error.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2024872</commentid>
    <comment_count>4</comment_count>
    <who name="Tao Zhou">tao.zhou</who>
    <bug_when>2024-03-29 17:40:35 -0700</bug_when>
    <thetext>this issue still exists, and quite strangely, the violation is only reported if its `nonce` only on CSP-Report-Only header, but not when its on CSP header.

so we can observe the violation with following header:

```
Content-Security-Policy: script-src &apos;self&apos; &apos;nonce-123&apos;;
Content-Security-Policy-Report-Only: script-src &apos;nonce-123&apos; report-uri /foo;
```

but not on:

```
Content-Security-Policy: script-src &apos;nonce-123&apos;;
Content-Security-Policy-Report-Only: script-src &apos;nonce-123&apos; report-uri /foo;
```</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2024892</commentid>
    <comment_count>5</comment_count>
    <who name="Tao Zhou">tao.zhou</who>
    <bug_when>2024-03-29 19:40:29 -0700</bug_when>
    <thetext>here is the minimum repro repo: https://github.com/taozhou-glean/webkit-nonce</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2138161</commentid>
    <comment_count>6</comment_count>
    <who name="Ryan Reno">rreno</who>
    <bug_when>2025-08-21 21:20:03 -0700</bug_when>
    <thetext>Thanks for the report.

When building the preload request on behalf of the HTMLPreloadScanner we aren&apos;t copying the nonce from the link element&apos;s nonce attribute into the fetch options we use when creating the network request. So later when the loader tries to validate we&apos;re allowed to do the load there&apos;s no nonce to check against and we trip over the Content-Security-Policy-Report-Only header.

The reason why it works in the other case (/csp-no-violation endpoint in the bun server) is because when we&apos;re building the preload request we do an early check of the nonce for enforcement policies (so Content-Security-Policy header or meta-tag delivered headers). If the check succeeds we skip later CSP pre-request checks. Since in the csp-no-violation case the nonce is present we will never send a violation report. In the failing case there is no nonce in the Content-Security-Policy header and so we do a full CSP check later, but with the aforementioned bug.

The fix here is to include the link element&apos;s nonce attribute in the fetch request during preload. We could also consider doing a nonce check against report only policies but that&apos;s a little more involved since we don&apos;t want to accidentally skip CSP for enforcement policies that would otherwise be allowed by report-only policies.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2138176</commentid>
    <comment_count>7</comment_count>
    <who name="Ryan Reno">rreno</who>
    <bug_when>2025-08-22 00:22:58 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/49756</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2138179</commentid>
    <comment_count>8</comment_count>
    <who name="Ryan Reno">rreno</who>
    <bug_when>2025-08-22 00:27:17 -0700</bug_when>
    <thetext>Submitted web-platform-tests pull request: https://github.com/web-platform-tests/wpt/pull/54454</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2138346</commentid>
    <comment_count>9</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2025-08-22 12:49:15 -0700</bug_when>
    <thetext>Committed 299070@main (2a8526c8f622): &lt;https://commits.webkit.org/299070@main&gt;

Reviewed commits have been landed. Closing PR #49756 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>