-
-
Notifications
You must be signed in to change notification settings - Fork 166
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
getAuthenticatorAssuranceLevel() triggers "getSession() could be insecure" warnings #910
Comments
There is a PR for that #909 |
Are there any updates on this? We are also using Next.js with the latest SSR package and implementing getAuthenticatorAssuranceLevel() in the middleware to check the users' AAL level. Our logs are flooded with warnings: "Using the user object as returned from supabase.auth.getSession() or from some supabase.auth.onAuthStateChange() events could be insecure! This value comes directly from the storage medium (usually cookies on the server) and many not be authentic. Use supabase.auth.getUser() instead which authenticates the data by contacting the Supabase Auth server." Which makes it really hard to debug and read console logs for anything (un)related to Supabase in our app. |
No updates on this that I'm aware of. There are several places in the code where this happens, besides this method: some examples are updating a user, setting a session, and refreshing a session - if executed on the server side of course. I believe there might be a couple of others. I'm hoping that after they get some more auth things completed in the next couple of months, that they decide this warning is unneeded and just remove it. |
omg thank you for posting this. I've been chasing down my particular source of this incessant warning, and eventually traced it to this same getAuthenticatorAssuranceLevel() function. I suppose unless the maintainers switch this function to use getUser() the correct course of action would be to only use getAuthenticatorAssuranceLevel() on the client side... has anyone gotten this working on their end before I go down that route? If it's the case that getAuthenticatorAssuranceLevel() Is only intended to be called on the client side, it would be nice for that to be added to the docs, and have a more explicit warning emitted |
Ok I reimplemented my code to do this check on the client side and the warnings went away. In my case I have a layout file covering an entire Dashboard section of my website, and inside that layout I have a useEffect that checks assurance level and either shows the MFA screen, or the dashboard as appropriate:
Hope this helps someone out there! |
Hey @k-thornton, the warning was to remind us that the token was retrieved from a storage medium (cookies) which could be tampered by the user, right? Which means that there is no secure way of getting the user's |
I hope that the problem will be solved. I can't imagine that moving the query to the client is the best solution when middleware should be the cleanest solution |
@antonsarg I just verify the jwt token with the jwt_secret and then decode the payload like suggested here |
Hey folks, Thanks for your patience with us. An update here - A fix is in the works. We'll soon move to an asymmetric model where |
@J0 So what is the best way to go for now especially for production? |
https://supabase.com/docs/guides/auth/auth-mfa#server-side-rendering That feels like the way it was intended to be implemented. |
Hey, while waiting for a cleaner version of a fix for this, I wanted to share I how dealt with the issue. It was happening when using
This chunk of code is inserted in the middleware's code, as shown in the step 4 of this documentation page : https://supabase.com/docs/guides/auth/server-side/nextjs?queryGroups=router&router=app |
Bug report
Describe the bug
Despite not using
getSession()
anywhere in my code, I am still receiving (numerous) console warnings stating the following:After doing some investigation, this issue seems to only occur when checking the user's MFA status via
supabase.auth.mfa.getAuthenticatorAssuranceLevel()
. If I remove or replace this call with a static return of'aal2'
values, the warnings disappear in console.I am using Next.js and server-side rendering with the App router + supabase/ssr.
To Reproduce
supabase.auth.mfa.getAuthenticatorAssuranceLevel()
.currentLevel
property of this call is compared against the defined/expected AAL level for that route, then - if they don't match the expected level` redirects them to the appropriate page (login page, enter MFA code page, dashboard page)Expected behavior
Since I have not called/used
getSession()
anywhere, I should not be seeing warnings in the console aboutgetSession()
.System information
Additional context
I did some investigation and it seems like
getAuthenticatorAssuranceLevel()
is referencing thesession.user
object in this line:Some suggestions/thoughts:
getAuthenticatorAssuranceLevel()
also meant to be treated as an insecure on the server (likegetSession()
)? If so, this probably needs to be reflected more clearly in the docs to prevent a developer from trying to protect routes based only on MFA status (this is possible since a logged-out user would returnnull
forcurrentLevel
andnextLevel
).getAuthenticatorAssuranceLevel()
be made more secure server-side by calling_getUser
? Then the resulting value could be referenced asuser.factors
instead ofsession.user.factors
. I assume this would add quite a lot of overhead to this function.getAuthenticatorAssuranceLevel()
to call_getUser
by default, could it be an option to pass auser
togetAuthenticatorAssuranceLevel()
so the developer can define if they want the method to be secure on the server?getSession()
has not been used anywhere in the code.I haven't explored too deeply into the source code so hopefully these thoughts make sense.
The text was updated successfully, but these errors were encountered: