@happyvertical/smrt-users 0.57.17 → 0.57.18
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.
- package/AGENTS.md +21 -0
- package/README.md +134 -4
- package/agents/retention.md +3 -2
- package/dist/chunks/{PasswordCredentialService-CyB9FmYp.js → PasswordCredentialService-DezdsV_v.js} +40 -3
- package/dist/chunks/PasswordCredentialService-DezdsV_v.js.map +1 -0
- package/dist/chunks/TerminalAuthService-Dn2BIzRM.js +4012 -0
- package/dist/chunks/TerminalAuthService-Dn2BIzRM.js.map +1 -0
- package/dist/collections/PasskeyChallengeCollection.d.ts +37 -0
- package/dist/collections/PasskeyChallengeCollection.d.ts.map +1 -0
- package/dist/collections/PasskeyCredentialCollection.d.ts +66 -0
- package/dist/collections/PasskeyCredentialCollection.d.ts.map +1 -0
- package/dist/collections/SessionCollection.d.ts.map +1 -1
- package/dist/collections/index.d.ts +2 -0
- package/dist/collections/index.d.ts.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -6
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +1302 -428
- package/dist/models/PasskeyChallenge.d.ts +32 -0
- package/dist/models/PasskeyChallenge.d.ts.map +1 -0
- package/dist/models/PasskeyCredential.d.ts +50 -0
- package/dist/models/PasskeyCredential.d.ts.map +1 -0
- package/dist/models/Session.d.ts +23 -0
- package/dist/models/Session.d.ts.map +1 -1
- package/dist/models/index.d.ts +2 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/operator.js +1 -1
- package/dist/retention.d.ts +3 -1
- package/dist/retention.d.ts.map +1 -1
- package/dist/services/PasskeyCredentialService.d.ts +382 -0
- package/dist/services/PasskeyCredentialService.d.ts.map +1 -0
- package/dist/services/SessionService.d.ts.map +1 -1
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +407 -9
- package/dist/svelte/auth.d.ts +9 -3
- package/dist/svelte/auth.d.ts.map +1 -1
- package/dist/svelte/index.d.ts +2 -0
- package/dist/svelte/index.d.ts.map +1 -1
- package/dist/svelte/index.js +1 -0
- package/dist/svelte/passkey.d.ts +58 -0
- package/dist/svelte/passkey.d.ts.map +1 -0
- package/dist/svelte/passkey.js +97 -0
- package/dist/sveltekit/index.d.ts +1 -0
- package/dist/sveltekit/index.d.ts.map +1 -1
- package/dist/sveltekit/passkey-handlers.d.ts +117 -0
- package/dist/sveltekit/passkey-handlers.d.ts.map +1 -0
- package/dist/sveltekit.js +259 -69
- package/dist/sveltekit.js.map +1 -1
- package/package.json +12 -10
- package/dist/chunks/PasswordCredentialService-CyB9FmYp.js.map +0 -1
- package/dist/chunks/TerminalAuthService-CCbM_G1V.js +0 -3012
- package/dist/chunks/TerminalAuthService-CCbM_G1V.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -15,6 +15,7 @@ are not prerequisites for unrelated user-package work.
|
|
|
15
15
|
| `src/services/TerminalAuthService.ts`, `src/services/LoginAttemptLimiter.ts`, `src/collections/LoginAttemptCollection.ts` | terminal approval concurrency, shared login budget and lockout (#3273), retry-safe database fixtures | [agents/terminal-auth-testing.md](agents/terminal-auth-testing.md) |
|
|
16
16
|
| `src/services/DeviceCredentialService.ts` | per-person PIN layered on a device session (#3276), verifier seam for other credential kinds | this file, "Security boundaries" |
|
|
17
17
|
| `src/services/PasswordCredentialService.ts`, `src/sveltekit/password-handlers.ts` | email + password sign-in and password lifecycle (#3274); shared scrypt in `credential-hash.ts` | this file, "Security boundaries"; README "Password sign-in" |
|
|
18
|
+
| `src/services/PasskeyCredentialService.ts`, `src/sveltekit/passkey-handlers.ts`, `src/svelte/passkey.ts` | passkey (WebAuthn) sign-in and passkey lifecycle (#3275); library does all verification | this file, "Security boundaries"; README "Passkey sign-in" |
|
|
18
19
|
| `src/retention.ts` | expired session/token/CLI-auth reaping and retention sweep wiring | [agents/retention.md](agents/retention.md) |
|
|
19
20
|
|
|
20
21
|
## Models and authority
|
|
@@ -122,6 +123,26 @@ are not prerequisites for unrelated user-package work.
|
|
|
122
123
|
session row (owner, first-class, no ceiling, listed non-password/pin
|
|
123
124
|
`authMethod`, fresh `outOfBandProofAt` stamp) and ends every session,
|
|
124
125
|
its own included. Never set that stamp from client input.
|
|
126
|
+
- `UsersPasskeyCredential` (many per person) and `UsersPasskeyChallenge` (consumed
|
|
127
|
+
challenge ledger) are sensitive with no generated surface;
|
|
128
|
+
`PasskeyCredentialService` and its handlers are the only paths. Verification is
|
|
129
|
+
`@simplewebauthn/server`, loaded on first use (its `reflect-metadata` polyfill is process-wide) and external in the build; never hand-roll COSE/CBOR. Sign-in reserves on
|
|
130
|
+
the submitted credential id before any work, requires user verification, checks
|
|
131
|
+
user handle and a strictly advancing counter (`reason: 'counter'`), mints, then
|
|
132
|
+
re-checks with a guarded counter UPDATE; a ceremony is an HMAC-signed
|
|
133
|
+
`ceremonyId` consumed into the unique ledger (replay = refuse; set
|
|
134
|
+
`challengeSecret` for multi-process). Unique arbiters are
|
|
135
|
+
`INSERT … ON CONFLICT DO NOTHING`, never a caught constraint error. Register and
|
|
136
|
+
self-remove need a session authenticated within `freshSessionSeconds`, decided
|
|
137
|
+
on the stored row (`Session.getAuthenticatedAt()`: server-set
|
|
138
|
+
`data.authenticatedAt`, which tenant-switch rotation carries forward, else
|
|
139
|
+
`created_at`; malformed fails closed; `setSessionData` refuses the key),
|
|
140
|
+
first-class, no ceiling, and its STORED `authMethod` in `freshAuthMethods` (default password/passkey/oidc/magic-link; never `terminal`, whose approval mints a fresh session for any holder of a stale one, nor `pin`); self list/rename also refuse a ceiling; `users.passkey.manage` follows the PIN's
|
|
141
|
+
single-tenant rule, and `removeAllPasskeys` is admin-only, never self. Sessions
|
|
142
|
+
end before and after every removal; `SESSION_DATA_KEYS.passkeyCredentialId` is
|
|
143
|
+
server-set (`setSessionData` refuses it). State-changing handlers require
|
|
144
|
+
`application/json` (415). Challenge rows are reaped only 10 minutes past expiry
|
|
145
|
+
(clock skew).
|
|
125
146
|
- A layered session whose tenant differs from its parent's never loads (null
|
|
126
147
|
is allowed: narrower). Limiter rows carry `retain_until`; retention must
|
|
127
148
|
not fall back to a process-wide horizon.
|
package/README.md
CHANGED
|
@@ -22,8 +22,10 @@ key revoke actions must verify the current account owns the selected record
|
|
|
22
22
|
before calling `SessionService.destroySession()` or the profile API-key
|
|
23
23
|
service. Passkey sign-in is deliberately hidden unless the host passes a
|
|
24
24
|
`passkeyCeremony` callback to `createUsersAuthAdapter()`. An endpoint alone
|
|
25
|
-
cannot enable it: the callback must perform the
|
|
26
|
-
|
|
25
|
+
cannot enable it: the callback must perform the WebAuthn browser ceremony and
|
|
26
|
+
delegate its verified result to an authorized server action. Build it with
|
|
27
|
+
`createPasskeySignInCeremony()` against the routes of
|
|
28
|
+
`createPasskeyCredentialHandlers()` (see "Passkey sign-in").
|
|
27
29
|
|
|
28
30
|
Auth components display safe, registered `users.auth.*` messages when an
|
|
29
31
|
adapter rejects; callback diagnostics are never rendered. Configure these
|
|
@@ -1098,7 +1100,131 @@ What the app must do:
|
|
|
1098
1100
|
`(await passwordAuth.service()).signIn({ … })` and set the cookie with the
|
|
1099
1101
|
returned `sessionId`; keep the session id out of page data.
|
|
1100
1102
|
|
|
1101
|
-
Passkeys/WebAuthn are a separate credential
|
|
1103
|
+
Passkeys/WebAuthn are a separate credential: see "Passkey sign-in" below.
|
|
1104
|
+
|
|
1105
|
+
### Passkey sign-in
|
|
1106
|
+
|
|
1107
|
+
`PasskeyCredentialService` (#3275) gives an app passkey (WebAuthn) sign-in for
|
|
1108
|
+
**existing, active** users, with no username typed: the authenticator offers
|
|
1109
|
+
its discoverable credential and the credential names the person. It never
|
|
1110
|
+
creates a user. Parsing and verification are `@simplewebauthn/server`; this
|
|
1111
|
+
package owns the ceremony state, the sign-in order and the authority rules.
|
|
1112
|
+
Passkeys live in their own sensitive objects, `UsersPasskeyCredential`
|
|
1113
|
+
(`users_passkey_credentials`, many per person) and `UsersPasskeyChallenge`
|
|
1114
|
+
(`users_passkey_challenges`, a replay ledger), with no generated
|
|
1115
|
+
REST/MCP/CLI surface and no change-feed entry. The service and handlers below
|
|
1116
|
+
are their only read and write paths. Sign-in mints a first-class session with
|
|
1117
|
+
`authMethod: 'passkey'`; tenant access still comes only from an active
|
|
1118
|
+
membership (explicit tenant, or `'unique-active-membership'`, exactly as for
|
|
1119
|
+
passwords).
|
|
1120
|
+
|
|
1121
|
+
#### Setup: `ORIGIN` and the relying party
|
|
1122
|
+
|
|
1123
|
+
Passkeys are bound to the relying party, so `relyingParty` is required and is
|
|
1124
|
+
validated at construction. `origin` is the exact origin(s) the browser runs on:
|
|
1125
|
+
an absolute `https:` URL with no path (`http:` only for `localhost`,
|
|
1126
|
+
`127.0.0.1`, `[::1]`). `rpId` defaults to the hostname of the first origin and
|
|
1127
|
+
must be that hostname or a parent domain of every origin. **Choose it once:**
|
|
1128
|
+
changing the RP id orphans every registered passkey.
|
|
1129
|
+
|
|
1130
|
+
```ts
|
|
1131
|
+
// src/lib/server/passkey-auth.ts
|
|
1132
|
+
import { createPasskeyCredentialHandlers } from '@happyvertical/smrt-users/sveltekit';
|
|
1133
|
+
|
|
1134
|
+
export const passkeyAuth = createPasskeyCredentialHandlers({
|
|
1135
|
+
db,
|
|
1136
|
+
relyingParty: { origin: ORIGIN, rpName: 'Teamworks' }, // ORIGIN = https://app.example.com
|
|
1137
|
+
challengeSecret: PASSKEY_CHALLENGE_SECRET, // >= 32 chars; REQUIRED with more than one process
|
|
1138
|
+
tenantId: () => SHOP_TENANT_ID, // value or (event) => …; omit for no tenant context
|
|
1139
|
+
cookieName: 'sid', // the same cookie createSessionHandler reads
|
|
1140
|
+
loginLimiter, // optional: share one limiter with password/PIN
|
|
1141
|
+
freshSessionSeconds: 15 * 60, // 60..3600, default 900
|
|
1142
|
+
maxPasskeysPerUser: 10, // 1..100, default 10
|
|
1143
|
+
});
|
|
1144
|
+
// POST /auth/passkey/options → passkeyAuth.authenticationOptions → { ceremonyId, options }
|
|
1145
|
+
// POST /auth/passkey/sign-in → passkeyAuth.signIn ({ ceremonyId, response })
|
|
1146
|
+
// POST /account/passkeys/options → passkeyAuth.registrationOptions → { ceremonyId, options }
|
|
1147
|
+
// GET /account/passkeys → passkeyAuth.list (?userId= for administrators)
|
|
1148
|
+
// POST /account/passkeys → passkeyAuth.register ({ ceremonyId, response, name? })
|
|
1149
|
+
// PATCH /account/passkeys → passkeyAuth.rename ({ passkeyId, name })
|
|
1150
|
+
// DELETE /account/passkeys → passkeyAuth.remove ({ passkeyId })
|
|
1151
|
+
// POST /admin/passkeys/remove-all → passkeyAuth.removeAll ({ userId })
|
|
1152
|
+
```
|
|
1153
|
+
|
|
1154
|
+
In the browser, `@happyvertical/smrt-users/svelte` provides
|
|
1155
|
+
`browserSupportsPasskeys()`, `createPasskeySignInCeremony()` (a
|
|
1156
|
+
`passkeyCeremony` for `createUsersAuthAdapter`, which reveals the sign-in
|
|
1157
|
+
button) and `registerPasskey({ name })`. A refused request throws a
|
|
1158
|
+
`PasskeyRequestError` carrying the server's `status` and `code`.
|
|
1159
|
+
|
|
1160
|
+
#### Ceremonies and replay
|
|
1161
|
+
|
|
1162
|
+
`beginAuthentication()` / `beginRegistration()` return an opaque `ceremonyId`:
|
|
1163
|
+
`base64url(payload).base64url(HMAC-SHA256(challengeSecret, payload))`, where
|
|
1164
|
+
the payload holds the purpose, a random 32-byte challenge, an expiry
|
|
1165
|
+
(`challengeTtlSeconds`, 1 to 600, default 300) and, for registration, the
|
|
1166
|
+
person plus the SHA-256 of the registering session id (never the raw id).
|
|
1167
|
+
Beginning writes nothing, so an unauthenticated request costs no storage.
|
|
1168
|
+
Finishing verifies the MAC in constant time, the purpose, the expiry and a
|
|
1169
|
+
4 KB bound, then **consumes** the challenge by inserting its hash into the
|
|
1170
|
+
unique ledger: a replay is a conflict and is refused. Without `challengeSecret`
|
|
1171
|
+
a random per-process secret is used, which only works while one process begins
|
|
1172
|
+
and finishes every ceremony.
|
|
1173
|
+
|
|
1174
|
+
#### Sign-in order and refusals
|
|
1175
|
+
|
|
1176
|
+
The submitted credential id is reserved against the shared
|
|
1177
|
+
`LoginAttemptLimiter` (kind `passkey`, source = client address) **before** any
|
|
1178
|
+
other work. Then: ceremony verified and consumed, credential loaded,
|
|
1179
|
+
assertion verified (origin, RP id, user verification **required**), user
|
|
1180
|
+
handle checked against the stored owner, signature counter checked (it must
|
|
1181
|
+
advance whenever either side is non-zero; a regression is refused and audited
|
|
1182
|
+
as `reason: 'counter'`), user active, membership. The session is minted and
|
|
1183
|
+
the credential re-checked with one guarded `UPDATE` of the counter, so a
|
|
1184
|
+
passkey removed (or used concurrently) mid-sign-in leaves no session. Every
|
|
1185
|
+
refusal other than a rate limit is one `PasskeyCredentialError` ("Invalid
|
|
1186
|
+
credentials."), HTTP 401 `invalid_credentials`; a rate limit is
|
|
1187
|
+
`LoginRateLimitError`, HTTP 429 with `Retry-After`.
|
|
1188
|
+
|
|
1189
|
+
#### Managing passkeys
|
|
1190
|
+
|
|
1191
|
+
- **Registering** (and a person removing their own) requires a session
|
|
1192
|
+
authenticated within `freshSessionSeconds` (tenant switching keeps the
|
|
1193
|
+
original time) by an interactive method in `freshAuthMethods` (default
|
|
1194
|
+
`password`, `passkey`, `oidc`, `magic-link`), all decided on the stored
|
|
1195
|
+
session row; layered/PIN sessions and sessions with a permission ceiling are
|
|
1196
|
+
refused. A `terminal` session never counts as fresh (nor does a null or
|
|
1197
|
+
unlisted method): approving a device code lets whoever holds any session,
|
|
1198
|
+
however stale, mint a brand new one, so its age proves nothing. `terminal`
|
|
1199
|
+
and `pin` are rejected in `freshAuthMethods` at construction. Listing and
|
|
1200
|
+
renaming one's own passkeys also refuse a permission ceiling. A stale session
|
|
1201
|
+
is `PasskeyReauthenticationRequiredError` (HTTP 401
|
|
1202
|
+
`reauthentication_required`): sign in again, then retry.
|
|
1203
|
+
- `listPasskeys` returns `{ id, name, createdAt, lastUsedAt, backedUp,
|
|
1204
|
+
deviceType, transports }`, never key material or credential ids.
|
|
1205
|
+
- `users.passkey.manage` lets an administrator list and remove the passkeys of
|
|
1206
|
+
people whose every active membership is in the administrator's own tenant
|
|
1207
|
+
(the same single-tenant rule as `users.password.manage`).
|
|
1208
|
+
- Removing a passkey ends sessions before **and** after the delete: the
|
|
1209
|
+
person's other passkey sessions (and the current one only if it was signed
|
|
1210
|
+
in with the removed passkey); an administrator's removal ends all of them.
|
|
1211
|
+
- Every management call writes a `managed` audit event (kind `passkey`; action,
|
|
1212
|
+
self, actor, revoked sessions; never key material).
|
|
1213
|
+
|
|
1214
|
+
#### Recovery when every passkey is lost
|
|
1215
|
+
|
|
1216
|
+
An administrator holding `users.passkey.manage` calls `removeAllPasskeys` for
|
|
1217
|
+
the person (never for themselves), which deletes all their passkeys and ends
|
|
1218
|
+
every passkey session. The person then signs in with another credential (a
|
|
1219
|
+
password or a magic link) and registers a new passkey from that fresh session.
|
|
1220
|
+
Keep at least one non-passkey path available for every person.
|
|
1221
|
+
|
|
1222
|
+
Run `smrt db:migrate` once for the two new tables, and sync the permission
|
|
1223
|
+
catalog so `users.passkey.manage` can be granted. The retention sweep reaps
|
|
1224
|
+
expired challenge rows (`users-passkey-challenges`), keeping each row for 10 minutes past its expiry
|
|
1225
|
+
so a process with a slow clock cannot replay it. Every state-changing passkey
|
|
1226
|
+
route requires `content-type: application/json` (415 otherwise). When
|
|
1227
|
+
`challengeSecret` is unset the service logs one warning at creation.
|
|
1102
1228
|
|
|
1103
1229
|
### Trusted deployment owner provisioning
|
|
1104
1230
|
|
|
@@ -1409,6 +1535,7 @@ TenantService supports three modes: `flexible` (no auto-create), `personal` (aut
|
|
|
1409
1535
|
| `UsersLoginAttempt`, `UsersLoginAuditEvent` | Hashed-key login budget rows and durable sign-in audit events (#3273). Closed generated surface. |
|
|
1410
1536
|
| `UsersPinCredential` | Per-person scrypt PIN hash for enrolled-device sign-in (#3276). Closed generated surface. |
|
|
1411
1537
|
| `UsersPasswordCredential` | Per-person scrypt password hash for email + password sign-in (#3274). Sensitive; closed generated surface. |
|
|
1538
|
+
| `UsersPasskeyCredential`, `UsersPasskeyChallenge` | Per-person WebAuthn passkeys (many per person) and the consumed-challenge replay ledger (#3275). Sensitive; closed generated surface. |
|
|
1412
1539
|
| `Group` | Team within a tenant. Gains permissions via GroupRole. |
|
|
1413
1540
|
| `Membership` | User + Tenant + Role junction. UNIQUE(userId, tenantId). |
|
|
1414
1541
|
| `MembershipOverride` | Per-user permission grant/deny on a membership. |
|
|
@@ -1484,7 +1611,7 @@ authority and effective dates, and no posting or balance is copied here.
|
|
|
1484
1611
|
| `MembershipOverrideCollection`, `TenantPermissionOverrideCollection` | Override management at membership and tenant levels |
|
|
1485
1612
|
| `GroupCollection`, `GroupMemberCollection`, `GroupRoleCollection`, `RolePermissionCollection` | Group and role-permission junction management |
|
|
1486
1613
|
| `AccessRequestCollection` | AccessRequest queries: `findByEmail()`, `findOpenByEmail()`, `findByStatus()`, `findOpen()` |
|
|
1487
|
-
| `UsersLoginAttemptCollection`, `UsersLoginAuditEventCollection`, `UsersPinCredentialCollection`, `UsersPasswordCredentialCollection` | Atomic limiter primitives, audit storage, and PIN and
|
|
1614
|
+
| `UsersLoginAttemptCollection`, `UsersLoginAuditEventCollection`, `UsersPinCredentialCollection`, `UsersPasswordCredentialCollection`, `UsersPasskeyCredentialCollection`, `UsersPasskeyChallengeCollection` | Atomic limiter primitives, audit storage, and PIN, password and passkey credential rows behind the services below |
|
|
1488
1615
|
|
|
1489
1616
|
### Services
|
|
1490
1617
|
|
|
@@ -1499,6 +1626,7 @@ authority and effective dates, and no posting or balance is copied here.
|
|
|
1499
1626
|
| `LoginAttemptLimiter` | Shared sign-in budget with exponential lockout and audit (#3273): `reserve()` → lease `.fail()`/`.succeed()`/`.release()`. `LoginRateLimitError`, `InvalidCredentialsError`, `LoginAuditSink`, `DurableLoginAuditSink`. |
|
|
1500
1627
|
| `DeviceCredentialService` | Per-person sign-in layered on an enrolled device session (#3276): `signInWithPin()`, `signIn(verifier, input)`, `signOut()`, `setPin()`, `resetPin()`, `clearPin()`. Person authority with optional `deviceCeiling`, `singleOccupant` hand-over, `personIdleSeconds` / `personMaxSeconds`. `PinVerifier`, `DeviceCredentialVerifier`. |
|
|
1501
1628
|
| `PasswordCredentialService` | Email + password sign-in for existing active users (#3274): `signIn()`, `setPassword()`, `changePassword()`, `resetPassword()`, `clearPassword()`, `hasPassword()`, `validatePassword()`. `PasswordCredentialError`, `PasswordCredentialForbiddenError`, `PasswordPolicyError`. |
|
|
1629
|
+
| `PasskeyCredentialService` | Passkey (WebAuthn) sign-in for existing active users (#3275): `beginAuthentication()`, `finishAuthentication()`, `beginRegistration()`, `finishRegistration()`, `listPasskeys()`, `renamePasskey()`, `removePasskey()`, `removeAllPasskeys()`, `hasPasskeys()`. `PasskeyCredentialError`, `PasskeyCredentialForbiddenError`, `PasskeyReauthenticationRequiredError`, `PasskeyRegistrationError`. |
|
|
1502
1630
|
| `OidcLoginService` | Generic OIDC authorization-code login with PKCE for Kanidm, Dex, and other standards-compliant providers. |
|
|
1503
1631
|
| `backfillLegacyUserProfiles` | Transactionally create and link canonical global Person Profiles for legacy Users; never creates OIDC identities or infers ownership. |
|
|
1504
1632
|
| `backfillUserEmailKeys` | Idempotently populate durable normalized-email keys after migrating legacy Users; fails closed on duplicates. |
|
|
@@ -1526,6 +1654,7 @@ authority and effective dates, and no posting or balance is copied here.
|
|
|
1526
1654
|
| `createMobileAuthHandlers` | Mountable `/api/mobile` PKCE, bearer session, bootstrap, logout, and route-guard handlers |
|
|
1527
1655
|
| `createDeviceCredentialHandlers` | Mountable PIN sign-in, sign-out, and PIN management handlers for enrolled devices |
|
|
1528
1656
|
| `createPasswordCredentialHandlers` | Mountable password sign-in (sets the session cookie) and password set/change/reset/clear handlers |
|
|
1657
|
+
| `createPasskeyCredentialHandlers` | Mountable passkey sign-in (sets the session cookie), registration, list, rename and remove handlers |
|
|
1529
1658
|
| `resolveMobileUploadDedupKey` | Resolves `clientCaptureId` with `Idempotency-Key` fallback for app-owned multipart routes |
|
|
1530
1659
|
| `SessionLocals` | Type for `event.locals` (extend in `app.d.ts`) |
|
|
1531
1660
|
|
|
@@ -1549,6 +1678,7 @@ for authentication, deduplication, and status semantics.
|
|
|
1549
1678
|
| `DEFAULT_LOGIN_MAX_ATTEMPTS`, `DEFAULT_LOGIN_ATTEMPT_WINDOW_SECONDS`, `DEFAULT_LOGIN_LOCKOUT_*` | 5 attempts per 300 s window; lockout 60 s × 2ⁿ, capped at 3600 s |
|
|
1550
1679
|
| `DEFAULT_PIN_MANAGE_PERMISSION`, `PIN_LOGIN_KIND` | `users.pin.manage`, `pin` |
|
|
1551
1680
|
| `DEFAULT_PASSWORD_MANAGE_PERMISSION`, `PASSWORD_LOGIN_KIND` | `users.password.manage`, `password` |
|
|
1681
|
+
| `DEFAULT_PASSKEY_MANAGE_PERMISSION`, `PASSKEY_LOGIN_KIND`, `PASSKEY_SESSION_DATA_KEY` | `users.passkey.manage`, `passkey`, `passkeyCredentialId` |
|
|
1552
1682
|
| `DEFAULT_PASSWORD_MIN_LENGTH`, `DEFAULT_PASSWORD_MAX_LENGTH`, `PASSWORD_MAX_LENGTH_CEILING`, `DEFAULT_PASSWORD_DENYLIST` | 10, 256, 1024, built-in common-password list |
|
|
1553
1683
|
| `TenantHierarchyError` | Thrown on a missing parent, a cycle, or exceeding the hierarchy depth limit (`code`) |
|
|
1554
1684
|
| `TenantHierarchyMaterializationError` | Thrown by `materializeTenantHierarchy` when any tenant's parent chain is broken; lists `problems` |
|
package/agents/retention.md
CHANGED
|
@@ -24,8 +24,9 @@ reap them.
|
|
|
24
24
|
optionally for exactly that reason. Registering is not scheduling: nothing is
|
|
25
25
|
deleted until something runs a sweep.
|
|
26
26
|
- **Task names** are `users-sessions`, `users-magic-link-tokens`,
|
|
27
|
-
`users-cli-auth-requests`, `users-login-attempts`, `users-login-audit-events
|
|
28
|
-
|
|
27
|
+
`users-cli-auth-requests`, `users-login-attempts`, `users-login-audit-events`,
|
|
28
|
+
`users-passkey-challenges` (consumed passkey ceremony challenges past their
|
|
29
|
+
expiry, #3275) — prefixed with the package's short name because the retention registry is
|
|
29
30
|
one process-global namespace. Opt one out with
|
|
30
31
|
`runRetentionSweep(db, { tasks: { 'users-sessions': false } })` or
|
|
31
32
|
`smrt db:prune --skip users-sessions`; `unregisterUserRetentionTasks()`
|
package/dist/chunks/{PasswordCredentialService-CyB9FmYp.js → PasswordCredentialService-DezdsV_v.js}
RENAMED
|
@@ -261,7 +261,23 @@ var SESSION_DATA_KEYS = {
|
|
|
261
261
|
* from, and it survives tenant-switch rotation (unlike the row's
|
|
262
262
|
* `created_at`).
|
|
263
263
|
*/
|
|
264
|
-
outOfBandProofAt: "outOfBandProofAt"
|
|
264
|
+
outOfBandProofAt: "outOfBandProofAt",
|
|
265
|
+
/**
|
|
266
|
+
* ISO timestamp of the original authentication, carried forward when
|
|
267
|
+
* tenant-switch rotation mints a replacement row (whose own `created_at`
|
|
268
|
+
* is new). Written only by `SessionService.switchTenant`; never from client
|
|
269
|
+
* input, and `setSessionData` refuses it. Absent on a session that has not
|
|
270
|
+
* rotated, where `created_at` is the authentication time. See
|
|
271
|
+
* {@link Session.getAuthenticatedAt}.
|
|
272
|
+
*/
|
|
273
|
+
authenticatedAt: "authenticatedAt",
|
|
274
|
+
/**
|
|
275
|
+
* Row id of the passkey (`users_passkey_credentials`) a session was signed
|
|
276
|
+
* in with. Set only by `PasskeyCredentialService` at mint; it decides which
|
|
277
|
+
* session a passkey removal ends. Never from client input, and
|
|
278
|
+
* `setSessionData` refuses it.
|
|
279
|
+
*/
|
|
280
|
+
passkeyCredentialId: "passkeyCredentialId"
|
|
265
281
|
};
|
|
266
282
|
function resolveSessionExpiry(ttlSeconds, data) {
|
|
267
283
|
const next = Date.now() + ttlSeconds * 1e3;
|
|
@@ -320,6 +336,23 @@ var Session = class extends SmrtObject {
|
|
|
320
336
|
return typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : null;
|
|
321
337
|
}
|
|
322
338
|
/**
|
|
339
|
+
* When the person authenticated: `data.authenticatedAt` when present, else
|
|
340
|
+
* the row's `created_at`. A present but malformed or future stamp returns
|
|
341
|
+
* null, which callers must treat as "not fresh" (fail closed). Also null
|
|
342
|
+
* when there is no usable `created_at`.
|
|
343
|
+
*/
|
|
344
|
+
getAuthenticatedAt() {
|
|
345
|
+
const raw = this.data?.[SESSION_DATA_KEYS.authenticatedAt];
|
|
346
|
+
if (raw !== void 0 && raw !== null) {
|
|
347
|
+
const at = typeof raw === "string" ? new Date(raw) : null;
|
|
348
|
+
if (!at || Number.isNaN(at.getTime())) return null;
|
|
349
|
+
if (at.getTime() > Date.now() + 3e4) return null;
|
|
350
|
+
return at;
|
|
351
|
+
}
|
|
352
|
+
const created = this.created_at;
|
|
353
|
+
return created instanceof Date && !Number.isNaN(created.getTime()) ? created : null;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
323
356
|
* Permission ceiling (`data.permissionCeiling`), or null when the session
|
|
324
357
|
* has none. A present but malformed value fails closed as an empty ceiling.
|
|
325
358
|
*/
|
|
@@ -784,6 +817,7 @@ var SessionCollection = class extends SmrtCollection {
|
|
|
784
817
|
* Set custom session data
|
|
785
818
|
*/
|
|
786
819
|
async setSessionData(sessionId, key, value) {
|
|
820
|
+
if (key === SESSION_DATA_KEYS.authenticatedAt || key === SESSION_DATA_KEYS.passkeyCredentialId) return false;
|
|
787
821
|
const session = await this.findValidSession(sessionId);
|
|
788
822
|
if (!session) return false;
|
|
789
823
|
session.setData(key, value);
|
|
@@ -5434,7 +5468,10 @@ var SessionService = class SessionService {
|
|
|
5434
5468
|
ttl: session.getIdleSeconds() ?? this.defaultTTL,
|
|
5435
5469
|
userAgent: session.userAgent,
|
|
5436
5470
|
ipAddress: session.ipAddress,
|
|
5437
|
-
data:
|
|
5471
|
+
data: {
|
|
5472
|
+
...session.data,
|
|
5473
|
+
[SESSION_DATA_KEYS.authenticatedAt]: session.data?.[SESSION_DATA_KEYS.authenticatedAt] ?? (session.created_at instanceof Date ? session.created_at.toISOString() : (/* @__PURE__ */ new Date(0)).toISOString())
|
|
5474
|
+
},
|
|
5438
5475
|
authMethod: session.authMethod,
|
|
5439
5476
|
parentSessionId: session.parentSessionId
|
|
5440
5477
|
});
|
|
@@ -6089,4 +6126,4 @@ var PasswordCredentialService = class PasswordCredentialService {
|
|
|
6089
6126
|
//#endregion
|
|
6090
6127
|
export { PermissionCatalogService as $, InvalidCredentialsError as A, Session as At, backfillUserEmailKeys as B, DEFAULT_LOGIN_ATTEMPT_WINDOW_SECONDS as C, SessionCollection as Ct, DEFAULT_LOGIN_MAX_ATTEMPTS as D, normalizeUsername as Dt, DEFAULT_LOGIN_LOCKOUT_MAX_SECONDS as E, normalizeEmail as Et, withoutListBounds as F, __exportAll as Ft, MAX_TENANT_HIERARCHY_DEPTH as G, TenantPermissionOverride as H, OidcProvisioningError as I, assertTenantTableName as J, TenantHierarchyError as K, UserCollection as L, LoginRateLimitError as M, Role as Mt, hashSecret as N, Permission as Nt, DEFAULT_SOURCE_LOCKOUT_AUDIT_SECONDS as O, DEFAULT_SESSION_TTL as Ot, verifySecretHash as P, Membership as Pt, RolePermissionCollection as Q, USER_EMAIL_KEY_BACKFILL_NAME as R, normalizeAncestorReadPolicy as S, UsersLoginAttempt as St, DEFAULT_LOGIN_LOCKOUT_FACTOR as T, isValidEmail as Tt, TenantCollection as U, TenantPermissionOverrideCollection as V, Tenant as W, recordTenantHierarchyChanges as X, planTenantHierarchy as Y, DEFAULT_ROLE_PERMISSION_PATTERNS as Z, PermissionResolver as _, GroupCollection as _t, DEFAULT_PASSWORD_RECOVERY_MAX_AGE_SECONDS as a, RolePermission as at, getConfiguredAncestorReadPolicy as b, UsersLoginAuditEvent as bt, PASSWORD_PERMISSION_DEFINITIONS as c, UsersPasswordCredentialCollection as ct, PasswordCredentialForbiddenError as d, MembershipOverride as dt, deriveOperationPermissionCollectionName as et, PasswordCredentialService as f, MembershipCollection as ft, SessionService as g, GroupMember as gt, outOfBandProofSessionData as h, GroupMemberCollection as ht, DEFAULT_PASSWORD_MIN_LENGTH as i, syncPermissionCatalog as it, LoginAttemptLimiter as j, generateSessionId as jt, DurableLoginAuditSink as k, SESSION_DATA_KEYS as kt, PASSWORD_RECOVERY_MAX_AGE_CEILING_SECONDS as l, UsersPasswordCredential as lt, ensurePasswordPermissionsRegistered as m, GroupRole as mt, DEFAULT_PASSWORD_MANAGE_PERMISSION as n, normalizeOperationPermissionAction as nt, PASSWORD_LOGIN_KIND as o, RoleCollection as ot, PasswordPolicyError as p, GroupRoleCollection as pt, applyTenantHierarchyUpdates as q, DEFAULT_PASSWORD_MAX_LENGTH as r, registerPermissionDefinitions as rt, PASSWORD_MAX_LENGTH_CEILING as s, PermissionCollection as st, DEFAULT_PASSWORD_DENYLIST as t, deriveOperationPermissionSlug as tt, PasswordCredentialError as u, MembershipOverrideCollection as ut, ANCESTOR_READ_ACTION as v, Group as vt, DEFAULT_LOGIN_LOCKOUT_BASE_SECONDS as w, User as wt, isAncestorReadableSlug as x, UsersLoginAttemptCollection as xt, DEFAULT_ANCESTOR_READ_MAX_DEPTH as y, UsersLoginAuditEventCollection as yt, UserEmailKeyBackfillError as z };
|
|
6091
6128
|
|
|
6092
|
-
//# sourceMappingURL=PasswordCredentialService-
|
|
6129
|
+
//# sourceMappingURL=PasswordCredentialService-DezdsV_v.js.map
|