Bug 229034 - [GTK] Origin is empty when sending fetch/XHR request to servers
Summary: [GTK] Origin is empty when sending fetch/XHR request to servers
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKitGTK (show other bugs)
Version: Other
Hardware: PC Linux
: P3 Normal
Assignee: Nobody
URL:
Keywords: Gtk
Depends on:
Blocks:
 
Reported: 2021-08-12 04:39 PDT by Yu-Wei Wu
Modified: 2021-09-17 00:02 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Yu-Wei Wu 2021-08-12 04:39:08 PDT
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.

> [Error] Origin  is not allowed by Access-Control-Allow-Origin.
> [Error] Fetch API cannot load http://mockbin.org/bin/123fj399fiv due to access control checks.
> [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't(gtk://, gtk://*, gtk://localhost... etc).
Functions webkit_security_manager_register_uri_scheme_as_cors_enabled(security_manager, "gtk") didn't work either.
Comment 1 Yu-Wei Wu 2021-09-17 00:02:42 PDT
Here's the example to test with: https://github.com/wusyong/gtkbrowser/tree/cors
It enables "gtk://" 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.