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

auth.setAuth security issue? #36

Open
enyo opened this issue May 12, 2022 · 3 comments
Open

auth.setAuth security issue? #36

enyo opened this issue May 12, 2022 · 3 comments

Comments

@enyo
Copy link

enyo commented May 12, 2022

Hi,

I might be misunderstanding the code, but isn't this line a problem?

// hooks.ts

// ... inside the handle() function:
await auth.setAuth(session.access_token)
// ...

Since this code runs on the server, this would mean that all subsequent calls on auth will use the same session.access_token for all users?

@one-aalam
Copy link
Owner

Hey @enyo , this isn't a security concern and it has to do with how Supabase can get the current user's context without actually being able to log them in a server side function. Applying it post authenticating, helps the subsequent calls. You can find more details about this particular API here

@enyo
Copy link
Author

enyo commented May 16, 2022

Mh... maybe I'm missing something, but this is from the docs:

This is most useful on server-side functions where you cannot log the user in, but have access to the user's access token.

const { user, error } = supabase.auth.setAuth(access_token)
 // This client will now send requests as this user
 const { data } = await supabase.from('your_table').select()

That means, that in your case, you're setting the auth token from that specific user for all subsequent requests. If there are two simultaneous users, it might be, that the token gets overriden by the second one, and the call for the first user fails (or worse, exposes private data).

The way that supabase does it, and why it works in their case, is because they create a new client for that specific call, instead of setting the auth token on the global singleton.

@one-aalam
Copy link
Owner

Thanks for pointing this out @enyo. I've probably overlooked this aspect. Let me figure out a solution for the same.

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

No branches or pull requests

2 participants