fix(authz-casdoor): scope session cookie per Casdoor client#13387
Open
shreemaan-abhishek wants to merge 4 commits into
Open
fix(authz-casdoor): scope session cookie per Casdoor client#13387shreemaan-abhishek wants to merge 4 commits into
shreemaan-abhishek wants to merge 4 commits into
Conversation
Each route's authz-casdoor session is now stored under a cookie name derived from its client_id, and the session payload is bound to the client_id it was issued for. Sessions established by one route are no longer honored by a route configured with a different client_id.
Replace the character-substitution helper with ngx.md5 so that distinct client_id values map to distinct session cookie names.
Switch the per-client cookie name derivation from ngx.md5 to resty.sha256, matching the pattern used in csrf, hmac-auth, and aws-lambda for security-adjacent hashing. The result is memoized per client_id at module scope so the digest is computed once per route load, not per request. Extend the regression test to assert that the Set-Cookie names issued by two routes with different client_ids differ, pinning the cookie-name scoping layer independently of the in-session client_id check.
nic-6443
approved these changes
May 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Each route configured with the
authz-casdoorplugin now stores its session under a cookie name derived from itsclient_id, and the session payload itself is bound to theclient_idit was issued for.Previously, every
authz-casdoorroute on a given host shared the defaultresty.sessioncookie name (session), and the access check at the start of_M.accessonly verified that anaccess_tokenwas present in the session — it did not verify that the session belonged to the route'sclient_id. As a result, twoauthz-casdoorroutes on the same host configured with differentclient_ids shared authentication state.The fix has two layers:
conf.client_id(sanitized to[A-Za-z0-9_]) and passed ascookie_nameto everyresty.sessionopen/new/startcall inside the plugin. Differentclient_ids now read and write different cookies.client_idbinding.client_idis stored in the session at write time. The gate check additionally requiressession_obj:get("client_id") == conf.client_idbefore honoring an existing session, so a session payload cannot be honored by a route configured with a differentclient_id.A regression test (
TEST 11+TEST 12int/plugin/authz-casdoor.t) configures two routes on the same host with differentclient_ids (low-clienton/low/*,high-clienton/high/*), drives the full login flow against the first route, and then re-uses the resulting cookie against the second route — asserting that the second route still redirects to Casdoor with its ownclient_id.Which issue(s) this PR fixes:
Fixes #
Breaking changes
authz-casdoorsessions will not be recognized: the cookie name changes from theresty.sessiondefault to a per-client_idname. Users will be redirected to Casdoor once to re-establish their session.authz-casdoorroutes on the same host with differentclient_ids and implicitly relied on a single session being shared between them will no longer do so. Operators that want shared authentication state across routes should configure those routes with the sameclient_id.Checklist