<?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>291793</bug_id>
          
          <creation_ts>2025-04-19 10:25:11 -0700</creation_ts>
          <short_desc>The crossorigin and src attribute order in &lt;img /&gt; cause CORS error</short_desc>
          <delta_ts>2025-04-26 10:27:58 -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>Images</component>
          <version>Safari 18</version>
          <rep_platform>Mac (Apple Silicon)</rep_platform>
          <op_sys>macOS 15</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=281998</see_also>
    
    <see_also>https://bugs.webkit.org/show_bug.cgi?id=190031</see_also>
          <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>bcjohnblue</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>cdumez</cc>
    
    <cc>sabouhallawa</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2111989</commentid>
    <comment_count>0</comment_count>
    <who name="">bcjohnblue</who>
    <bug_when>2025-04-19 10:25:11 -0700</bug_when>
    <thetext>Case 1 - Set &quot;crossOrigin&quot; before &quot;src&quot;

When set &quot;crossOrigin&quot; before &quot;src&quot;, safari only send one CORS request and it is regard as correctly

Online demo - https://bcjohnblue.github.io/browser-cors-error/safari-very-good-1.html

&lt;script&gt;
  window.onload = function () {
    setTimeout(() =&gt; {
      const img = document.createElement(&apos;img&apos;);
      img.crossOrigin = &apos;anonymous&apos;;
      img.src =
        &apos;https://rjzdhlvuuafqvgoyticm.supabase.co/functions/v1/getCORSImage?image=building.jpg&apos;;
      document.body.appendChild(img);
    }, 0);
  };
&lt;/script&gt;


Case 2. Set &quot;src&quot; before &quot;crossOrigin&quot;

When set &quot;src&quot; before &quot;crossOrigin&quot;, safari send two requests, one is CORS request and the other one is no-CORS request

Therefore, Safari may randomly cache requests made without CORS headers. If such a no-CORS request gets cached, it can lead to CORS errors when the user reloads the page later.

Online demo - https://bcjohnblue.github.io/browser-cors-error/safari-very-bad-1.html

&lt;script&gt;
  window.onload = function () {
    setTimeout(() =&gt; {
      const img = document.createElement(&apos;img&apos;);
      img.src =
        &apos;https://rjzdhlvuuafqvgoyticm.supabase.co/functions/v1/getCORSImage?image=building.jpg&apos;;
      img.crossOrigin = &apos;anonymous&apos;;
      document.body.appendChild(img);
    }, 0);
  };
&lt;/script&gt;


How to reproduce:

1. go to https://bcjohnblue.github.io/browser-cors-error/safari-very-bad-1.html

2. clear the cache

3. reload the page

4. you will see two requests are send, one is CORS request and the other one is no-CORS request

5. reload the page again and if Safari cache the no-CORS request on the last step, it will cause CORS error

6. if CORS error not happen, repeat step 2 to step 5


Expected Results:

The result of case 2 should be the same as that of case 1, so it won&apos;t cause random CORS errors.


Relative links:

1. crossorigin and src attribute order matter - https://github.com/sveltejs/svelte/issues/7454
2. crossOrigin attribute needs to be applied before `&lt;img src&gt;` attribute - https://github.com/facebook/react/issues/14035
3. Safari loads image twice if crossorigin attribute goes after src - https://github.com/vuejs/core/issues/4680</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2113279</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-04-26 10:27:58 -0700</bug_when>
    <thetext>&lt;rdar://problem/150105834&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>