<?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>229034</bug_id>
          
          <creation_ts>2021-08-12 04:39:08 -0700</creation_ts>
          <short_desc>[GTK] Origin is empty when sending fetch/XHR request to servers</short_desc>
          <delta_ts>2021-09-17 00:02:42 -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>WebKitGTK</component>
          <version>Other</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>Gtk</keywords>
          <priority>P3</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Yu-Wei Wu">wusyong9104</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>bugs-noreply</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1783786</commentid>
    <comment_count>0</comment_count>
    <who name="Yu-Wei Wu">wusyong9104</who>
    <bug_when>2021-08-12 04:39:08 -0700</bug_when>
    <thetext>I got a weird CORS behavior that if I register a URI scheme, gtk:// for example. If the page is loaded with that URI scheme, and then using fetch or XHR inside that webview to any server that enables CORS, it will got the following errors.

&gt; [Error] Origin  is not allowed by Access-Control-Allow-Origin.
&gt; [Error] Fetch API cannot load http://mockbin.org/bin/123fj399fiv due to access control checks.
&gt; [Error] Failed to load resource: Origin  is not allowed by Access-Control-Allow-Origin.

The origin seems to be empty, not even null. But if I checked in the devtools, the origin will be there (gtk://localhost for example)
Setting Access-Control-Allow-Origin: * will pass, but any others won&apos;t(gtk://, gtk://*, gtk://localhost... etc).
Functions webkit_security_manager_register_uri_scheme_as_cors_enabled(security_manager, &quot;gtk&quot;) didn&apos;t work either.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1794355</commentid>
    <comment_count>1</comment_count>
    <who name="Yu-Wei Wu">wusyong9104</who>
    <bug_when>2021-09-17 00:02:42 -0700</bug_when>
    <thetext>Here&apos;s the example to test with: https://github.com/wusyong/gtkbrowser/tree/cors
It enables &quot;gtk://&quot; URL scheme and sets the scheme with cors enabled.
It also enables the devtool to help us easier to debug.

I used mockbin to test several options: https://mockbin.org/
It has code snippets to let you copy the fetch request and paste it to devtool of the window directly to see the result.
Only Access-Control-Allow-Origin: * will work. gtk://, gtk://*, gtk://index.html all will get empty origin.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>