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

Preflight CORS requests are not hadled correctly #56

Closed
izderadicka opened this issue Sep 6, 2021 · 12 comments
Closed

Preflight CORS requests are not hadled correctly #56

izderadicka opened this issue Sep 6, 2021 · 12 comments
Labels
bug Something isn't working

Comments

@izderadicka
Copy link
Owner

When using with --cors header and other web client, served from different location then API, and which sends preflight requests , then
OPTIONS preflight for /authenticate return 401 status,
thus
client/web browser cannot access the endpoint

OPTIONS requests handling has to be fixed in audioserve - especially when --cors switch is on.

izderadicka added a commit that referenced this issue Sep 6, 2021
We did not handle correctly OPTIONS request in CORS preflight check.

Now it should be fixed.

Issue: #56
@izderadicka
Copy link
Owner Author

Fix pushed to master

@izderadicka
Copy link
Owner Author

@KodeStar pls update here if it is working for you.

@KodeStar
Copy link

KodeStar commented Sep 8, 2021

I’ve not tried it yet, been busy trying to add features and fix bugs, will try to build from master later today or tomorrow

@izderadicka izderadicka added the bug Something isn't working label Sep 8, 2021
@KodeStar
Copy link

Any chance you could put out a release with this change in it? It will be much easier for me to test.

@izderadicka
Copy link
Owner Author

@KodeStar - released latest master as v0.15.6. Can you confirm that CORS preflight is now working?

@KodeStar
Copy link

I think we have a success, it's not complaining about cors any longer, now I just have to work out why what I'm trying to send isn't working :)

@KodeStar
Copy link

KodeStar commented Sep 13, 2021

Would it be possible to send the audioserve_token as a custom header instead of a cookie? The issue is, because the server and the frontend aren't on the same address it wont let me set the cookie. So all my subsequent requests to endpoints fail.

edit Nvm, I looked through the auth.rs code and realised it could be sent via an Authorization bearer token!

@izderadicka
Copy link
Owner Author

@KodeStar,
Yes you can use Bearer token as well as cookie. In browser you can you send cookie even to different host (if it was setup by that host). I'm using it in development of default client (as it is convenient and you don't have manage the header yourself). Just need to add this option to XHR withCredentials: true - see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/withCredentials

@KodeStar
Copy link

KodeStar commented Sep 13, 2021

I was originally using axios and passing withCredentials: true but it didn't help, I have since got rid of axios and am just using fetch, I haven't tried it with that since I got it working by passing the bearer. However, when I tried it with axios I got this error in the browser https://imgur.com/Oa3C4go

This attempt to set a cookie via a Set-Cookie header was blocked because it had the "SameSite=Lax" attribute but came from a cross-site response which was not the response to a top-level navigation.

@izderadicka
Copy link
Owner Author

@ Kodestar Hmm, this make sense - our cookie is now SameSite: Lax so it depends how login is initiated in browser. Problem is mainly for development, cause normally then client files and API are served from same location in production.
As I said it works for me now in FF for current client - probably the way login is initiated suits definition of "top-level navigation".

Anyhow if bearer token working for you it's good solution, as this will in both development and production set up. If there are still issues with CORS let me know, otherwise I think we can close this issue.

@KodeStar
Copy link

Agreed :)

@izderadicka
Copy link
Owner Author

CORS Headers looks working OK. However still some change needs to be done on cookie - created new issue fo this #64

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

No branches or pull requests

2 participants