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
The Keycloak client uses the state OAuth 2.0 parameter, which is not mandatory but strongly recommended 👍.
I see in the client code that, when parsing the callback URL, it checks that the state parameter exists, but never checks if its value matches the one it generated at the beginning of the flow. I think this could lead to security vulnerability.
Could you please tell me if I'm right, and if so, fix this?
Thanks a lot!
Version
26.0.6
Expected behavior
If the client gets a response with a different state token than the one it initially generated, it should stop the authentication flow.
Actual behavior
If the client gets a response with a different state token than the one it initially generated, it continues with the authentication flow.
How to Reproduce?
Edit the state parameter that is returned by the server.
This parameter is actually validated, although the code could be a bit clearer on the matter. The state parameter is used as a key for state stored locally in the browser, if the stored state cannot be found then the callback never becomes valid when parsed:
This basically means that Keycloak JS will consider this a whole new flow, and it will do all the checks from scratch again. This is working as intended, and is secure behavior.
Activity
jonkoops commentedon Jul 8, 2025
This parameter is actually validated, although the code could be a bit clearer on the matter. The
stateparameter is used as a key for state stored locally in the browser, if the stored state cannot be found then the callback never becomesvalidwhen parsed:keycloak-js/lib/keycloak.js
Lines 1020 to 1029 in bb0ad94
This means that later on, the callback will be determined invalid, and is never processed:
keycloak-js/lib/keycloak.js
Lines 811 to 815 in bb0ad94
This basically means that Keycloak JS will consider this a whole new flow, and it will do all the checks from scratch again. This is working as intended, and is secure behavior.
jonkoops commentedon Jul 8, 2025
No problem, thanks for reporting this, I had to do some digging as well to understand if we were doing the right thing here.