Replies: 4 comments
-
Anyone? |
Beta Was this translation helpful? Give feedback.
-
This does not look right.
https://next-auth.js.org/getting-started/client#sessionprovider I assume, since you are asking this, you are not using the token on the client side and do not need it there. There are niche use cases of having credentials on the client-side, however, the only mechanism of storing arbitrary credentials in a browser designed with the appropriate security and threat model in mind is a cookie with the If you come from a backend development background there may have been a confusion due to the use of the common term "session". The functionality provided by A rough counterpart of a traditional backend session in next-auth would be the
https://next-auth.js.org/configuration/callbacks#jwt-callback What you have set in the token can then be accessesed server-side only with the |
Beta Was this translation helpful? Give feedback.
-
Looks like this was an attempted workaround due to some changes and limitation of the App Router. For those who are struggling with the App Router, indeed there appears to be an inconvenience (at the very least) of working with the session server-side with the App Router. See the related question: vercel/next.js#52006 |
Beta Was this translation helpful? Give feedback.
-
There is surprisingly little clarity on this question, even after all this time. Not that @hesalx answers here and in vercel/next.js#52006 aren't comprehensive, but when you read things like this in the next-auth docs you do get the impression that auth tokens in session objects is ok:
But there is absolutely a security concern here, if not a downright vulnerability. There are 2 potential vulnerabilities:
The xss attack point is the one which most concerned me, and initially seemed like an unavoidable consequence of putting secrets in the session object. I then thought I understood how to avoid making the session object available for an xss attack, which explained to me why the next-auth docs left session storage of access tokens on the table. I have finally come back around to thinking that it's vulnerable to attack. I'm tempted to believe that I'm wrong at this last step, but I don't think so. The concern is that if a session is delivered to your browser, and then your client-side application code has access to this session object, then it probably follows that other 3rd party code that you're running in your project (whether it's part of the bundle or even loaded from 3rd party addresses), will have access to that session object too. My initial conclusion was then that this explains why next-auth performs a request for every instance of So that might be the answer or there might be another answer to explain why session stored access tokens might be acceptable, with the right care. However, I still see a vulnerability, not during or after the application code processing of the session object response, but during it's conveyance in to the So I'm left feeling like perhaps there are ways of having a session stored auth token, but even if the fetch monkey-patch issue I've described there isn't a vulnerability (and I really don't see how it isn't), then you still better be careful about how you are handling your session contents after receipt if any of it is secret. Please correct me if I'm wrong on any of this. I've only been looking in to it for a morning and the lack of hardline advice against this on the dicussion forums and docs makes me think I must be wrong, but my experiments tell me I'm not. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I'm assigning the access token to my session callback, like this:
When I use my application, I can see there's a network request to get the session, and the access token can be seen in the response there. The access token is sent to the client (browser).
Is my access token secure if it's sent to the browser in an HTTP request?
Thanks
Beta Was this translation helpful? Give feedback.
All reactions