Skip to content

Conversation

@Nipsuli
Copy link
Contributor

@Nipsuli Nipsuli commented Oct 15, 2024

Example Clerk auth provider does not work when both Authorization and Origin headers are set. This allows one to skip setting the origin header explicitly.

In my application I'm routing all requests via tauri-http by patching global fetch. And I'm using custom Clerk setup to get the token shared between js and rust. To do that I need to use Authorization header instead of cookies to communicate with Clerk. And Clerk fails if there is both Authorization header and Origin header, as such I need a way to send requests without origin header.

I do like the default behavior of setting the origin header if it's not set as that mimics the browser behavior. But I also need a way to not send it. This does not change any existing behaviors, and Origin header can anyways be:

Origin: null
Origin: <scheme>://<hostname>
Origin: <scheme>://<hostname>:<port>

So empty string would be invalid header value according to the spec. As such I was thinking that if client has sent empty origin header we could just omit the origin header.

Example Clerk auth provider does not work when both Authorization and
Origin headers are set. This allows one to skip setting the origin
header explicitly.
@Nipsuli Nipsuli requested a review from a team as a code owner October 15, 2024 10:43
Copy link
Member

@amrbashir amrbashir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, Could you also add a change file in .changes directory?

// In case empty origin is passed, remove it. Some services do not like Origin header
// so this way we can remove it in explicit way. The default behaviour is still to set it
if cfg!(feature = "unsafe-headers")
&& headers.get(header::ORIGIN) == Some(&HeaderValue::from_static(""))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should match on an empty string, because there might be some users who want to send empty string for Origin. I'd rather add a new option when making the request, for example:

fetch(url, {
  sendOriginHeader: false
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is something I was thinking a lot. Like I'd like to avoid adding extra parameters to the fetch and try to keep the fetch as close to global fetch. And in case of patching global fetch with tauri-http (example to get control what fetches actually can be made) the consumers assume standard fetch. Different libraries support some pre/post hooks for different operations that allow example inject headers and such like for custom auth and they operate with the RequestInit object.

And the syntax of Origin header is:

Origin: null
Origin: <scheme>://<hostname>
Origin: <scheme>://<hostname>:<port>

MDN origin header
RFC 6454

Sending an empty string is invalid format. In case user wants to hide the origin for example privacy reasons they should set it to null string literal.

For these reasons I ended up with sending empty string in the origin header as the mechanism.

I hope my reasoning makes sense.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was comparing with how node and deno runtimes behave and both allow setting Origin to an empty string. However your reasoning is quite valid and I think we should go with your approach until someone else asks for this specific behavior.

@github-actions
Copy link
Contributor

github-actions bot commented Oct 16, 2024

Package Changes Through 943de57

There are 8 changes which include dialog with patch, dialog-js with patch, positioner with patch, positioner-js with patch, http with patch, http-js with patch, shell with patch, shell-js with patch

Planned Package Versions

The following package releases are the planned based on the context of changes in this pull request.

package current next
api-example 2.0.2 2.0.3
api-example-js 2.0.0 2.0.1
dialog 2.0.1 2.0.2
dialog-js 2.0.0 2.0.1
http 2.0.1 2.0.2
http-js 2.0.0 2.0.1
positioner 2.0.1 2.0.2
positioner-js 2.0.0 2.0.1
shell 2.0.1 2.0.2
shell-js 2.0.0 2.0.1

Add another change file through the GitHub UI by following this link.


Read about change files or the docs at github.com/jbolda/covector

@amrbashir amrbashir changed the title Allow http calls without origin header feat: allow http calls without origin header Oct 16, 2024
@amrbashir amrbashir merged commit cfd48b3 into tauri-apps:v2 Oct 16, 2024
15 checks passed
@amrbashir
Copy link
Member

Thank you

Sir-Thom pushed a commit to Sir-Thom/plugins-workspace that referenced this pull request Oct 22, 2024
mochja added a commit to mochja/gitbutler that referenced this pull request May 22, 2025
Currently the request to Ollama contains `Origin: null` header, which is not accepted by Ollama server (server responds with 403).

There seem to be a way to remove Origin header, by setting it's value to an empty string.

fixes:
- gitbutlerapp#8078
- gitbutlerapp#5862

ref:
- tauri-apps/plugins-workspace#1941
- https://github.com/ollama/ollama-js/blob/6a4bfe3ab033f611639dfe4249bdd6b9b19c7256/src/browser.ts#L38
- https://github.com/gitbutlerapp/gitbutler/blob/9af0e4bbaa845aeb40a82f22ad66975a61990654/Cargo.lock#L8431
gezihuzi pushed a commit to Hypobenthos/plugins-workspace that referenced this pull request Jun 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants