Login CSRF (Session fixation) attack #1011
-
How does this approach effectively prevent login CSRF(session fixation) attacks without reintroducing full CSRF protection on login endpoint? and this article on login CSRF UX issues:
|
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
Hey! Great question. This is something we considered carefully. Epic Stack uses For login CSRF/session fixation: our If we ever change our cookie config (e.g., to More details in our decision doc as you linked: https://github.com/epicweb-dev/epic-stack/blob/main/docs/decisions/035-remove-csrf.md Thanks for raising the concern! |
Beta Was this translation helpful? Give feedback.
-
@kentcdodds Yes, using However, I’m specifically referring to public POST endpoints, particularly the Consider the following attack scenario: Even though no cookies are required to be sent with the request (so SameSite=Lax blocks nothing here), epic app sets a session cookie as a result of that login. From the victim’s perspective, they are now logged in—but under someone else’s identity. If they do not notice (and most users will not), this leads to confusing and potentially dangerous behavior. For example, an attacker might retrieve anything the victim does while logged into that session—search history, profile changes etc. This is the same class of issue Google once faced.
I understand and agree with the motivation to simplify the stack and avoid full CSRF protection everywhere. However, I would suggest treating the login endpoint as a special case. It is public, it changes authentication state, and it has no CSRF protection under the current setup. One lightweight and effective approach could be to add CSRF protection only to the login endpoint. That would protect against this class of attacks without reintroducing complexity across the app. From a user experience perspective, this kind of attack is especially frustrating because the user likely has no idea anything went wrong. They just end up logged in as someone else, and it can take a long time before they realize it. So again, the overall design is strong and well-considered. I just think public POST endpoints, in this case the login route, deserves this small extra layer of protection to avoid a very confusing and subtle failure case. |
Beta Was this translation helpful? Give feedback.
-
The attack does not rely on cookies being sent with the request. It relies on the fact that server sets a session cookie in the response. That means an attacker can still trick a user’s browser into submitting a cross-site POST to /login using the attacker’s own credentials. If the login succeeds, the browser receives a session cookie — authenticating the victim as the attacker. Example flow:
<form method="POST" action="https://epic-app.com/login">
<input name="username" value="[email protected]" />
<input name="password" value="password123" />
</form>
<script>document.forms[0].submit()</script>
This is possible even if the login request is cross-origin and has no existing cookies. The critical point is that the server responds with a Set-Cookie, which the browser stores.
|
Beta Was this translation helpful? Give feedback.
This is a very good point! I would be willing to accept a pull request to add CSRF protection for the login form. Thank you for bringing this up.