You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to use the JS library to make a call to "database.update" and have requested changes commit to the table using an expired JWT. Making a check of session.getUser() returns a null value indicating that the user is not authenticated but the underlying operation to make the update is successful.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
[In the context of a NestJS API]
Make an API PATCH request using a client such as Insomnia or Postman (I'm using Insomnia)
Provide a previously valid JWT (I.e now expired) within the Authorisation header as a bearer token
(Checks for the validity of the token are implemented within a middleware):
if('authorization'inreq.headers&&'refreshtoken'inreq.headers){consttoken=req.headers.authorization.split(' ')[1]const{data: { user }}=awaitClient.connection.auth.getUser(token)// make sure the user is authenticatedif(!user){next(res.status(403).json({message: "User is not logged in"}))}// set the current session with the provided tokensawaitClient.connection.auth.setSession({access_token: token,refresh_token: req.headers.refreshtokenasstring})returnnext()}
Checks for user availability in the session "fail" correctly when implemented (I.e no user returned by SupaBase as expected):
if(!user){next(res.status(403).json({message: "User is not logged in"}))}
There is a small window of time where an expired JWT will still be accepted. I don't recall the exact timeframe though - maybe 30 seconds? How long are you waiting before you try the expired JWT?
Calling setSession with an expired access_token and a valid refresh_token will cause the session to be refreshed, giving you a valid access_token for your query.
If you want to avoid this, then I'd manually set the client's authorization header when creating the client, instead of using setSession.
Bug report
Describe the bug
It is possible to use the JS library to make a call to "database.update" and have requested changes commit to the table using an expired JWT. Making a check of session.getUser() returns a null value indicating that the user is not authenticated but the underlying operation to make the update is successful.
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
[In the context of a NestJS API]
Expected behavior
The database change (or any operation requiring an authenticated user) should be denied and not occur.
System information
Additional context
The text was updated successfully, but these errors were encountered: