feat(graphile): propagate jwt.claims.session_id to pgSettings#1014
Merged
pyramation merged 1 commit intomainfrom Apr 19, 2026
Merged
feat(graphile): propagate jwt.claims.session_id to pgSettings#1014pyramation merged 1 commit intomainfrom
pyramation merged 1 commit intomainfrom
Conversation
Pairs with constructive-io/constructive-db#908, which adds session_id to the RETURNS TABLE of authenticate() and authenticate_strict(). Now that req.token.session_id is populated by the auth middleware, surface it as "jwt.claims.session_id" on the request transaction so jwt_private.current_session_id() returns a real value. Without this, every session-scoped DB procedure (sign_out, revoke_session, extend_token_expires, verify_password, verify_totp, require_step_up, webauthn_*) silently matches zero rows — the MFA step-up window in particular never elevates because verify_password updates sessions.last_password_verified WHERE id = NULL. - types.ts: add session_id?: string to ConstructiveAPIToken - graphile.ts: set pgSettings['jwt.claims.session_id'] when present
Contributor
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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.
Summary
Pairs with constructive-io/constructive-db#908, which adds
session_idto theRETURNS TABLEofauthenticate()andauthenticate_strict(). Now thatreq.token.session_idis populated by the auth middleware (it falls out ofresult.rows[0]in <ref_snippet file="/home/ubuntu/repos/constructive/graphql/server/src/middleware/auth.ts" lines="118-138" />), surface it asjwt.claims.session_idon the request transaction sojwt_private.current_session_id()returns a real value inside PL/pgSQL.Without this, every session-scoped DB procedure silently matched zero rows:
verify_password,verify_totp—UPDATE sessions SET last_password_verified = now() WHERE id = NULLis a no-op, so the subsequentrequire_step_upcheck still fails.sign_out,revoke_session,extend_token_expires, allwebauthn_*flows — same pattern.The most user-visible break was MFA step-up: completing a password challenge did nothing.
Changes
session_id?: stringtoConstructiveAPIToken.pgSettings['jwt.claims.session_id']when present.Guarded with an
if (req.token.session_id)so this PR is safe to ship before the DB-side PR rolls out: ifauthenticate()still returns the old 4-column shape,req.token.session_idwill beundefinedand the GUC simply isn't set (same behavior as today). Once the DB-side ships, the GUC starts flowing automatically.Review & Testing Checklist for Human
Risk: yellow — one-line change, but it's on the auth hot path.
req.token.session_idstays undefined and this PR is a no-op (safe, but not useful).SELECT current_setting('jwt.claims.session_id', true)via GraphQL/psql inside a request transaction and confirm it matches the session row for the current login.require_step_upnow sees the elevation.Notes
ConstructiveAPITokenalready had[key: string]: unknown, so typingsession_id?: stringis additive and doesn't break any consumer.Link to Devin session: https://app.devin.ai/sessions/f0c49af3f7f24bf39e5ad0fd74f25c07
Requested by: @pyramation