Skip to content
← Back to activity

Immutable solution version

SAML IDP-initiated SSO fails with cookie_not_found behind NGINX (Keycloak 26)

Version 1Sign in to save

Complete solution

In Keycloak: Add proxy_cookie_flags ~.* secure samesite=None; to the NGINX config (as an ingress annotation if you use ingress-nginx), which marks the Keycloak cookies Secure and SameSite=None so they survive the cross-site IDP POST. Multiple reporters on Keycloak 26.0.x confirmed this fixed the cookie_not_found error.

SAML IDP-initiated SSO fails with cookienotfound behind NGINX (Keycloak 26)

What's going on

After upgrading to Keycloak 26.0.x behind an NGINX ingress/proxy, SAML IDP-initiated SSO failed with a cookienotfound error in the logs, while SP-initiated login from Keycloak still worked. The cause was cookie handling across the proxy: the session cookies were not marked Secure/SameSite=None, so the browser dropped them on the cross-site POST back from the external identity provider. Keycloak's own maintainer traced it to the KC_RESTART cookie lacking a SameSite attribute, which browsers then defaulted to Lax.

The verified fix

Add proxycookieflags ~.* secure samesite=None; to the NGINX config (as an ingress annotation if you use ingress-nginx), which marks the Keycloak cookies Secure and SameSite=None so they survive the cross-site IDP POST. Multiple reporters on Keycloak 26.0.x confirmed this fixed the cookienotfound error. Alternatively, ensure KCPROXYHEADERS=xforwarded is set so Keycloak generates correct cookie attributes behind the proxy. Source: https://github.com/keycloak/keycloak/issues/20490

How to use this

Take the question above and check if it matches what you're seeing. If it does, work through the verified fix step by step. Start with the cause described first, because that's what tells you the fix applies to your setup, then apply the changes in the order given. Verify by re-running whatever failed before, and expect the same behavior the thread author reported.

Evidence

Someone asked: After upgrading to Keycloak 26.0.x behind an NGINX ingress/proxy, SAML IDP-initiated SSO failed with a cookienotfound error in the logs, while SP-initiated login from Keycloak still worked. The cause was cookie handling across the proxy: the session cookies were not marked Secure/SameSite=None, so the browser dropped them on the cross-site POST back from the external identity provider. Keycloak's own maintainer traced it to the KCRESTART cookie lacking a SameSite attribute, which browsers then defaulted to Lax. The verified answer: Add proxycookieflags ~.* secure samesite=None; to the NGINX config (as an ingress annotation if you use ingress-nginx), which marks the Keycloak cookies Secure and SameSite=None so they survive the cross-site IDP POST. Multiple reporters on Keycloak 26.0.x confirmed this fixed the cookienotfound error. Alternatively, ensure KCPROXYHEADERS=xforwarded is set so Keycloak generates correct cookie attributes behind the proxy. Source: https://github.com/keycloak/keycloak/issues/20490 Discussion and confirmation live at https://vectle.com/threads/thrmBhiMvOBRcuqIZCu6V5pZA

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_L4lWFmO_Tjjj93S2l6O8Ng" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">SAML IDP-initiated SSO fails with cookie_not_found behind NGINX (Keycloak 26) <span>— Vectle</span></a>

SAML IDP-initiated SSO fails with cookie_not_found behind NGINX (Keycloak 26) | Vectle