najm-auth 3.3.2 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { A as AuthUser } from './types-BaSfgxqE.js';
1
+ import { A as AuthUser } from './types-CI2t8wpJ.js';
2
2
  import { S as SessionRecoveryFailure } from './sessionRecovery-D5Fa0yZ1.js';
3
3
 
4
4
  interface ServerSession {
package/dist/index.d.ts CHANGED
@@ -109,7 +109,7 @@ interface SessionCookieConfig {
109
109
  /** HMAC secret. Falls back to NAJM_SESSION_SECRET, then jwt.accessSecret. */
110
110
  secret?: string;
111
111
  }
112
- type OAuthProvider = 'google';
112
+ type OAuthProvider = 'google' | 'github';
113
113
  interface GoogleOAuthConfig {
114
114
  /** Google OAuth web client ID. Falls back to GOOGLE_CLIENT_ID. */
115
115
  clientId?: string;
@@ -131,12 +131,33 @@ interface GoogleOAuthConfig {
131
131
  /** Optional Google Workspace hosted-domain allowlist. */
132
132
  allowedHostedDomains?: string[];
133
133
  }
134
+ interface GitHubOAuthConfig {
135
+ /** GitHub OAuth App client ID. Falls back to GITHUB_CLIENT_ID. */
136
+ clientId?: string;
137
+ /** GitHub OAuth App client secret. Falls back to GITHUB_CLIENT_SECRET. */
138
+ clientSecret?: string;
139
+ /**
140
+ * Absolute backend callback URL registered in GitHub. Falls back to
141
+ * GITHUB_CALLBACK_URL, then `${frontendUrl}/api/auth/oauth/github/callback`.
142
+ */
143
+ callbackUrl?: string;
144
+ /** Frontend route that completes the Najm client session. */
145
+ frontendCallbackPath?: string;
146
+ /** Frontend route that receives stable OAuth errors. */
147
+ errorRedirectPath?: string;
148
+ /** Create a Najm user for a new GitHub identity (default: true). */
149
+ allowSignup?: boolean;
150
+ /** Link an existing user by verified email (default: false). */
151
+ autoLinkVerifiedEmail?: boolean;
152
+ }
134
153
  interface OAuthConfig {
135
154
  /**
136
155
  * Enable Google with environment defaults (`google: true`), or override
137
156
  * individual settings for split-origin deployments and policy changes.
138
157
  */
139
158
  google?: true | GoogleOAuthConfig;
159
+ /** Enable GitHub with environment defaults, or override provider settings. */
160
+ github?: true | GitHubOAuthConfig;
140
161
  }
141
162
  interface ResolvedGoogleOAuthConfig {
142
163
  clientId: string;
@@ -148,8 +169,18 @@ interface ResolvedGoogleOAuthConfig {
148
169
  autoLinkVerifiedEmail: boolean;
149
170
  allowedHostedDomains: string[];
150
171
  }
172
+ interface ResolvedGitHubOAuthConfig {
173
+ clientId: string;
174
+ clientSecret: string;
175
+ callbackUrl: string;
176
+ frontendCallbackPath: string;
177
+ errorRedirectPath: string;
178
+ allowSignup: boolean;
179
+ autoLinkVerifiedEmail: boolean;
180
+ }
151
181
  interface ResolvedOAuthConfig {
152
182
  google?: ResolvedGoogleOAuthConfig;
183
+ github?: ResolvedGitHubOAuthConfig;
153
184
  }
154
185
  /**
155
186
  * Complete auth plugin configuration (internal)
@@ -628,6 +659,11 @@ interface SessionCookieData {
628
659
  * (password change/reset, logout-all) without hitting the database.
629
660
  */
630
661
  sessionVersion: number;
662
+ /**
663
+ * The refresh session this snapshot belongs to, so a single-device logout —
664
+ * which deliberately leaves the per-user version alone — can still reach it.
665
+ */
666
+ tokenFamily: string;
631
667
  /** Epoch ms when the cookie was written */
632
668
  iat: number;
633
669
  }
@@ -646,8 +682,10 @@ declare class CookieManager {
646
682
  getCookieName(): string;
647
683
  /**
648
684
  * Write a signed session cookie containing user data, roles, and permissions.
649
- * The cookie is HMAC-signed with the configured session secret so it is tamper-proof
650
- * but readable without a database query. Short TTL (5 min) ensures freshness.
685
+ * The cookie is HMAC-signed with the configured session secret, so its claims
686
+ * can be parsed without a database query. Authorization still verifies the
687
+ * session version and positive family liveness; a valid signature alone is
688
+ * never a revocation check. Short TTL (5 min) bounds claim staleness.
651
689
  */
652
690
  setSessionCookie(data: Omit<SessionCookieData, 'iat'>): void;
653
691
  /**
@@ -684,6 +722,12 @@ declare class UserRepository {
684
722
  role?: string | null;
685
723
  }) | undefined>;
686
724
  create(data: NewUser): Promise<User>;
725
+ /**
726
+ * Ids of everyone holding a role. Used to end sessions when the role's
727
+ * permission set changes: tokens carry permissions as claims, so the holders
728
+ * keep exercising the old set until their sessions do.
729
+ */
730
+ getIdsByRole(roleId: string): Promise<string[]>;
687
731
  update(id: string, data: Partial<NewUser>): Promise<User | undefined>;
688
732
  updateLastLogin(id: string): Promise<User>;
689
733
  incrementFailedAttempts(id: string): Promise<User>;
@@ -917,64 +961,6 @@ declare class RoleService {
917
961
  getRoleIdByName(name: any): Promise<string>;
918
962
  }
919
963
 
920
- type SanitizedUser = Omit<User, 'password' | 'failedLoginAttempts' | 'lockoutUntil'> & {
921
- role?: string | null;
922
- permissions?: string[];
923
- };
924
- declare class UserService {
925
- private roleValidator;
926
- private roleService;
927
- private userRepository;
928
- private userValidator;
929
- private encryptionService;
930
- private i18nService;
931
- private authConfig;
932
- private t;
933
- constructor(roleValidator: RoleValidator, roleService: RoleService, userRepository: UserRepository, userValidator: UserValidator, encryptionService: EncryptionService, i18nService: I18nService, authConfig: AuthConfig);
934
- private sanitizeUser;
935
- private sanitizeUsers;
936
- private requireUser;
937
- private resolveUserRole;
938
- getAll(options?: {
939
- limit?: number;
940
- offset?: number;
941
- }): Promise<SanitizedUser[]>;
942
- getById(id: string): Promise<SanitizedUser>;
943
- getByEmail(email: string): Promise<SanitizedUser>;
944
- /**
945
- * Find user by email without throwing - returns null if not found
946
- * Used for timing-safe authentication
947
- */
948
- findByEmail(email: string): Promise<(User & {
949
- role?: string | null;
950
- }) | undefined>;
951
- findByEmailInsensitive(email: string): Promise<(User & {
952
- role?: string | null;
953
- }) | undefined>;
954
- findByPhone(phone: string): Promise<UserWithPermissions>;
955
- getAuthRecordById(id: string): Promise<User | undefined>;
956
- create(data: Record<string, any>, options?: {
957
- validatePasswordStrength?: boolean;
958
- }): Promise<SanitizedUser>;
959
- update(id: string, data: Record<string, any>): Promise<SanitizedUser>;
960
- delete(id: string): Promise<SanitizedUser>;
961
- deleteAll(): Promise<SanitizedUser[]>;
962
- getRoleName(id: string): Promise<string | null>;
963
- updateLastLogin(id: string): Promise<void>;
964
- incrementFailedAttempts(id: string): Promise<number>;
965
- resetFailedAttempts(id: string): Promise<void>;
966
- setLockout(id: string, until: string): Promise<void>;
967
- assignRole(id: string, roleId?: string, roleName?: string): Promise<SanitizedUser>;
968
- removeRole(id: string): Promise<SanitizedUser>;
969
- seedAdminUser(config?: {
970
- email?: string;
971
- password?: string;
972
- name?: string;
973
- }): Promise<SanitizedUser>;
974
- updateLang(language: string): Promise<string>;
975
- getLang(): Promise<string>;
976
- }
977
-
978
964
  declare class TokenRepository {
979
965
  db: TDb;
980
966
  private schema;
@@ -1000,7 +986,7 @@ declare class TokenRepository {
1000
986
  }): Promise<any>;
1001
987
  /**
1002
988
  * Rotate an existing refresh-token family with compare-and-swap semantics.
1003
- * This can never insert a family deleted by a concurrent logout.
989
+ * This can never update a family durably revoked by a concurrent logout.
1004
990
  */
1005
991
  rotateRefreshToken(tokenData: {
1006
992
  userId: string;
@@ -1023,9 +1009,15 @@ declare class TokenRepository {
1023
1009
  markPreviousUsed(tokenFamily: string, previousHash: string): Promise<any>;
1024
1010
  /** Look up a single session's token row by its family identifier. */
1025
1011
  getByFamily(tokenFamily: string): Promise<any>;
1026
- /** Revoke a single session (one family). */
1012
+ /**
1013
+ * Durably revoke one family without depending on physical deletion.
1014
+ *
1015
+ * The row remains as a tombstone until its original refresh expiry. This is
1016
+ * what prevents a later cache loss from turning a failed/omitted cleanup
1017
+ * delete into a valid database-backed recovery session.
1018
+ */
1027
1019
  revokeFamily(tokenFamily: string): Promise<any>;
1028
- /** Revoke every session for a user (password change/reset, logout-all). */
1020
+ /** Durably revoke every active family for a user. */
1029
1021
  revokeAllForUser(userId: string): Promise<any>;
1030
1022
  /**
1031
1023
  * Opportunistic cleanup: with one row per family (no unique userId), expired
@@ -1042,6 +1034,193 @@ declare class TokenRepository {
1042
1034
  getUser(userId: string): Promise<any>;
1043
1035
  }
1044
1036
 
1037
+ /**
1038
+ * The single owner of "this credential is no longer good".
1039
+ *
1040
+ * Every path that changes a user's security state — status, password, role,
1041
+ * permissions, deletion — has to reach the same code, or one of them will be
1042
+ * forgotten and an already-issued token will outlive the change that was
1043
+ * supposed to end it. That is the shape of the defect this service closes.
1044
+ *
1045
+ * It deliberately depends on the repository rather than TokenService: TokenService
1046
+ * needs to call it too, and going through the service would close a DI cycle.
1047
+ */
1048
+ declare class SessionInvalidationService {
1049
+ private cache;
1050
+ private tokens;
1051
+ private config;
1052
+ constructor(cache: CacheService, tokens: TokenRepository);
1053
+ /**
1054
+ * Fields whose change ends existing sessions. Everything absent from this set
1055
+ * — display name, avatar, language — is a profile edit and must leave the
1056
+ * user signed in, on every device.
1057
+ */
1058
+ static readonly SECURITY_FIELDS: readonly ["password", "status", "role", "roleId", "email", "emailVerified", "phone"];
1059
+ /** Whether an update payload touches anything that must end sessions. */
1060
+ static affectsSecurityState(data: Record<string, unknown> | null | undefined): boolean;
1061
+ private get accessTokenTtlMs();
1062
+ private get refreshTokenTtlMs();
1063
+ sessionVersionKey(userId: string): string;
1064
+ revokedFamilyKey(tokenFamily: string): string;
1065
+ /**
1066
+ * Positive liveness marker for one session family.
1067
+ *
1068
+ * The signed session snapshot is authorized against this rather than against
1069
+ * the absence of a revocation marker, so losing the cache cannot make a
1070
+ * logged-out family look valid again: with no marker the fast path simply
1071
+ * declines and the request falls through to the database-backed resolver.
1072
+ */
1073
+ familyKey(tokenFamily: string): string;
1074
+ userCacheKey(userId: string): string;
1075
+ parseSessionVersion(raw: string | null): number;
1076
+ getSessionVersion(userId: string): Promise<number>;
1077
+ /**
1078
+ * Extend the version key's lifetime without rewriting its value.
1079
+ *
1080
+ * Token issuance used to `set()` the version it had just read, which meant an
1081
+ * invalidation landing between that read and that write was silently undone —
1082
+ * the revoked version came back and the old tokens verified again. Only the
1083
+ * expiry is touched here, so a concurrent bump always survives.
1084
+ */
1085
+ touchSessionVersion(userId: string): Promise<void>;
1086
+ /**
1087
+ * Invalidate every access token already issued for a user, and drop the
1088
+ * cached user record so the next read sees the new state rather than a stale
1089
+ * snapshot that is merely truthy.
1090
+ *
1091
+ * The bump is an atomic increment, so concurrent invalidations cannot read
1092
+ * the same version and write the same successor back.
1093
+ */
1094
+ invalidateAccessTokens(userId: string): Promise<number>;
1095
+ dropUserCache(userId: string): Promise<void>;
1096
+ /**
1097
+ * End every session a user holds: access tokens by version, refresh sessions
1098
+ * by row, and each family's liveness marker.
1099
+ *
1100
+ * Callers run this AFTER their database mutation has committed. Running it
1101
+ * before would leave a window in which a concurrent login re-established a
1102
+ * session against the state the mutation was about to remove; running it
1103
+ * after a rollback merely signs the user out again, which is safe.
1104
+ */
1105
+ invalidateUser(userId: string): Promise<void>;
1106
+ /**
1107
+ * Record that a family is live, and whose it is. Called wherever the family's
1108
+ * refresh row is written.
1109
+ *
1110
+ * The marker stores the owning user rather than a bare flag so a reader can
1111
+ * confirm, in the same single lookup, that the family it was handed actually
1112
+ * belongs to the identity claiming it.
1113
+ *
1114
+ * Revocation always wins. A refresh that rotated its row, was descheduled,
1115
+ * and resumed after a logout would otherwise re-mark its family live and
1116
+ * hand the browser back the session it had just ended — the database row is
1117
+ * gone by then, but nothing on the fast path reads the database. So this
1118
+ * writes, then re-reads the revocation marker and withdraws the write if one
1119
+ * appeared. Combined with `markFamilyRevoked` setting the revocation marker
1120
+ * *before* clearing liveness, every interleaving of the two converges on
1121
+ * revoked: whichever of the pair observes the other, the liveness key ends
1122
+ * up deleted.
1123
+ *
1124
+ * @returns whether the family is live after this call.
1125
+ */
1126
+ markFamilyIssued(tokenFamily: string, userId: string): Promise<boolean>;
1127
+ /**
1128
+ * What one lookup can say about a family, in a single batched cache read.
1129
+ *
1130
+ * The three answers are deliberately distinct. `revoked` is authoritative and
1131
+ * must deny. `unknown` means the cache cannot vouch for the family — it was
1132
+ * evicted, or the cache was lost — and must send the caller to an
1133
+ * authoritative, database-backed check rather than being read either way.
1134
+ * Only `live` is a positive assertion, and only for the named user.
1135
+ */
1136
+ familyStatus(tokenFamily: string | undefined, userId?: string): Promise<'live' | 'revoked' | 'unknown'>;
1137
+ /**
1138
+ * Whether a family is positively known to be live, and — when a user is
1139
+ * given — to belong to that user.
1140
+ *
1141
+ * `false` means "not proven live" — revoked, mismatched, or simply not in
1142
+ * cache. Callers must treat it as a reason to fall back to an authoritative
1143
+ * check, never as proof of validity in the other direction.
1144
+ */
1145
+ isFamilyLive(tokenFamily: string, userId?: string): Promise<boolean>;
1146
+ private readMany;
1147
+ /**
1148
+ * Keep revocation through both credential lifetimes. If deleting the refresh
1149
+ * row fails, its still-valid cookie must remain denied after access expires.
1150
+ */
1151
+ markFamilyRevoked(tokenFamily: string): Promise<void>;
1152
+ isFamilyRevoked(tokenFamily: string): Promise<boolean>;
1153
+ }
1154
+
1155
+ type SanitizedUser = Omit<User, 'password' | 'failedLoginAttempts' | 'lockoutUntil'> & {
1156
+ role?: string | null;
1157
+ permissions?: string[];
1158
+ };
1159
+ declare class UserService {
1160
+ private roleValidator;
1161
+ private roleService;
1162
+ private userRepository;
1163
+ private userValidator;
1164
+ private encryptionService;
1165
+ private i18nService;
1166
+ private authConfig;
1167
+ private sessionInvalidation?;
1168
+ private t;
1169
+ constructor(roleValidator: RoleValidator, roleService: RoleService, userRepository: UserRepository, userValidator: UserValidator, encryptionService: EncryptionService, i18nService: I18nService, authConfig: AuthConfig, sessionInvalidation?: SessionInvalidationService);
1170
+ /**
1171
+ * End the user's sessions after a security-relevant mutation has committed.
1172
+ *
1173
+ * Deactivating, deleting, or re-roling an account through the generic
1174
+ * endpoints used to leave every already-issued token working until it
1175
+ * expired. Invalidation belongs here, next to the write, so no caller can
1176
+ * forget it — the application-level commands that already revoke keep doing
1177
+ * so, and a second call is harmless.
1178
+ */
1179
+ private invalidateSessions;
1180
+ private sanitizeUser;
1181
+ private sanitizeUsers;
1182
+ private requireUser;
1183
+ private resolveUserRole;
1184
+ getAll(options?: {
1185
+ limit?: number;
1186
+ offset?: number;
1187
+ }): Promise<SanitizedUser[]>;
1188
+ getById(id: string): Promise<SanitizedUser>;
1189
+ getByEmail(email: string): Promise<SanitizedUser>;
1190
+ /**
1191
+ * Find user by email without throwing - returns null if not found
1192
+ * Used for timing-safe authentication
1193
+ */
1194
+ findByEmail(email: string): Promise<(User & {
1195
+ role?: string | null;
1196
+ }) | undefined>;
1197
+ findByEmailInsensitive(email: string): Promise<(User & {
1198
+ role?: string | null;
1199
+ }) | undefined>;
1200
+ findByPhone(phone: string): Promise<UserWithPermissions>;
1201
+ getAuthRecordById(id: string): Promise<User | undefined>;
1202
+ create(data: Record<string, any>, options?: {
1203
+ validatePasswordStrength?: boolean;
1204
+ }): Promise<SanitizedUser>;
1205
+ update(id: string, data: Record<string, any>): Promise<SanitizedUser>;
1206
+ delete(id: string): Promise<SanitizedUser>;
1207
+ deleteAll(): Promise<SanitizedUser[]>;
1208
+ getRoleName(id: string): Promise<string | null>;
1209
+ updateLastLogin(id: string): Promise<void>;
1210
+ incrementFailedAttempts(id: string): Promise<number>;
1211
+ resetFailedAttempts(id: string): Promise<void>;
1212
+ setLockout(id: string, until: string): Promise<void>;
1213
+ assignRole(id: string, roleId?: string, roleName?: string): Promise<SanitizedUser>;
1214
+ removeRole(id: string): Promise<SanitizedUser>;
1215
+ seedAdminUser(config?: {
1216
+ email?: string;
1217
+ password?: string;
1218
+ name?: string;
1219
+ }): Promise<SanitizedUser>;
1220
+ updateLang(language: string): Promise<string>;
1221
+ getLang(): Promise<string>;
1222
+ }
1223
+
1045
1224
  declare class CredentialSetupRequirementRepository {
1046
1225
  private db;
1047
1226
  private schema;
@@ -1059,17 +1238,18 @@ declare class TokenService {
1059
1238
  private cookieManager;
1060
1239
  private cache;
1061
1240
  private credentialSetupRequirements?;
1241
+ private sessions?;
1062
1242
  private config;
1063
1243
  private t;
1064
- constructor(tokenRepository: TokenRepository, cookieManager: CookieManager, cache: CacheService, credentialSetupRequirements?: CredentialSetupRequirementRepository);
1244
+ constructor(tokenRepository: TokenRepository, cookieManager: CookieManager, cache: CacheService, credentialSetupRequirements?: CredentialSetupRequirementRepository, sessions?: SessionInvalidationService);
1245
+ /** The shared invalidation contract — see SessionInvalidationService. */
1246
+ private get invalidation();
1065
1247
  /**
1066
1248
  * Get blacklist key prefix
1067
1249
  */
1068
1250
  private get blacklistPrefix();
1069
1251
  private get resetTokenPrefix();
1070
- private get sessionVersionPrefix();
1071
1252
  private sessionVersionKey;
1072
- private accessTokenTtlMs;
1073
1253
  private expiresAt;
1074
1254
  private getCacheValues;
1075
1255
  private parseSessionVersion;
@@ -1086,6 +1266,7 @@ declare class TokenService {
1086
1266
  private static readonly PREVIOUS_GRACE_SECONDS;
1087
1267
  private clearRefreshSessionCookies;
1088
1268
  private rejectRefreshSession;
1269
+ private assertRefreshFamilyAllowed;
1089
1270
  private readRefreshSessionCookie;
1090
1271
  /**
1091
1272
  * Read the refresh cookie and return the userId it belongs to.
@@ -1112,8 +1293,20 @@ declare class TokenService {
1112
1293
  roles: any[];
1113
1294
  permissions: any;
1114
1295
  sessionVersion: number;
1296
+ tokenFamily: string;
1115
1297
  }>;
1116
1298
  getUser(auth: string): Promise<any>;
1299
+ /**
1300
+ * A user record is only an authorization if the account is still usable.
1301
+ *
1302
+ * A valid signature and an unrevoked version say the *token* is intact; they
1303
+ * say nothing about whether the account behind it was since deactivated or
1304
+ * deleted. Session invalidation is what normally ends such a token, but this
1305
+ * check is what makes a truthy cached record insufficient on its own — so a
1306
+ * missed invalidation, or a record filled into cache moments before the
1307
+ * change, still cannot authorize a request.
1308
+ */
1309
+ private requireActiveUser;
1117
1310
  getUserById(userId: string): Promise<any>;
1118
1311
  private hashToken;
1119
1312
  getTokenExpire(token: string): number | undefined;
@@ -1125,9 +1318,22 @@ declare class TokenService {
1125
1318
  * session was invalidated after it was written.
1126
1319
  */
1127
1320
  getSessionVersion(userId: string): Promise<number>;
1321
+ /**
1322
+ * Whether one session family is positively known to be live.
1323
+ *
1324
+ * `false` means "not proven live" — logged out, or simply not in cache — and
1325
+ * is a reason to fall back to an authoritative check, never on its own a
1326
+ * reason to treat a session as valid.
1327
+ */
1328
+ isSessionFamilyLive(tokenFamily: string | undefined, userId?: string): Promise<boolean>;
1128
1329
  /**
1129
1330
  * Generate access token with unique jti for blacklist support.
1130
1331
  * Includes roles/permissions for client-side RBAC/PBAC.
1332
+ *
1333
+ * The token only verifies while its `tokenFamily` is a live session — see
1334
+ * verifyAccessToken. A token minted without one, or for a family that has
1335
+ * been revoked, is refused by design rather than trusted on its signature.
1336
+ * Use generateTokens() to establish a family.
1131
1337
  */
1132
1338
  generateAccessToken(data: {
1133
1339
  userId: string;
@@ -1202,30 +1408,24 @@ declare class TokenService {
1202
1408
  revokeFamily(tokenFamily: string): Promise<any>;
1203
1409
  /**
1204
1410
  * Opportunistic cleanup of expired/abandoned sessions. With one row per
1205
- * family (no unique userId), abandoned logins would otherwise accumulate.
1411
+ * family (no unique userId), expired live rows and revocation tombstones
1412
+ * would otherwise accumulate.
1206
1413
  * Best-effort — never let cleanup failure break the calling flow.
1207
1414
  */
1208
1415
  deleteExpiredSessions(): Promise<void>;
1209
1416
  invalidateUserAccessTokens(userId: string): Promise<number>;
1210
1417
  getUserFromCookie(): Promise<any>;
1211
- private get revokedFamilyPrefix();
1212
1418
  private revokedFamilyKey;
1213
- /**
1214
- * Mark a family as revoked in cache for the access-token TTL, so every
1215
- * access token minted for that family (not just the presented one) is
1216
- * rejected by verifyAccessToken until it would have expired anyway.
1217
- */
1218
- private markFamilyRevoked;
1219
1419
  /**
1220
1420
  * Revoke only the suspect family — NOT the whole user. Bumping the global
1221
1421
  * per-user session version here would kill every device's access tokens on a
1222
- * single family's reuse detection. Instead drop the family's refresh row and
1223
- * mark the family revoked so its access tokens stop verifying.
1422
+ * single family's reuse detection. Instead durably mark the family revoked
1423
+ * so database recovery and its access tokens both stop verifying.
1224
1424
  */
1225
1425
  private revokeSuspectRefreshFamily;
1226
1426
  /**
1227
1427
  * Logout the CURRENT session only — blacklist the presented access token,
1228
- * mark its family revoked, and delete that family's refresh row. Other
1428
+ * mark its family revoked in cache and durably in the token row. Other
1229
1429
  * devices/sessions for the same user keep working. Use a password change or
1230
1430
  * reset (revoke-all) to terminate every session.
1231
1431
  *
@@ -1265,8 +1465,20 @@ declare class TokenService {
1265
1465
  userId: string;
1266
1466
  }>;
1267
1467
  /**
1268
- * Verify password reset token
1269
- * Returns userId if valid, throws error if expired/invalid
1468
+ * Verify and CONSUME a password reset or invite token.
1469
+ *
1470
+ * Consumption is a single atomic compare-and-delete, so exactly one of any
1471
+ * number of concurrent callers holding the same link is told to proceed. The
1472
+ * earlier `get()` then `del()` pair left a window in which two callers both
1473
+ * read the same jti, both passed, and both went on to set a password.
1474
+ *
1475
+ * The comparison also means a stale token cannot delete the jti of a newer
1476
+ * one that superseded it — the newer link keeps working.
1477
+ *
1478
+ * Callers must finish validating the replacement password BEFORE calling
1479
+ * this: consumption is deliberately irreversible, so a token burned by a
1480
+ * request that then failed validation would cost the user their link for
1481
+ * nothing.
1270
1482
  */
1271
1483
  verifyResetToken(token: string): Promise<string>;
1272
1484
  private getUserSessionVersion;
@@ -1665,14 +1877,18 @@ declare class AuthService {
1665
1877
  }
1666
1878
 
1667
1879
  /**
1668
- * Composite key: resolved client address + hashed normalized identity.
1669
- * Buckets rate limits per client+credential combo so different users
1670
- * on the same address (e.g. localhost, NAT) don't share a single bucket.
1671
- *
1672
- * The address arrives already resolved through the configured trusted-proxy
1673
- * boundary; this module must never parse forwarding headers itself.
1880
+ * Login's bucket. `loginDto` accepts either field, and the service reads
1881
+ * `identifier` first, so the key follows the same order.
1674
1882
  */
1675
1883
  declare const authIdentityRateLimitKey: (ctx: Context, keyContext?: RateLimitKeyContext) => Promise<string>;
1884
+ /**
1885
+ * Bucket for routes whose DTO declares `email` and nothing else — password
1886
+ * reset requests and public registration. Deliberately does NOT fall back to
1887
+ * `identifier`: that field is discarded by validation, so honouring it would
1888
+ * hand a caller a fresh allowance per invented value while every request still
1889
+ * targeted the one email the handler reads.
1890
+ */
1891
+ declare const authEmailRateLimitKey: (ctx: Context, keyContext?: RateLimitKeyContext) => Promise<string>;
1676
1892
  declare class AuthController {
1677
1893
  private authService;
1678
1894
  constructor(authService: AuthService);
@@ -1741,6 +1957,14 @@ declare class AuthController {
1741
1957
  }
1742
1958
 
1743
1959
  declare class AuthGuard {
1960
+ /**
1961
+ * A resolved principal is not automatically an authorized one.
1962
+ *
1963
+ * The resolvers ahead of this guard already reject deactivated accounts, so
1964
+ * this is the backstop for anything that publishes a principal by another
1965
+ * route: a truthy user record must still be an active one to pass. Records
1966
+ * whose projection omits `status` are unchanged.
1967
+ */
1744
1968
  canActivate(user: any): boolean;
1745
1969
  }
1746
1970
  declare const isAuth: () => ClassDecorator & MethodDecorator;
@@ -2065,7 +2289,18 @@ declare class PermissionService {
2065
2289
  private permissionRepository;
2066
2290
  private permissionValidator;
2067
2291
  private roleService;
2068
- constructor(permissionRepository: PermissionRepository, permissionValidator: PermissionValidator, roleService: RoleService);
2292
+ private userRepository?;
2293
+ private sessionInvalidation?;
2294
+ constructor(permissionRepository: PermissionRepository, permissionValidator: PermissionValidator, roleService: RoleService, userRepository?: UserRepository, sessionInvalidation?: SessionInvalidationService);
2295
+ /**
2296
+ * End the sessions of everyone holding a role whose permission set changed.
2297
+ *
2298
+ * Access tokens and signed session snapshots both carry permissions as
2299
+ * claims, so a permission removed from a role stays exercisable until the
2300
+ * sessions that captured it end. This is an infrequent administrative
2301
+ * action, and the work is proportional to the role's membership.
2302
+ */
2303
+ private invalidateRoleHolders;
2069
2304
  getAll(): Promise<{
2070
2305
  id: string;
2071
2306
  name: string;
@@ -2802,4 +3037,4 @@ declare const authSeed: (config: AuthSeedConfig) => Record<string, SeedEntry>;
2802
3037
  */
2803
3038
  declare function seedAuthData(config: SeedAuthDataConfig): Promise<SeedAuthDataResult>;
2804
3039
 
2805
- export { AUTH_CONFIG, AUTH_CORE_MODULE, en as AUTH_EN, AUTH_LOCALES, AUTH_LOGIN_RATE_LIMIT_ENV, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthLoginRateLimitConfig, type AuthPluginConfig, AuthQueries, type AuthRateLimitEnvironment, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, AuthSessionService, type AuthUser, CREDENTIAL_SETUP_CODES, CREDENTIAL_SETUP_MODULE, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type CredentialSetupChangeDto, type CredentialSetupCode, type CredentialSetupConfig, CredentialSetupController, type CredentialSetupOptions, type CredentialSetupPasswordOptions, type CredentialSetupPending, CredentialSetupRepository, CredentialSetupRequirementRepository, type CredentialSetupRequirementRow, CredentialSetupRequirementService, CredentialSetupService, type CredentialSetupSessionInfo, type CredentialSetupStarted, DEFAULT_AUTH_LOGIN_RATE_LIMIT, DEFAULT_CREDENTIAL_SETUP_COOKIE_NAME, DEFAULT_CREDENTIAL_SETUP_TTL_MS, type DefineRolesOptions, type EmailParam, EncryptionService, type GoogleOAuthConfig, IdentityConfig, type IdentityResolver, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, type LoginResult, NewPermission, NewRoleEntity, NewUser, type OAuthConfig, type OAuthProvider, Owned, type OwnedMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, PASSWORD_SETUP_PURPOSE, PUBLIC_REGISTRATION_MODULE, PasswordSetupService, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, type ProvisionUserWithPasswordInput, type ProvisionUserWithSetupInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type RegisterDto, RegistrationController, type ResetPasswordDto, type ResolvedCredentialSetupConfig, ResolvedIdentityConfig, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, TOKEN_STATUS, TOKEN_TYPE, TemporaryCredentialInput, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authIdentityRateLimitKey, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createIdentityResolver, createPermissionDto, createRoleDto, createTokenDto, createUserDto, credentialSetupChangeDto, credentialSetupError, defaultCredentialSetupPasswordSchema, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmailIdentifier, isEmpty, isFile, isPath, join, languageParam, loginDto, normalizeAuthIdentifier, normalizeSetupPurpose, own, parseSchema, permissionIdParam, pickProps, refreshTokenDto, registerDto, resetPasswordDto, resolveAuthLoginRateLimitConfig, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };
3040
+ export { AUTH_CONFIG, AUTH_CORE_MODULE, en as AUTH_EN, AUTH_LOCALES, AUTH_LOGIN_RATE_LIMIT_ENV, AUTH_MODULE, AUTH_PERMISSIONS, AUTH_ROLE, AUTH_SCHEMA, AUTH_SUPPORTED_LANGUAGES, AUTH_USER, type AssignPermissionDto, type AssignRoleDto, type AssignRoleParams, type AuthConfig, AuthController, AuthGuard, type AuthLoginRateLimitConfig, type AuthPluginConfig, AuthQueries, type AuthRateLimitEnvironment, AuthResolver, type AuthSchema, type AuthSeedConfig, AuthService, AuthSessionService, type AuthUser, CREDENTIAL_SETUP_CODES, CREDENTIAL_SETUP_MODULE, Can, CanCreate, CanDelete, CanList, CanRead, CanUpdate, type ChainableGuard, type ChangePasswordDto, type CheckPermissionDto, type ConfiguredOwnership, type ConfirmResetPasswordDto, CookieManager, type CreatePermissionDto, type CreateRoleDto, type CreateTokenDto, type CreateUserDto, type CredentialSetupChangeDto, type CredentialSetupCode, type CredentialSetupConfig, CredentialSetupController, type CredentialSetupOptions, type CredentialSetupPasswordOptions, type CredentialSetupPending, CredentialSetupRepository, CredentialSetupRequirementRepository, type CredentialSetupRequirementRow, CredentialSetupRequirementService, CredentialSetupService, type CredentialSetupSessionInfo, type CredentialSetupStarted, DEFAULT_AUTH_LOGIN_RATE_LIMIT, DEFAULT_CREDENTIAL_SETUP_COOKIE_NAME, DEFAULT_CREDENTIAL_SETUP_TTL_MS, type DefineRolesOptions, type EmailParam, EncryptionService, type GitHubOAuthConfig, type GoogleOAuthConfig, IdentityConfig, type IdentityResolver, type InviteUserDto, type JwtConfig, type JwtPayload, type LanguageParam, type LoginDto, type LoginResult, NewPermission, NewRoleEntity, NewUser, type OAuthConfig, type OAuthProvider, Owned, type OwnedMethods, type OwnershipConfig, type OwnershipProvider, type OwnershipRule, OwnershipToken, type OwnershipTokenOptions, PASSWORD_SETUP_PURPOSE, PUBLIC_REGISTRATION_MODULE, PasswordSetupService, Permission, PermissionController, PermissionGuard, type PermissionIdParam, PermissionRepository, PermissionService, PermissionValidator, Policy, type ProvisionUserInput, type ProvisionUserWithPasswordInput, type ProvisionUserWithSetupInput, ROLES, ROLE_GROUPS, type RefreshTokenDto, type RegisterDto, RegistrationController, type ResetPasswordDto, type ResolvedCredentialSetupConfig, ResolvedIdentityConfig, type ResourceAccessor, type ResourceGuards, type ResourceGuardsOptions, type RevokeTokenDto, Role, RoleController, RoleEntity, RoleGuard, type RoleIdParam, type RoleInput, RolePermission, RoleRepository, RoleService, type RoleType, RoleValidator, type RunAsUser, type SanitizedUser, ScopeContext, type ScopeResult, type SeedAuthDataConfig, type SeedAuthDataResult, type SeedUserConfig, type SessionCookieData, SessionInvalidationService, TOKEN_STATUS, TOKEN_TYPE, TemporaryCredentialInput, type TokenIdParam, type TokenPair, TokenRepository, TokenService, USER_STATUS, type UpdatePermissionDto, type UpdateRoleDto, type UpdateTokenDto, type UpdateUserDto, User, UserController, type UserIdInParam, type UserIdParam, type UserListQuery, UserRepository, UserService, UserValidator, type UserWithPermissions, type VerifyTokenDto, assignPermissionDto, assignRoleDto, assignRoleParams, auth$1 as auth, authEmailRateLimitKey, authIdentityRateLimitKey, authSeed, avatarsPath, calculateAge, calculateYearsOfExperience, changePasswordDto, checkPermissionDto, clean, configureOwnership, confirmResetPasswordDto, createIdentityResolver, createPermissionDto, createRoleDto, createTokenDto, createUserDto, credentialSetupChangeDto, credentialSetupError, defaultCredentialSetupPasswordSchema, defineRoles, emailParam, formatDate, getAuthLocale, getAvatarFile, inviteUserDto, isAdmin, isAdministrator, isAuth, isEmailIdentifier, isEmpty, isFile, isPath, join, languageParam, loginDto, normalizeAuthIdentifier, normalizeSetupPurpose, own, parseSchema, permissionIdParam, pickProps, refreshTokenDto, registerDto, resetPasswordDto, resolveAuthLoginRateLimitConfig, revokeTokenDto, roleIdParam, runAsUser, seedAuthData, tokenIdParam, updatePermissionDto, updateRoleDto, updateTokenDto, updateUserDto, userIdInParam, userIdParam, userListQuery, verifyTokenDto, where };