Skip to content

Commit 41ab24d

Browse files
committed
feat(graphile): propagate jwt.claims.session_id to pgSettings
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
1 parent 15a46bc commit 41ab24d

2 files changed

Lines changed: 5 additions & 0 deletions

File tree

graphql/server/src/middleware/graphile.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,10 @@ const buildPreset = (
239239
...context,
240240
};
241241

242+
if (req.token.session_id) {
243+
pgSettings['jwt.claims.session_id'] = req.token.session_id;
244+
}
245+
242246
// Propagate credential metadata as JWT claims so PG functions
243247
// can read them via current_setting('jwt.claims.access_level') etc.
244248
if (req.token.access_level) {

graphql/server/src/middleware/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { ApiStructure } from '../types';
33
export type ConstructiveAPIToken = {
44
id?: string;
55
user_id?: string;
6+
session_id?: string;
67
access_level?: string;
78
kind?: string;
89
[key: string]: unknown;

0 commit comments

Comments
 (0)