-
Notifications
You must be signed in to change notification settings - Fork 4.9k
oauth2: CSRF cookie should be cleared after flow complete #39210
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
Comments
@bplotnick Thanks for reporting this issue! Is it blocking your use case? I'll take care of it when I have some time. |
/assign |
@zhaohuabing yeah, it's blocking but i can write the fix (i've already written the regression test). just wanted to open the issue first to solicit input and make sure that the proposed solution is acceptable. |
The browser sometimes sends multiple requests before the first one gets authenticated, resulting in multiple callbacks from the OAuth2 server, which may not always arrive in the same order as the requests were sent. The same nonce is used for these requests to ensure successful nonce validation. More discussion can be found here: #36276
I think this approach should work. we can remove the existing CSRF cookie and create a new one using the new HMAC. |
/unassign |
This makes sense, thanks for the context
ok i'll go ahead and implement this |
…on (#39213) Commit Message: Reset CSRF token when token validation fails during redirection Additional Description: If the CSRF token cookie is present during the redirection to the authorization server, it will be validated. Previously, if this validation failed, the oauth flow would fail. Now it will simply be reset. This fixes the case where an hmac secret change causes a redirect flow, but the CSRF token cookie hasn't yet expired causing a CSRF token validation failure. Risk Level: Low Testing: Unit tests Docs Changes: Release Notes: Reset CSRF token when token validation fails during redirection. If the CSRF token cookie is present during the redirection to the authorization server, it will be validated. Previously, if this validation failed, the oauth flow would fail. Now the CSRF token will simply be reset. This fixes the case where an hmac secret change causes a redirect flow, but the CSRF token cookie hasn't yet expired causing a CSRF token validation failure. Platform Specific Features: Fixes: #39210 --------- Signed-off-by: Ben Plotnick <bplotnick@netflix.com>
Title: CSRF cookie should be cleared after flow complete
Description:
I think that the CSRF cookie should be cleared after the completion of the flow. Firstly, it isn't needed anymore after the flow, so it's extraneous. But more importantly, you can have a scenario where it fails validation but improperly causes a failed flow. Let's say you rotate the HMAC secret, the token hmac validation will fail, which will send you into redirectToOAuthServer(), but then the CSRF token will get validated here and also fail validation.
We should probably 1) clear the CSRF cooke after the callback validation and 2) clear and remove the cookie when during redirect rather than failing the flow.
Repro steps:
csrf token validation failed
CC: @zhaohuabing
The text was updated successfully, but these errors were encountered: