<?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>276364</bug_id>
          
          <creation_ts>2024-07-09 05:19:12 -0700</creation_ts>
          <short_desc>XMLHttpRequest without credentials fails with CORS error on redirections</short_desc>
          <delta_ts>2024-07-16 05:20:12 -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>Page Loading</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Przemyslaw Gorszkowski">pgorszkowski</reporter>
          <assigned_to name="Przemyslaw Gorszkowski">pgorszkowski</assigned_to>
          <cc>achristensen</cc>
    
    <cc>annevk</cc>
    
    <cc>beidson</cc>
    
    <cc>m_finkel</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>2045287</commentid>
    <comment_count>0</comment_count>
    <who name="Przemyslaw Gorszkowski">pgorszkowski</who>
    <bug_when>2024-07-09 05:19:12 -0700</bug_when>
    <thetext>The problem was reported for WPE: https://github.com/WebPlatformForEmbedded/WPEWebKit/issues/1361 but it can be reproduced also for GTK or safari(iphone). The steps to reproduce:
1. make a XMLHTTPRequest without credentials to same origin (same_origin_redirect)
    const xhr = new XMLHttpRequest();
    xhr.open(&quot;GET&quot;, &quot;http://same_origin/same_origin_redirect.php&quot;, true);
    xhr.send(null); 
2. same_origin_redirect.php redirects to different origin:
&lt;?php
header(&quot;Access-Control-Allow-Origin: *&quot;);
header(&quot;HTTP/1.1 301 Moved Permanently&quot;);
header(&quot;Cache-Control: no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate&quot;);
header(&quot;Location: http://different_origin/different_origin_redirect.php&quot;);
?&gt;
3. different_origin_redirect.php redirects to same origin:
&lt;?php
header(&quot;Access-Control-Allow-Origin: *&quot;);
header(&quot;HTTP/1.1 301 Moved Permanently&quot;);
header(&quot;Cache-Control: no-store, no-cache, max-age=0, must-revalidate, proxy-revalidate&quot;);
header(&quot;Location: http://same_origin/same_origin_target.php&quot;);
?&gt;
4. same_origin_targe.php:
&lt;?php
header(&quot;Access-Control-Allow-Origin: *&quot;);
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;/head&gt;
&lt;body style=&quot;background-color:white&quot;&gt;
  &lt;p style=&quot;font-weight: 600;&quot;&gt;Wildcard CORS&lt;/p&gt;&lt;br /&gt;
  &lt;p&gt;Status: &lt;strong id=&quot;status&quot;&gt;SUCCESS&lt;/strong&gt;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;


The last redirect fails because of:
[Error] Cross-origin redirection to http://same_origin/same_origin_target.php denied by Cross-Origin Resource Sharing policy: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true.
[Error] Failed to load resource: Cross-origin redirection to http://same_origin/same_origin_target.php denied by Cross-Origin Resource Sharing policy: Cannot use wildcard in Access-Control-Allow-Origin when credentials flag is true. (same_origin_redirect.php, line 0)
[Error] XMLHttpRequest cannot load http://different_origin/different_origin_redirect.php due to access control checks.

The problem can be also reproduced with LayoutTest with similar case (I will add the case in LayoutTests/http/tests/xmlhttprequest/access-control-and-redirects-async-same-origin.html in PR).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2045288</commentid>
    <comment_count>1</comment_count>
    <who name="Przemyslaw Gorszkowski">pgorszkowski</who>
    <bug_when>2024-07-09 05:31:54 -0700</bug_when>
    <thetext>The problem does not exist on FF or Chrome (Chromium)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2045290</commentid>
    <comment_count>2</comment_count>
    <who name="Przemyslaw Gorszkowski">pgorszkowski</who>
    <bug_when>2024-07-09 05:42:09 -0700</bug_when>
    <thetext>The Fetch specification describes in which cases &quot;*&quot; Access-Control-Allow-Origin are allowed for which credentials modes:
https://fetch.spec.whatwg.org/#cors-protocol-and-credentials

The problem in webkit seems to be implementation of the &quot;passesAccessControlCheck&quot; from: https://github.com/WebKit/WebKit/blob/main/Source/WebCore/loader/CrossOriginAccessControl.cpp#L266

The &quot;passesAccessControlCheck&quot; uses &quot;StoredCredentialsPolicy&quot; while probably it should use &quot;FetchOptionsCredentials&quot; to handle it correctly.

Chromium implementation: https://chromium.googlesource.com/chromium/src/+/refs/heads/main/services/network/public/cpp/cors/cors.cc#144</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2045485</commentid>
    <comment_count>3</comment_count>
    <who name="Przemyslaw Gorszkowski">pgorszkowski</who>
    <bug_when>2024-07-10 01:19:29 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/30638</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2046457</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-07-16 05:20:12 -0700</bug_when>
    <thetext>&lt;rdar://problem/131831204&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>