<?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>289396</bug_id>
          
          <creation_ts>2025-03-07 21:47:20 -0800</creation_ts>
          <short_desc>CORS: Safelist Last-Event-ID</short_desc>
          <delta_ts>2025-03-14 22:48:14 -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>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>espen</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>annevk</cc>
    
    <cc>ap</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2101599</commentid>
    <comment_count>0</comment_count>
    <who name="">espen</who>
    <bug_when>2025-03-07 21:47:20 -0800</bug_when>
    <thetext>Filing an implementation bug for https://github.com/whatwg/fetch/pull/1788 - see issue for proposal and discussion to change the specification.

When using `XMLHttpRequest` or `fetch`, sending a cross-origin request with a (safe) `Last-Event-ID` request header triggers a CORS preflight request with an `access-control-request-headers: last-event-id` header. However, when using the EventSource API, the same request does not.

Thus, it makes sense to safelist the `last-event-id` header, as long as it has less than 128 characters and does not include any CORS-unsafe request header bytes.
This enables users to build custom EventSource-compatible polyfills, without requiring the server to implement CORS for something that can already be bypassed by using EventSource.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101794</commentid>
    <comment_count>1</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2025-03-09 18:15:47 -0700</bug_when>
    <thetext>Could you please clarify what makes EventSource-compatible polyfills necessary?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101824</commentid>
    <comment_count>2</comment_count>
    <who name="">espen</who>
    <bug_when>2025-03-09 22:02:16 -0700</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #1)
&gt; Could you please clarify what makes EventSource-compatible polyfills
&gt; necessary?

Just to be clear; polyfills is just one aspect of this - https://github.com/whatwg/fetch/issues/568 outlines why safelisting this header makes sense, as you can theoretically bypass this already with a cooperating server.

As for the polyfill question, there are a ton of reasons why you&apos;d want to provide a better API - the EventSource API leaves a lot to be desired:


- Being able to subscribe to any event sent from the server (EventSource requires you to explicit list named events you want to subscribe to)
- Being able to differentiate between connection errors and events named &apos;error&apos;
- Configurable reconnection policies
- Better error handling (EventSource gives you little to no information whatsoever - not even status code)
- Being able to set an initial Last-Event-ID
- Including additional headers with the request (authorization is a common one)

There are already polyfills out there that does a lot of this, but it&apos;s a shame that for the standard case of reconnecting after a disconnect, you need the server to be &quot;compatible&quot; with the polyfill by responding to a preflight request and allowing `last-event-id`, when that is not needed if using the `EventSource` API. As mentioned previously, this is sort of false security anyway, since you can use a cooperating server to redirect you and include a `last-event-id` without requiring a preflight request.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2101831</commentid>
    <comment_count>3</comment_count>
    <who name="">espen</who>
    <bug_when>2025-03-09 22:26:58 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/42180</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2103502</commentid>
    <comment_count>4</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2025-03-14 22:48:14 -0700</bug_when>
    <thetext>&lt;rdar://problem/147104095&gt;</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>