Skip to content
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

Does Panda avoid race conditions on its anti-forgery token? #142

Open
rtyley opened this issue May 21, 2024 · 0 comments
Open

Does Panda avoid race conditions on its anti-forgery token? #142

rtyley opened this issue May 21, 2024 · 0 comments

Comments

@rtyley
Copy link
Member

rtyley commented May 21, 2024

We fixed an re-authentication issue in play-googleauth back in 2018, the issue also looks like it may affect pan-domain-authentication, to some extent:

image

When authenticating, the OAuth process requires that we send an anti-forgery token when redirecting to Google, and then verify that token when it comes back - in Panda, we use a random string and store it in the panda-antiForgeryToken cookie before redirecting to Google:

def sendForAuth(implicit request: RequestHeader, email: Option[String] = None) = {
val antiForgeryToken = OAuth.generateAntiForgeryToken()
OAuth.redirectToOAuthProvider(antiForgeryToken, email)(ec) map { res =>
val originUrl = request.uri
res.withCookies(cookie(ANTI_FORGERY_KEY, antiForgeryToken), cookie(LOGIN_ORIGIN_KEY, originUrl))

...when Google redirects back to us, we check if the anti-forgery token we've been called with matches the value we've stored in the panda-antiForgeryToken cookie:

token <- decodeCookie(ANTI_FORGERY_KEY)
originalUrl <- decodeCookie(LOGIN_ORIGIN_KEY)
} yield {
OAuth.validatedUserIdentity(token)(request, ec, wsClient).map { claimedAuth =>

This can experience problems if the user has many browser windows open - if all browser windows decide to reauthenticate at the same time, they will all choose different random values for panda-antiForgeryToken, each overriding the cookie, and thus when Google redirects back to us, the validation will fail.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant