Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS not working in Safari (but does in Chrome) #3983

Closed
finn753 opened this issue Apr 27, 2024 · 3 comments · Fixed by #4086
Closed

CORS not working in Safari (but does in Chrome) #3983

finn753 opened this issue Apr 27, 2024 · 3 comments · Fixed by #4086
Assignees
Labels
bug Something isn't working

Comments

@finn753
Copy link

finn753 commented Apr 27, 2024

What is the issue?

I can't make API requests from Safari.
I've enabled all origins "*" and it perfectly works in Chrome, but Safari just throws CORS errors.
I've tried with the ollama/browser npm package and a manual fetch request, to make sure it's not the problem.
Both are failing

OS

macOS

GPU

Apple

CPU

Apple

Ollama version

0.1.32

@finn753 finn753 added the bug Something isn't working label Apr 27, 2024
@BruceMacD
Copy link
Contributor

Hi @finn753, thanks for opening the issue. Safari has some stricter CORs policies than Chrome does. Is there any specific CORs error in the safari console? That will help narrow this one down a bit, a quick Safari CORs test worked for my specific setup.

@jzevin
Copy link

jzevin commented May 5, 2024

@BruceMacD I was going to post the issue, so I had done a bit of research as I don't know go but the following may help:

res.set_header("Access-Control-Allow-Headers", "*");

I think Safari does not accept the wildcard in Access-Control-Allow-Headers when credentials are included. Consequently, requests that explicitly set the User-Agent header are blocked due to CORS policy violations.

Proposed Solution:
Replace the wildcard in the Access-Control-Allow-Headers with an explicit list of headers. For example:

res.set_header("Access-Control-Allow-Headers", "Content-Type, Accept, X-Requested-With, User-Agent");

Impact:
This issue prevents the application from performing authorized cross-origin requests where custom headers, particularly User-Agent, are necessary.

@BruceMacD BruceMacD self-assigned this May 7, 2024
@BruceMacD
Copy link
Contributor

Thanks for the insights @jzevin, I was able to reproduce and add a couple more headers to #4086 that will fix this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants