You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OIDC: csrf token validation failed when multiple requests on the same OIDC protected domain are accessed at the same time #7205
From time to time we see this error OAuth flow failed. appearing in the browser, when a HTTP-Route is secured with an OIDC Security Policy. Furthermore also some users report this behavior.
In the Browser a 401 with the text OAuth flow failed. is rendered.
Log reports that “csrf token validation failed”.
It might be the case that a browser tab is initiating the authentication, which is then setting the csrf token to a specific value.
And then a different tab is also in parallel initiating the authentication which also sets a different csrf token.
How to reproduce this:
logout if already login with OIDC
add multiple urls with the same domain secured by OIDC security policy(oauth2 filter is used under the hood) to a browser bookmark folder.
right click that bookmark folder, select "Open-All" pop-up menu
All the other opened tabs except the last one will report OAuth flow failed.
Note: this needs to be handled in envoy data plane. Creating this issue just for tracking purpose.
We also have it just after connecting, I was thinking that the issue may be because we have several pods running and the second request is done on another pod that don't have yet retrieved the token.
I see the same issue with this setup backed by a single GW class...
Three HTTP routes, one of which is a dummy for the OAuth2 callback
NAMESPACE NAME HOSTNAMES AGE
trial auth-dummy ["auth.trial.test.com"] 48d
trial echo-envoy ["echo-envoy.trial.test.com"] 56d
argocd argocd ["argocd.trial.test.com"] 55d
Two security policies, one per namespace
NAMESPACE NAME AGE
trial echo-envoy 52d
argocd echo-envoy 52d
They use the same Google OIDC client configuration and share the same, static idToken cookie name so that you should only log in once.
Two gateways sharing the same class
NAMESPACE NAME CLASS ADDRESS PROGRAMMED AGE
trial trial wildcard k8s-envoygat-foo-yyy-zzz.elb.xxx.amazonaws.com True 52d
argocd argocd wildcard k8s-envoygat-foo-yyy-zzz.elb.xxx.amazonaws.com True 52d
The echo-envoy route, which just points to a backend that echoes HTTP headers back, works fine. The argocd route results in OAuth flow failed and csrf token validation failed, respectively.
changed the title [-]oidc: csrf token validation failed when multiple requests on the same OIDC protected domain are accessed at the same time[/-][+]OIDC: csrf token validation failed when multiple requests on the same OIDC protected domain are accessed at the same time[/+]on Oct 28, 2025
The OAuth 2.0 [RFC6749] server responses are unchanged by the PKCE specification, client implementations of this specification do not need to know if the server has implemented this specification or not and SHOULD send the additional parameters as defined in Section 4 to all servers.
Thank you @zhaohuabing. I was just looking for a temporary workaround. The issue occurs for us 100% of the time. We don't even need to use multiple tabs. Just go to the first URL (echo-envoy), which works. Then type or autocomplete the second URL and you get the "OAuth flow failed." error. Maybe I'll just turn off Gateway Namespace mode and stop sharing cookies across hostnames.
Maybe I'll just turn off Gateway Namespace mode and stop sharing cookies across hostnames.
This only happens in Gateway Namespace mode when cookied_domain is set as trial.test.com? Could you please share an example setup that I can reproduce this at my side?
This only happens in Gateway Namespace mode when cookied_domain is set as trial.test.com? Could you please share an example setup that I can reproduce this at my side?
for me it happens with cookie_domain set but not with namespace mode.
I see the same issue with this setup backed by a single GW class...
Three HTTP routes, one of which is a dummy for the OAuth2 callback
NAMESPACE NAME HOSTNAMES AGE
trial auth-dummy ["auth.trial.test.com"] 48d
trial echo-envoy ["echo-envoy.trial.test.com"] 56d
argocd argocd ["argocd.trial.test.com"] 55d
Hi @rudi-ch may I ask how you declare such dummy route for the OAuth2 callback? I assume it is needed for Envoy to be able to route the callback to itself, right?
I'm sorry to bother you but the only examples I find are those where the callback is implemented by the application instead of Envoy.
Activity
sylvainOL commentedon Oct 17, 2025
Hello, we do have this issue quite often.
We also have it just after connecting, I was thinking that the issue may be because we have several pods running and the second request is done on another pod that don't have yet retrieved the token.
rudi-ch commentedon Oct 21, 2025
I see the same issue with this setup backed by a single GW class...
Three HTTP routes, one of which is a dummy for the OAuth2 callback
Two security policies, one per namespace
They use the same Google OIDC client configuration and share the same, static idToken cookie name so that you should only log in once.
Two gateways sharing the same class
The echo-envoy route, which just points to a backend that echoes HTTP headers back, works fine. The argocd route results in
OAuth flow failedandcsrf token validation failed, respectively.rudi-ch commentedon Oct 22, 2025
Is there a way to turn off PKCE in the meantime?
[-]oidc: csrf token validation failed when multiple requests on the same OIDC protected domain are accessed at the same time[/-][+]OIDC: csrf token validation failed when multiple requests on the same OIDC protected domain are accessed at the same time[/+]zhaohuabing commentedon Oct 28, 2025
PKCE can't(don't need to) be turned off.
The OAuth 2.0 [RFC6749] server responses are unchanged by the PKCE specification, client implementations of this specification do not need to know if the server has implemented this specification or not and SHOULD send the additional parameters as defined in Section 4 to all servers.
This is recommend by rfc 7636: https://www.rfc-editor.org/rfc/rfc7636#section-5
rudi-ch commentedon Oct 28, 2025
Thank you @zhaohuabing. I was just looking for a temporary workaround. The issue occurs for us 100% of the time. We don't even need to use multiple tabs. Just go to the first URL (echo-envoy), which works. Then type or autocomplete the second URL and you get the "OAuth flow failed." error. Maybe I'll just turn off Gateway Namespace mode and stop sharing cookies across hostnames.
zhaohuabing commentedon Oct 29, 2025
CSRF and PKCE are two different things.
This only happens in Gateway Namespace mode when
cookied_domainis set astrial.test.com? Could you please share an example setup that I can reproduce this at my side?sylvainOL commentedon Oct 29, 2025
for me it happens with
cookie_domainset but not with namespace mode.Here's the code for:
github-actions commentedon Dec 25, 2025
This issue has been automatically marked as stale because it has not had activity in the last 30 days.
zhaohuabing commentedon Dec 31, 2025
Closing this issue as the fix has been merged on the envoy upstream. No change on the Envoy Gateway side is needed.
frandiazplatox commentedon Jan 7, 2026
Hi @rudi-ch may I ask how you declare such dummy route for the OAuth2 callback? I assume it is needed for Envoy to be able to route the callback to itself, right?
I'm sorry to bother you but the only examples I find are those where the callback is implemented by the application instead of Envoy.