@happyvertical/smrt-users 0.60.14 → 0.60.16
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 +28 -0
- package/README.md +66 -0
- package/agents/permissions.md +18 -0
- package/dist/chunks/{PasswordCredentialService-BSSP_kyT.js → PasswordCredentialService-D_evcc-I.js} +144 -17
- package/dist/chunks/PasswordCredentialService-D_evcc-I.js.map +1 -0
- package/dist/chunks/{TerminalAuthService-BGeqNZU_.js → TerminalAuthService-CKw_Aoy1.js} +133 -8
- package/dist/chunks/TerminalAuthService-CKw_Aoy1.js.map +1 -0
- package/dist/chunks/permission-registry-PhcdZvKe.js +19 -0
- package/dist/chunks/permission-registry-PhcdZvKe.js.map +1 -0
- package/dist/collections/SessionCollection.d.ts +30 -0
- package/dist/collections/SessionCollection.d.ts.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +111 -11
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +89 -1
- package/dist/models/Session.d.ts +45 -0
- package/dist/models/Session.d.ts.map +1 -1
- package/dist/models/index.d.ts +1 -1
- package/dist/models/index.d.ts.map +1 -1
- package/dist/operator.js +1 -1
- package/dist/permission-registry-state.d.ts +8 -0
- package/dist/permission-registry-state.d.ts.map +1 -0
- package/dist/permission-registry.d.ts +24 -0
- package/dist/permission-registry.d.ts.map +1 -0
- package/dist/permission-registry.js +2 -0
- package/dist/services/MagicLinkService.d.ts +55 -0
- package/dist/services/MagicLinkService.d.ts.map +1 -1
- package/dist/services/OidcLoginService.d.ts +63 -0
- package/dist/services/OidcLoginService.d.ts.map +1 -1
- package/dist/services/PasswordCredentialService.d.ts +23 -0
- package/dist/services/PasswordCredentialService.d.ts.map +1 -1
- package/dist/services/PermissionCatalogService.d.ts +2 -27
- package/dist/services/PermissionCatalogService.d.ts.map +1 -1
- package/dist/services/SessionService.d.ts +8 -0
- package/dist/services/SessionService.d.ts.map +1 -1
- package/dist/services/index.d.ts +3 -3
- package/dist/services/index.d.ts.map +1 -1
- package/dist/smrt-knowledge.json +85 -7
- package/dist/smrt-knowledge.okf.md +4 -2
- package/dist/step-up.d.ts +57 -0
- package/dist/step-up.d.ts.map +1 -0
- package/dist/step-up.js +36 -0
- package/dist/step-up.js.map +1 -0
- package/dist/sveltekit.js +2 -2
- package/package.json +20 -12
- package/dist/chunks/PasswordCredentialService-BSSP_kyT.js.map +0 -1
- package/dist/chunks/TerminalAuthService-BGeqNZU_.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -9,6 +9,7 @@ are not prerequisites for unrelated user-package work.
|
|
|
9
9
|
|
|
10
10
|
| Module | Scope | Module doc |
|
|
11
11
|
|---|---|---|
|
|
12
|
+
| `src/permission-registry.ts` | portable permission metadata registration; same root/service singleton, no authority grants | [agents/permissions.md](agents/permissions.md#portable-metadata-registry-4765) |
|
|
12
13
|
| `src/services/PermissionResolver.ts` | permission precedence, inherited memberships, guards, RLS, role seeding | [agents/permissions.md](agents/permissions.md) |
|
|
13
14
|
| `src/services/OidcLoginService.ts`, collections and OIDC handlers | identity reconciliation, transaction boundaries, migration readiness | [agents/oidc-provisioning.md](agents/oidc-provisioning.md) |
|
|
14
15
|
| `src/services/MobileAuthService.ts` | mobile handshake, bearer sessions, bootstrap extension boundary | [agents/mobile-auth.md](agents/mobile-auth.md) |
|
|
@@ -144,6 +145,33 @@ are not prerequisites for unrelated user-package work.
|
|
|
144
145
|
server-set (`setSessionData` refuses it). State-changing handlers require
|
|
145
146
|
`application/json` (415). Challenge rows are reaped only 10 minutes past expiry
|
|
146
147
|
(clock skew).
|
|
148
|
+
- Step-up (#4841, `src/step-up.ts`, subpath `./step-up`): `requireRecentAuthentication`
|
|
149
|
+
decides on `SessionContext.reauthenticatedAt`, derived from the stored row:
|
|
150
|
+
`data.reauthenticatedAt` (server-set through `SessionCollection.markReauthenticated`
|
|
151
|
+
only after a deliberate fresh authentication; `setSessionData` refuses it;
|
|
152
|
+
extend/activity never move it) or the sign-in time of a password or passkey
|
|
153
|
+
session only (`STEP_UP_SIGN_IN_AUTH_METHODS` = `password`, `passkey`; an OIDC
|
|
154
|
+
or magic-link SIGN-IN, `terminal`, `pin`, `mobile` never count: an unlocked
|
|
155
|
+
stolen device can complete them without the person). Rule: an EXISTING
|
|
156
|
+
session never counts as fresh by itself; a DELIBERATE fresh authentication
|
|
157
|
+
with any supported method does, so an OIDC-only or magic-link-only owner can
|
|
158
|
+
still step up. Methods, all stamping the EXISTING session (never minting one),
|
|
159
|
+
all refusing layered/PIN/ceilinged sessions (`Session.isStepUpEligible`):
|
|
160
|
+
`PasswordCredentialService.stepUp` (limiter-guarded password check);
|
|
161
|
+
`OidcLoginService.beginStepUp`/`completeStepUp` (authorization request with
|
|
162
|
+
`prompt=login` + `max_age=0`; the transaction is stored on the session as
|
|
163
|
+
`data.oidcStepUpIntent`, taken at the callback so it is single use; the ID
|
|
164
|
+
token must verify as at sign-in AND carry `auth_time` inside the window, not
|
|
165
|
+
before the intent started, not future; its issuer+subject must be an existing
|
|
166
|
+
`OidcIdentity` of the session user's own profile; a provider that omits
|
|
167
|
+
`auth_time` or ignores `prompt`/`max_age` is refused);
|
|
168
|
+
`MagicLinkService.requestStepUp`/`consumeStepUp` (token claim `purpose:
|
|
169
|
+
step_up` + session digest + user id, TTL <= 300 s, single use; `verify` and
|
|
170
|
+
`inspect` refuse it so it cannot sign in; `consumeStepUp` refuses a link
|
|
171
|
+
without that purpose). Every step-up refusal is one `StepUpRequiredError`
|
|
172
|
+
(`step_up_required`) that does not say which check failed. A passkey owner
|
|
173
|
+
re-authenticates with a fresh passkey sign-in. Keep the entry free of
|
|
174
|
+
side-effect imports.
|
|
147
175
|
- A layered session whose tenant differs from its parent's never loads (null
|
|
148
176
|
is allowed: narrower). Limiter rows carry `retain_until`; retention must
|
|
149
177
|
not fall back to a process-wide horizon.
|
package/README.md
CHANGED
|
@@ -1150,6 +1150,72 @@ What the app must do:
|
|
|
1150
1150
|
|
|
1151
1151
|
Passkeys/WebAuthn are a separate credential: see "Passkey sign-in" below.
|
|
1152
1152
|
|
|
1153
|
+
### Step-up (recent authentication) for sensitive actions
|
|
1154
|
+
|
|
1155
|
+
A signed-in session is not proof the person is at the keyboard now. For an
|
|
1156
|
+
action that must not ride on an old or unlocked session (replacing a vault
|
|
1157
|
+
account, #4841), require a recent authentication:
|
|
1158
|
+
|
|
1159
|
+
```ts
|
|
1160
|
+
import { requireRecentAuthentication } from '@happyvertical/smrt-users/step-up';
|
|
1161
|
+
|
|
1162
|
+
const ctx = await sessionService.loadSessionContext(sessionId);
|
|
1163
|
+
// throws StepUpRequiredError (code 'step_up_required') unless the person
|
|
1164
|
+
// proved a credential within the last 5 minutes (maxAgeSeconds, max 1 hour)
|
|
1165
|
+
requireRecentAuthentication(ctx, { maxAgeSeconds: 300 });
|
|
1166
|
+
```
|
|
1167
|
+
|
|
1168
|
+
- The proof is server-side session state. A password or passkey sign-in counts
|
|
1169
|
+
at mint; `oidc`, `magic-link`, `terminal`, `pin`, `mobile` and host-defined
|
|
1170
|
+
sessions do not (an OIDC login can complete silently from the provider's
|
|
1171
|
+
existing browser session, and a magic link from the device's own mail app,
|
|
1172
|
+
so an unlocked stolen device could mint either). `ctx.reauthenticatedAt` is
|
|
1173
|
+
derived from the stored row.
|
|
1174
|
+
- The rule: **an existing session never counts as fresh by itself; a
|
|
1175
|
+
deliberate fresh authentication with any supported method does.** Every
|
|
1176
|
+
method below stamps the EXISTING session (no new session, no user switch),
|
|
1177
|
+
refuses layered/PIN and ceilinged sessions, and answers every refusal with
|
|
1178
|
+
one error that does not say which check failed, so a person who signs in
|
|
1179
|
+
only with Google/OIDC or only by email link can still step up.
|
|
1180
|
+
- **Password**: the page asks for the password and the host calls
|
|
1181
|
+
`(await passwordAuth.service()).stepUp({ sessionId, password, ipAddress })`.
|
|
1182
|
+
It uses the sign-in limiter and constant-work verification; every refusal
|
|
1183
|
+
is one `PasswordCredentialError`.
|
|
1184
|
+
- **Passkey**: re-authenticate with a fresh passkey sign-in and use the new
|
|
1185
|
+
session; there is no separate passkey step-up ceremony.
|
|
1186
|
+
- **OIDC**: `const { url } = await oidc.beginStepUp({ sessionId })`, redirect
|
|
1187
|
+
the person to `url`, then on the callback
|
|
1188
|
+
`await oidc.completeStepUp({ sessionId, callbackUrl })`. The request sets
|
|
1189
|
+
`prompt=login` and `max_age=0`. The transaction (state, nonce, PKCE
|
|
1190
|
+
verifier) is held on the session server-side as its one pending intent
|
|
1191
|
+
(`data.oidcStepUpIntent`, one at a time, dies with the session); the
|
|
1192
|
+
callback takes it, so it works once. The ID token is verified as at
|
|
1193
|
+
sign-in, and must also carry `auth_time` that is within the step-up window
|
|
1194
|
+
(default 300 s, `stepUpWindowSeconds`), not before the intent started and
|
|
1195
|
+
not in the future. The returned issuer+subject must be an existing OIDC
|
|
1196
|
+
identity of the session's own user: it never creates a user or switches
|
|
1197
|
+
one. A provider that does not emit `auth_time`, or ignores
|
|
1198
|
+
`prompt`/`max_age`, is refused, so confirm yours returns `auth_time`. Use a
|
|
1199
|
+
`redirectUri` registered with the provider for step-up (it must not be
|
|
1200
|
+
handled as a sign-in callback). Refusals are `StepUpRequiredError`.
|
|
1201
|
+
- **Magic link**: `const { token, email } = await links.requestStepUp({
|
|
1202
|
+
sessionId })` issues a link of purpose `step_up`, bound to that session and
|
|
1203
|
+
its user, valid for at most 300 s and once; email it to `email` (the
|
|
1204
|
+
user's own address). When the person opens it, the host calls
|
|
1205
|
+
`await links.consumeStepUp({ token, sessionId })` with the SAME session
|
|
1206
|
+
cookie. A sign-in link cannot step up and a step-up link cannot sign in
|
|
1207
|
+
(`verify()`/`inspect()` refuse it); another session or user, an expired or
|
|
1208
|
+
reused link, or a changed account email are all `StepUpRequiredError`.
|
|
1209
|
+
- The stamp (`SESSION_DATA_KEYS.reauthenticatedAt`) is never client input
|
|
1210
|
+
(`setSessionData` refuses it), is not moved by refresh, activity or
|
|
1211
|
+
`extend()`, is carried unchanged across tenant-switch rotation, and dies
|
|
1212
|
+
with the session.
|
|
1213
|
+
- `isTenantOwnerSession(ctx)` is the matching owner test: a direct active
|
|
1214
|
+
`owner` membership on a first-class session (not a member, `terminal`/`pin`
|
|
1215
|
+
device, layered, ceilinged or inherited one).
|
|
1216
|
+
- The `@happyvertical/smrt-users/step-up` entry has no side effects and can be
|
|
1217
|
+
imported by packages that must not load the whole identity module.
|
|
1218
|
+
|
|
1153
1219
|
### Passkey sign-in
|
|
1154
1220
|
|
|
1155
1221
|
`PasskeyCredentialService` (#3275) gives an app passkey (WebAuthn) sign-in for
|
package/agents/permissions.md
CHANGED
|
@@ -212,3 +212,21 @@ collection's CRUD grants (#3878); `deriveOperationPermissionSlug()` resolves
|
|
|
212
212
|
them for class and catalog-slug callers. Catalog generation merges optional
|
|
213
213
|
`databaseActions` into the target grant's PostgreSQL bindings. CRUD grants
|
|
214
214
|
cannot themselves be aliased. See core's [generator contract](../../core/agents/generators.md#custom-action-permission-aliases-3878).
|
|
215
|
+
|
|
216
|
+
## Portable metadata registry (#4765)
|
|
217
|
+
|
|
218
|
+
Browser-safe packages import `registerPermissionDefinitions` and its existing
|
|
219
|
+
`PermissionDefinition` / PostgreSQL binding types from
|
|
220
|
+
`@happyvertical/smrt-users/permission-registry`. This entry imports only shared
|
|
221
|
+
metadata storage. It does not load Users models, catalog database sync, operator
|
|
222
|
+
services, PostgreSQL policy generation or Core filesystem discovery.
|
|
223
|
+
|
|
224
|
+
The old package-root and PermissionCatalogService exports re-export the exact
|
|
225
|
+
same function. Both paths share the existing process-global Map/counter; each
|
|
226
|
+
returned disposer removes only its own registration and may be called repeatedly.
|
|
227
|
+
Definitions retain their original references and normalization/conflict rules
|
|
228
|
+
remain in the server catalog. No second catalog or no-op browser registration is
|
|
229
|
+
introduced. Metadata registration and catalog sync do not grant a user, role,
|
|
230
|
+
tenant or resource permission. Existing persisted grants/current authority checks
|
|
231
|
+
remain required. Use the public portable entry rather than private service paths
|
|
232
|
+
when a model package needs declarations without the server runtime.
|
package/dist/chunks/{PasswordCredentialService-BSSP_kyT.js → PasswordCredentialService-D_evcc-I.js}
RENAMED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { a as MembershipStatus, c as TenantPermissionEffect, l as TenantStatus, n as DEFAULT_ROLES, o as OverrideEffect, r as DEFAULT_ROLE_SLUGS, s as SessionStatus, u as UserStatus } from "./types-DqUZxluX.js";
|
|
2
|
+
import { n as getRuntimePermissionRegistrations, t as registerPermissionDefinitions } from "./permission-registry-PhcdZvKe.js";
|
|
2
3
|
import { IN_LIST_CHUNK_SIZE, ObjectRegistry, SmrtCollection, SmrtObject, bumpChangeFeed, chunkArray, crossPackageRef, field, findManifestEntryByQualifiedName, foreignKey, inheritedCollectionSurface, isEmbeddedDatabase, isPostgresDatabase, resolveOperationPermissionAlias, smrt, withEmbeddedWriteTransaction } from "@happyvertical/smrt-core";
|
|
3
4
|
import { getCurrentTenant, runTenantHierarchyReadScope, withSystemContext } from "@happyvertical/smrt-tenancy";
|
|
4
5
|
import { AmbiguousOidcIdentityError, CanonicalPersonProfileError, OidcIdentity, OidcIdentityCollection, ProfileCollection, normalizeIdentityEmail } from "@happyvertical/smrt-profiles";
|
|
@@ -245,6 +246,7 @@ var __decorateClass$11 = (decorators, target, key, kind) => {
|
|
|
245
246
|
return result;
|
|
246
247
|
};
|
|
247
248
|
var __publicField$11 = (obj, key, value) => __defNormalProp$11(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
249
|
+
var STEP_UP_SIGN_IN_AUTH_METHODS = Object.freeze(["password", "passkey"]);
|
|
248
250
|
var DEFAULT_SESSION_TTL = 10080 * 60;
|
|
249
251
|
var SESSION_DATA_KEYS = {
|
|
250
252
|
/** `string[]` of permission slugs the session's resolved set is intersected with. */
|
|
@@ -272,6 +274,25 @@ var SESSION_DATA_KEYS = {
|
|
|
272
274
|
*/
|
|
273
275
|
authenticatedAt: "authenticatedAt",
|
|
274
276
|
/**
|
|
277
|
+
* ISO timestamp of the last step-up: a fresh password check made on this
|
|
278
|
+
* already-signed-in session (#4841). Written only by
|
|
279
|
+
* `SessionCollection.markReauthenticated` after the credential was verified;
|
|
280
|
+
* never from client input (`setSessionData` refuses it), never moved by
|
|
281
|
+
* `extend()`/activity, carried forward unchanged by tenant-switch rotation
|
|
282
|
+
* and gone with the session. See {@link Session.getReauthenticatedAt}.
|
|
283
|
+
*/
|
|
284
|
+
reauthenticatedAt: "reauthenticatedAt",
|
|
285
|
+
/**
|
|
286
|
+
* The pending OIDC step-up intent of this session: the authorization
|
|
287
|
+
* transaction (state, nonce, PKCE verifier) of a re-authentication the
|
|
288
|
+
* session itself started, with its expiry. Written only by
|
|
289
|
+
* `SessionCollection.recordStepUpIntent`, consumed (removed) by
|
|
290
|
+
* `SessionCollection.takeStepUpIntent` on the callback, so it is single use
|
|
291
|
+
* and dies with the session. Never from client input (`setSessionData`
|
|
292
|
+
* refuses it).
|
|
293
|
+
*/
|
|
294
|
+
oidcStepUpIntent: "oidcStepUpIntent",
|
|
295
|
+
/**
|
|
275
296
|
* Row id of the passkey (`users_passkey_credentials`) a session was signed
|
|
276
297
|
* in with. Set only by `PasskeyCredentialService` at mint; it decides which
|
|
277
298
|
* session a passkey removal ends. Never from client input, and
|
|
@@ -318,6 +339,14 @@ var Session = class extends SmrtObject {
|
|
|
318
339
|
return this.parentSessionId !== null && this.parentSessionId !== "";
|
|
319
340
|
}
|
|
320
341
|
/**
|
|
342
|
+
* Whether this session may step up (#4841) at all: a first-class session,
|
|
343
|
+
* not a layered or PIN one, with no permission ceiling. Every step-up method
|
|
344
|
+
* (password, OIDC, magic link) requires it.
|
|
345
|
+
*/
|
|
346
|
+
isStepUpEligible() {
|
|
347
|
+
return !this.isLayered() && this.authMethod !== "pin" && this.getPermissionCeiling() === null;
|
|
348
|
+
}
|
|
349
|
+
/**
|
|
321
350
|
* Absolute expiry cap (`data.absoluteExpiresAt`), or null when the session
|
|
322
351
|
* has none. An unreadable value fails closed as "already passed".
|
|
323
352
|
*/
|
|
@@ -353,6 +382,27 @@ var Session = class extends SmrtObject {
|
|
|
353
382
|
return created instanceof Date && !Number.isNaN(created.getTime()) ? created : null;
|
|
354
383
|
}
|
|
355
384
|
/**
|
|
385
|
+
* When the person last proved a credential on this session (#4841): the
|
|
386
|
+
* newer of the step-up stamp (`data.reauthenticatedAt`) and the sign-in time
|
|
387
|
+
* ({@link Session.getAuthenticatedAt}), the latter counting only for an
|
|
388
|
+
* interactive sign-in method in {@link STEP_UP_SIGN_IN_AUTH_METHODS}. A
|
|
389
|
+
* `terminal`, `pin`, `mobile` or host-defined session proves nothing about
|
|
390
|
+
* the person at mint. A present but malformed step-up stamp returns null
|
|
391
|
+
* (fail closed, even if the sign-in time is fresh).
|
|
392
|
+
*/
|
|
393
|
+
getReauthenticatedAt() {
|
|
394
|
+
const raw = this.data?.[SESSION_DATA_KEYS.reauthenticatedAt];
|
|
395
|
+
let stepUp = null;
|
|
396
|
+
if (raw !== void 0 && raw !== null) {
|
|
397
|
+
const at = typeof raw === "string" ? new Date(raw) : null;
|
|
398
|
+
if (!at || Number.isNaN(at.getTime())) return null;
|
|
399
|
+
stepUp = at;
|
|
400
|
+
}
|
|
401
|
+
const signIn = typeof this.authMethod === "string" && STEP_UP_SIGN_IN_AUTH_METHODS.includes(this.authMethod) ? this.getAuthenticatedAt() : null;
|
|
402
|
+
if (stepUp && signIn) return stepUp > signIn ? stepUp : signIn;
|
|
403
|
+
return stepUp ?? signIn;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
356
406
|
* Permission ceiling (`data.permissionCeiling`), or null when the session
|
|
357
407
|
* has none. A present but malformed value fails closed as an empty ceiling.
|
|
358
408
|
*/
|
|
@@ -814,10 +864,69 @@ var SessionCollection = class extends SmrtCollection {
|
|
|
814
864
|
return true;
|
|
815
865
|
}
|
|
816
866
|
/**
|
|
867
|
+
* Record a step-up (#4841): stamp `data.reauthenticatedAt` on a live session.
|
|
868
|
+
* Call ONLY after the person's credential was verified on the server; this
|
|
869
|
+
* method proves nothing itself. Returns the stamp, or null when the session
|
|
870
|
+
* is unknown, not active, expired, or not `userId`'s (when given). Only the
|
|
871
|
+
* stamp moves: expiry, activity and every other `data` key are untouched,
|
|
872
|
+
* so ordinary use or refresh can never extend it.
|
|
873
|
+
*/
|
|
874
|
+
async markReauthenticated(sessionId, options = {}) {
|
|
875
|
+
const at = options.at ?? /* @__PURE__ */ new Date();
|
|
876
|
+
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
877
|
+
const session = await this.findValidSession(sessionId);
|
|
878
|
+
if (!session) return null;
|
|
879
|
+
if (options.userId !== void 0 && session.userId !== options.userId) return null;
|
|
880
|
+
session.setData(SESSION_DATA_KEYS.reauthenticatedAt, at.toISOString());
|
|
881
|
+
try {
|
|
882
|
+
await session.save();
|
|
883
|
+
return at;
|
|
884
|
+
} catch (error) {
|
|
885
|
+
if (attempt === 3 || !(error instanceof Error && "code" in error && error.code === "RUNTIME_REVISION_CONFLICT")) throw error;
|
|
886
|
+
}
|
|
887
|
+
}
|
|
888
|
+
return null;
|
|
889
|
+
}
|
|
890
|
+
/**
|
|
891
|
+
* Record the OIDC step-up intent of a live session (#4841): the transaction
|
|
892
|
+
* a re-authentication the session itself started must come back with. Only
|
|
893
|
+
* one intent is pending per session; a new one replaces the old. Returns
|
|
894
|
+
* false when the session is unknown, not live, or not `userId`'s.
|
|
895
|
+
*/
|
|
896
|
+
async recordStepUpIntent(sessionId, intent, options = {}) {
|
|
897
|
+
const session = await this.findValidSession(sessionId);
|
|
898
|
+
if (!session) return false;
|
|
899
|
+
if (options.userId !== void 0 && session.userId !== options.userId) return false;
|
|
900
|
+
session.setData(SESSION_DATA_KEYS.oidcStepUpIntent, intent);
|
|
901
|
+
await session.save();
|
|
902
|
+
return true;
|
|
903
|
+
}
|
|
904
|
+
/**
|
|
905
|
+
* Take (read and remove) the pending OIDC step-up intent, so it can be used
|
|
906
|
+
* once. Returns null when there is none, the session is not live or not
|
|
907
|
+
* `userId`'s, or the removal lost a write race (the other writer holds the
|
|
908
|
+
* intent). Never retries: a contested intent is a refused one.
|
|
909
|
+
*/
|
|
910
|
+
async takeStepUpIntent(sessionId, options = {}) {
|
|
911
|
+
const session = await this.findValidSession(sessionId);
|
|
912
|
+
if (!session) return null;
|
|
913
|
+
if (options.userId !== void 0 && session.userId !== options.userId) return null;
|
|
914
|
+
const raw = session.data?.[SESSION_DATA_KEYS.oidcStepUpIntent];
|
|
915
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) return null;
|
|
916
|
+
session.removeData(SESSION_DATA_KEYS.oidcStepUpIntent);
|
|
917
|
+
try {
|
|
918
|
+
await session.save();
|
|
919
|
+
} catch (error) {
|
|
920
|
+
if (error instanceof Error && "code" in error && error.code === "RUNTIME_REVISION_CONFLICT") return null;
|
|
921
|
+
throw error;
|
|
922
|
+
}
|
|
923
|
+
return raw;
|
|
924
|
+
}
|
|
925
|
+
/**
|
|
817
926
|
* Set custom session data
|
|
818
927
|
*/
|
|
819
928
|
async setSessionData(sessionId, key, value) {
|
|
820
|
-
if (key === SESSION_DATA_KEYS.authenticatedAt || key === SESSION_DATA_KEYS.passkeyCredentialId) return false;
|
|
929
|
+
if (key === SESSION_DATA_KEYS.authenticatedAt || key === SESSION_DATA_KEYS.reauthenticatedAt || key === SESSION_DATA_KEYS.oidcStepUpIntent || key === SESSION_DATA_KEYS.passkeyCredentialId) return false;
|
|
821
930
|
const session = await this.findValidSession(sessionId);
|
|
822
931
|
if (!session) return false;
|
|
823
932
|
session.setData(key, value);
|
|
@@ -2131,10 +2240,6 @@ async function writeInSeedingBatches(db, items, write) {
|
|
|
2131
2240
|
}
|
|
2132
2241
|
//#endregion
|
|
2133
2242
|
//#region src/services/PermissionCatalogService.ts
|
|
2134
|
-
function getRuntimePermissionRegistrations() {
|
|
2135
|
-
globalThis.__smrtUsersPermissionRegistrations ??= /* @__PURE__ */ new Map();
|
|
2136
|
-
return globalThis.__smrtUsersPermissionRegistrations;
|
|
2137
|
-
}
|
|
2138
2243
|
function toSnakeCase(value) {
|
|
2139
2244
|
return value.replace(/([a-z0-9])([A-Z])/g, "$1_$2").replace(/[-\s]+/g, "_").toLowerCase();
|
|
2140
2245
|
}
|
|
@@ -2494,14 +2599,6 @@ function mergeDefinitionSet(current, incomingDefinitions, source) {
|
|
|
2494
2599
|
mergeBindings(existing, definition);
|
|
2495
2600
|
}
|
|
2496
2601
|
}
|
|
2497
|
-
function registerPermissionDefinitions(definitions) {
|
|
2498
|
-
globalThis.__smrtUsersPermissionRegistrationCounter = (globalThis.__smrtUsersPermissionRegistrationCounter ?? 0) + 1;
|
|
2499
|
-
const registrationId = globalThis.__smrtUsersPermissionRegistrationCounter;
|
|
2500
|
-
getRuntimePermissionRegistrations().set(registrationId, definitions);
|
|
2501
|
-
return () => {
|
|
2502
|
-
getRuntimePermissionRegistrations().delete(registrationId);
|
|
2503
|
-
};
|
|
2504
|
-
}
|
|
2505
2602
|
function definitionChangesPermission(existing, definition) {
|
|
2506
2603
|
return (definition.name ?? existing.name) !== existing.name || (definition.description ?? existing.description) !== existing.description || (definition.category ?? existing.category) !== existing.category;
|
|
2507
2604
|
}
|
|
@@ -5312,6 +5409,10 @@ var PermissionResolver = class PermissionResolver {
|
|
|
5312
5409
|
};
|
|
5313
5410
|
//#endregion
|
|
5314
5411
|
//#region src/services/SessionService.ts
|
|
5412
|
+
function withoutStepUpIntent(data) {
|
|
5413
|
+
const { [SESSION_DATA_KEYS.oidcStepUpIntent]: _intent, ...rest } = data ?? {};
|
|
5414
|
+
return rest;
|
|
5415
|
+
}
|
|
5315
5416
|
var SessionService = class SessionService {
|
|
5316
5417
|
options;
|
|
5317
5418
|
sessionCollection;
|
|
@@ -5413,7 +5514,8 @@ var SessionService = class SessionService {
|
|
|
5413
5514
|
sessionId: session.id,
|
|
5414
5515
|
authMethod: session.authMethod,
|
|
5415
5516
|
parent,
|
|
5416
|
-
permissionCeiling
|
|
5517
|
+
permissionCeiling,
|
|
5518
|
+
reauthenticatedAt: current.getReauthenticatedAt()
|
|
5417
5519
|
};
|
|
5418
5520
|
}
|
|
5419
5521
|
return null;
|
|
@@ -5537,7 +5639,7 @@ var SessionService = class SessionService {
|
|
|
5537
5639
|
userAgent: session.userAgent,
|
|
5538
5640
|
ipAddress: session.ipAddress,
|
|
5539
5641
|
data: {
|
|
5540
|
-
...session.data,
|
|
5642
|
+
...withoutStepUpIntent(session.data),
|
|
5541
5643
|
[SESSION_DATA_KEYS.authenticatedAt]: session.data?.[SESSION_DATA_KEYS.authenticatedAt] ?? (session.created_at instanceof Date ? session.created_at.toISOString() : (/* @__PURE__ */ new Date(0)).toISOString())
|
|
5542
5644
|
},
|
|
5543
5645
|
authMethod: session.authMethod,
|
|
@@ -5860,6 +5962,31 @@ var PasswordCredentialService = class PasswordCredentialService {
|
|
|
5860
5962
|
}
|
|
5861
5963
|
}
|
|
5862
5964
|
/**
|
|
5965
|
+
* Re-verify the signed-in person's password on their CURRENT session and
|
|
5966
|
+
* stamp `data.reauthenticatedAt` (#4841), which
|
|
5967
|
+
* `requireRecentAuthentication` then reads. Goes through the same limiter
|
|
5968
|
+
* and constant-work verification as sign-in and self-service changes, so it
|
|
5969
|
+
* is no oracle outside the sign-in budget. A layered/PIN session or one with
|
|
5970
|
+
* a permission ceiling never steps up. Every refusal (no or dead session,
|
|
5971
|
+
* wrong password, none set) is one {@link PasswordCredentialError}. The
|
|
5972
|
+
* stamp is not client input and ordinary session use never moves it.
|
|
5973
|
+
*/
|
|
5974
|
+
async stepUp(input) {
|
|
5975
|
+
const sessionId = typeof input.sessionId === "string" ? input.sessionId.trim() : "";
|
|
5976
|
+
if (!sessionId) throw new PasswordCredentialError();
|
|
5977
|
+
const session = await this.sessionRows.findValidSession(sessionId);
|
|
5978
|
+
if (!session?.isStepUpEligible()) throw new PasswordCredentialError();
|
|
5979
|
+
const user = await this.users.get(session.userId);
|
|
5980
|
+
if (!user?.id || !user.isActive()) throw new PasswordCredentialError();
|
|
5981
|
+
await this.verifyCurrent(user, input.password, input.ipAddress, "step-up");
|
|
5982
|
+
const at = await this.sessionRows.markReauthenticated(sessionId, { userId: user.id });
|
|
5983
|
+
if (!at) throw new PasswordCredentialError();
|
|
5984
|
+
return {
|
|
5985
|
+
sessionId,
|
|
5986
|
+
reauthenticatedAt: at.toISOString()
|
|
5987
|
+
};
|
|
5988
|
+
}
|
|
5989
|
+
/**
|
|
5863
5990
|
* Set a password where the person has none: the person themself from any
|
|
5864
5991
|
* first-class session, or an administrator holding `managePermission` for
|
|
5865
5992
|
* someone else (which, if a password already exists, replaces it and ends
|
|
@@ -6192,6 +6319,6 @@ var PasswordCredentialService = class PasswordCredentialService {
|
|
|
6192
6319
|
}
|
|
6193
6320
|
};
|
|
6194
6321
|
//#endregion
|
|
6195
|
-
export { PermissionCatalogService as $, InvalidCredentialsError as A,
|
|
6322
|
+
export { PermissionCatalogService as $, InvalidCredentialsError as A, STEP_UP_SIGN_IN_AUTH_METHODS 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, OidcProvisioningError as F, Membership as Ft, MAX_TENANT_HIERARCHY_DEPTH as G, TenantPermissionOverride as H, UserCollection as I, __exportAll as It, assertTenantTableName as J, TenantHierarchyError as K, requireExistingOwnedPerson as L, LoginRateLimitError as M, generateSessionId as Mt, hashSecret as N, Role as Nt, DEFAULT_SOURCE_LOCKOUT_AUDIT_SECONDS as O, DEFAULT_SESSION_TTL as Ot, verifySecretHash as P, Permission 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, withoutListBounds as it, LoginAttemptLimiter as j, Session 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, syncPermissionCatalog 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 };
|
|
6196
6323
|
|
|
6197
|
-
//# sourceMappingURL=PasswordCredentialService-
|
|
6324
|
+
//# sourceMappingURL=PasswordCredentialService-D_evcc-I.js.map
|