<?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>256472</bug_id>
          
          <creation_ts>2023-05-08 09:46:27 -0700</creation_ts>
          <short_desc>Incorrect Sec-Fetch-Site values on iframes</short_desc>
          <delta_ts>2024-04-18 05:29:13 -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>Frames</component>
          <version>Safari 16</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=260284</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Bartosz Niemczura">niemczura</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>achristensen</cc>
    
    <cc>annevk</cc>
    
    <cc>bfulgham</cc>
    
    <cc>cdumez</cc>
    
    <cc>jerryzz</cc>
    
    <cc>pgriffis</cc>
    
    <cc>vincentlee</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>wilander</cc>
    
    <cc>youennf</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1953725</commentid>
    <comment_count>0</comment_count>
    <who name="Bartosz Niemczura">niemczura</who>
    <bug_when>2023-05-08 09:46:27 -0700</bug_when>
    <thetext>Sec-Fetch-Site values are supposed to provide information about the relationship between a request initiator&apos;s origin and the origin of the requested resource (https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Sec-Fetch-Site and https://w3c.github.io/webappsec-fetch-metadata/#sec-fetch-site-header)

However, when the following iframe is included on the page, the value of the Sec-Fetch-Site header will be &quot;none&quot;:

&lt;iframe method=&quot;get&quot; referrerpolicy=&quot;no-referrer&quot; src=&quot;https://www.example.com&quot;&gt;&lt;/iframe&gt;

It appears to be due to referrer policy attribute. Setting it to no-referrer will cause Safari to send Sec-Fetch-Site header with &quot;none&quot; value regardless of the origin the iframe i.e. same-origin, same-site and cross-site frames would all have this header set to &quot;none&quot;.

---

Reproduction steps:
1. Open any website, e.g. example.com
2. Open developer tools and paste the following code in the JS console:
```
const iframe = document.createElement(&apos;iframe&apos;);
iframe.src = &apos;https://www.example.com&apos;;
iframe.referrerPolicy = &apos;no-referrer&apos;;
iframe.method = &apos;get&apos;;
document.body.appendChild(iframe);
```
3. Inspect the request headers send on the iframe request.

Expected Outcome:
The Sec-Fetch-Site header is set to same-origin, same-site and cross-site, etc.

Actual Outcome:
The Sec-Fetch-Site header is set to none.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1954099</commentid>
    <comment_count>1</comment_count>
      <attachid>466295</attachid>
    <who name="Patrick Griffis">pgriffis</who>
    <bug_when>2023-05-09 12:06:04 -0700</bug_when>
    <thetext>Created attachment 466295
fetch-metadata-iframe-no-referrer-test.patch

Attached is a test case for this. Will look into it further.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1955446</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2023-05-15 09:47:19 -0700</bug_when>
    <thetext>&lt;rdar://problem/109358563&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1955746</commentid>
    <comment_count>3</comment_count>
    <who name="Patrick Griffis">pgriffis</who>
    <bug_when>2023-05-16 13:17:17 -0700</bug_when>
    <thetext>So the problem is pretty clear in that `CachedResourceLoader::computeFetchMetadataSite()` should not be using referrer information to calculate this.

I&apos;m having a hard time finding information to detect if a navigation was &quot;user-initiated&quot; though.

All the APIs that seem interesting like:

- DocumentLoader::lastNavigationWasAppInitiated()
- Navigation::wasUserInitiated()
- LocalFrame::hasHadUserInteraction()

All return not useful values on macOS Safari.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1956456</commentid>
    <comment_count>4</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-05-19 06:30:29 -0700</bug_when>
    <thetext>Why would user-initiated matter here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1956560</commentid>
    <comment_count>5</comment_count>
    <who name="Patrick Griffis">pgriffis</who>
    <bug_when>2023-05-19 12:21:10 -0700</bug_when>
    <thetext>(In reply to Anne van Kesteren from comment #4)
&gt; Why would user-initiated matter here?

To quote MDN for example:

&gt; none
&gt;    This request is a user-originated operation. For example: entering a URL into the address bar, opening a bookmark, or dragging-and-dropping a file into the browser window.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1958385</commentid>
    <comment_count>6</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-05-27 05:34:25 -0700</bug_when>
    <thetext>Patrick, two things:

1. Best not to look at MDN to figure out what to implement. https://w3c.github.io/webappsec-fetch-metadata/ is the relevant specification.
2. Looking at https://w3c.github.io/webappsec-fetch-metadata/#abstract-opdef-set-site step 4 and the explanation linked there makes it clear to me that when navigating a nested document &quot;none&quot; can never be correct. A user-initiated navigation as meant there would always involve a top-level navigation.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1971574</commentid>
    <comment_count>7</comment_count>
    <who name="Jerry Zhang">jerryzz</who>
    <bug_when>2023-08-16 13:08:27 -0700</bug_when>
    <thetext>In addition to referrerpolicy, it seems the Sec-Fetch-Site behavior is also incorrect for sandboxed iframes: https://bugs.webkit.org/show_bug.cgi?id=260284</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1971966</commentid>
    <comment_count>8</comment_count>
    <who name="Patrick Griffis">pgriffis</who>
    <bug_when>2023-08-17 18:43:19 -0700</bug_when>
    <thetext>(In reply to Anne van Kesteren from comment #6)
&gt; Patrick, two things:
&gt; 
&gt; 1. Best not to look at MDN to figure out what to implement.
&gt; https://w3c.github.io/webappsec-fetch-metadata/ is the relevant
&gt; specification.

The spec you linked says the exact same things: https://w3c.github.io/webappsec-fetch-metadata/#directly-user-initiated</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1972925</commentid>
    <comment_count>9</comment_count>
    <who name="Anne van Kesteren">annevk</who>
    <bug_when>2023-08-23 00:47:12 -0700</bug_when>
    <thetext>Patrick, but none of that applies to a nested document navigation, right?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2024481</commentid>
    <comment_count>10</comment_count>
    <who name="Vincent Lee">vincentlee</who>
    <bug_when>2024-03-28 09:55:23 -0700</bug_when>
    <thetext>Hi, what&apos;s the status on this? We&apos;d love to roll out serverside security checks for Safari based on the Sec-Fetch headers, but Sec-Fetch-Site not being correct is giving us pause. We&apos;ve rolled out on all other browsers, so only Safari is left.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2029432</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-04-18 05:29:10 -0700</bug_when>
    <thetext>Committed 277662@main (ab5d20c0ff15): &lt;https://commits.webkit.org/277662@main&gt;

Reviewed commits have been landed. Closing PR #27350 and removing active labels.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>466295</attachid>
            <date>2023-05-09 12:06:04 -0700</date>
            <delta_ts>2023-05-09 12:06:04 -0700</delta_ts>
            <desc>fetch-metadata-iframe-no-referrer-test.patch</desc>
            <filename>test.patch</filename>
            <type>text/plain</type>
            <size>1331</size>
            <attacher name="Patrick Griffis">pgriffis</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL0xheW91dFRlc3RzL2h0dHAvd3B0L2ZldGNoL2ZldGNoLW1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