Skip to content

OIDC: csrf token validation failed when multiple requests on the same OIDC protected domain are accessed at the same time #7205

Closed

Description

@zhaohuabing

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:

  1. logout if already login with OIDC
  2. add multiple urls with the same domain secured by OIDC security policy(oauth2 filter is used under the hood) to a browser bookmark folder.
  3. 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.

Activity

  1. added
    kind/bug
    and removed on Oct 13, 2025
  2. self-assigned this
    on Oct 13, 2025
  3. sylvainOL commented on Oct 17, 2025

    @sylvainOL

    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.

  4. rudi-ch commented on Oct 21, 2025

    @rudi-ch

    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.

  5. rudi-ch commented on Oct 22, 2025

    @rudi-ch

    Is there a way to turn off PKCE in the meantime?

  6. 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
  7. zhaohuabing commented on Oct 28, 2025

    @zhaohuabing
    MemberAuthor

    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

  8. rudi-ch commented on Oct 28, 2025

    @rudi-ch

    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.

  9. zhaohuabing commented on Oct 29, 2025

    @zhaohuabing
    MemberAuthor

    CSRF and PKCE are two different things.

    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?

  10. github-actions commented on Dec 25, 2025

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has not had activity in the last 30 days.

  11. zhaohuabing commented on Dec 31, 2025

    @zhaohuabing
    MemberAuthor

    Closing this issue as the fix has been merged on the envoy upstream. No change on the Envoy Gateway side is needed.

  12. frandiazplatox commented on Jan 7, 2026

    @frandiazplatox

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions