@happyvertical/smrt-users 0.62.13 → 0.63.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.
- package/AGENTS.md +1 -0
- package/agents/service-principals.md +63 -0
- package/dist/chunks/{PasswordCredentialService-BfYi-lfi.js → PasswordCredentialService-DODrdCBc.js} +155 -16
- package/dist/chunks/PasswordCredentialService-DODrdCBc.js.map +1 -0
- package/dist/chunks/TerminalAuthService-CbqTyRK1.js +4148 -0
- package/dist/chunks/TerminalAuthService-CbqTyRK1.js.map +1 -0
- package/dist/collections/SessionCollection.d.ts +20 -1
- package/dist/collections/SessionCollection.d.ts.map +1 -1
- package/dist/collections/UserCollection.d.ts.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +219 -7
- package/dist/index.js.map +1 -1
- package/dist/manifest.json +203 -7
- package/dist/models/Session.d.ts +4 -3
- package/dist/models/Session.d.ts.map +1 -1
- package/dist/models/User.d.ts +56 -0
- package/dist/models/User.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/password-readiness.d.ts.map +1 -1
- package/dist/services/DeviceCredentialService.d.ts.map +1 -1
- package/dist/services/PasswordCredentialService.d.ts.map +1 -1
- package/dist/services/ServicePrincipalService.d.ts +106 -0
- package/dist/services/ServicePrincipalService.d.ts.map +1 -0
- package/dist/services/SessionService.d.ts.map +1 -1
- package/dist/services/TenantInvitationService.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 +113 -6
- package/dist/smrt-knowledge.okf.md +6 -2
- package/dist/sveltekit.js +2 -2
- package/package.json +9 -9
- package/dist/chunks/PasswordCredentialService-BfYi-lfi.js.map +0 -1
- package/dist/chunks/TerminalAuthService-COKIU73u.js +0 -4147
- package/dist/chunks/TerminalAuthService-COKIU73u.js.map +0 -1
package/AGENTS.md
CHANGED
|
@@ -19,6 +19,7 @@ are not prerequisites for unrelated user-package work.
|
|
|
19
19
|
| `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" |
|
|
20
20
|
| `src/services/TenantInvitationService.ts`, `src/services/MailboxAuthenticationService.ts` | exact-role invitations, preserved identity, one-use generations and embedded transaction send budgets | [agents/family-invitations.md](agents/family-invitations.md) |
|
|
21
21
|
| `src/services/oauth-cimd.ts`, `src/services/oauth-cimd-fetch.ts` | opt-in Client ID Metadata Documents for the SDK OAuth server (#5081): required origin policy, SSRF-pinned fetch, cache | [agents/oauth-authorization.md](agents/oauth-authorization.md#client-id-metadata-documents-5081) |
|
|
22
|
+
| `src/services/ServicePrincipalService.ts` | non-login service principals (#5245): tenant-bound, idempotent per key, permanent retire; sessions refused at mint and resolve | [agents/service-principals.md](agents/service-principals.md) |
|
|
22
23
|
| `src/retention.ts` | expired session/token/CLI-auth reaping and retention sweep wiring | [agents/retention.md](agents/retention.md) |
|
|
23
24
|
|
|
24
25
|
## Models and authority
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# Service principals (#5245)
|
|
2
|
+
|
|
3
|
+
A service principal is a User plus one Membership in exactly one tenant that an
|
|
4
|
+
automated actor (an agent, an integration) holds grants as. It can never sign
|
|
5
|
+
in, and hosts need no per-path refusals: smrt-users enforces that itself.
|
|
6
|
+
|
|
7
|
+
## Data shape
|
|
8
|
+
|
|
9
|
+
All new `User` columns are nullable and `readonly` (never mass-assigned over a
|
|
10
|
+
generated surface); every existing row is a person and is unaffected.
|
|
11
|
+
|
|
12
|
+
| Field | Person | Service principal |
|
|
13
|
+
|---|---|---|
|
|
14
|
+
| `principalKind` | `null` | `'service'` |
|
|
15
|
+
| `servicePrincipalTenantId` | `null` | the only tenant it is valid in |
|
|
16
|
+
| `servicePrincipalKey` | `null` | caller key, unique per tenant (`users_service_principal_tenant_key`) |
|
|
17
|
+
| `retiredAt` | `null` | set once on retirement, never cleared by the service |
|
|
18
|
+
|
|
19
|
+
`User.save()` refuses: an unknown `principalKind`; service fields on a person;
|
|
20
|
+
an email or username on a service principal (so no email- or username-keyed
|
|
21
|
+
path can address it); missing tenant/key; and `active`/`pending` status once
|
|
22
|
+
`retiredAt` is set. Its profile is a tenant-scoped `bot` profile, one per
|
|
23
|
+
principal (`profileId` is unique).
|
|
24
|
+
|
|
25
|
+
## Enforcement
|
|
26
|
+
|
|
27
|
+
- Mint: `SessionCollection.createSession` refuses any user whose stored
|
|
28
|
+
`principal_kind` is non-null (fail closed for unknown kinds). Every mint in
|
|
29
|
+
the package (sign-in methods, PIN layers, terminal approval, tenant-switch
|
|
30
|
+
rotation, `SessionService.createSession`) goes through it; a structural test
|
|
31
|
+
in `service-principal.test.ts` keeps it that way.
|
|
32
|
+
- Resolve: `SessionCollection.findValidSession` returns null for such a row,
|
|
33
|
+
which covers `loadSessionContext` and every direct consumer (password,
|
|
34
|
+
passkey, magic-link and OIDC step-up, invitation accept, mailbox auth).
|
|
35
|
+
`loadSessionContext` also refuses a service principal session user or
|
|
36
|
+
layered parent (`User.canHoldSession()`). OAuth grants and mobile bearers
|
|
37
|
+
resolve through `loadSessionContext`.
|
|
38
|
+
- `TenantInvitationService` refuses its membership on issue, accept, mailbox
|
|
39
|
+
authentication and the OIDC owner seam.
|
|
40
|
+
- app-runtime's external-OIDC MCP principal mapping refuses it.
|
|
41
|
+
|
|
42
|
+
## API
|
|
43
|
+
|
|
44
|
+
`ServicePrincipalService.create({ db, transaction: 'caller' })` is a trusted
|
|
45
|
+
host seam like invitation `prepare()`: the host authorizes tenant and role and
|
|
46
|
+
owns the transaction; the service never opens one.
|
|
47
|
+
|
|
48
|
+
- `createServicePrincipal({ tenantId, key, roleSlug | roleId, displayName? })`
|
|
49
|
+
creates or replays by `(tenantId, key)`; a replay with another role, or of a
|
|
50
|
+
retired key, is a `ServicePrincipalError` (409).
|
|
51
|
+
- `retireServicePrincipal({ tenantId, userId })` is permanent and idempotent:
|
|
52
|
+
user suspended and stamped `retiredAt`, membership inactive, any session row
|
|
53
|
+
revoked. Null for a person or another tenant's principal. There is no
|
|
54
|
+
reactivation API; create a new principal under a new key.
|
|
55
|
+
- `isActiveServicePrincipal({ tenantId, userId })` is the per-call validity
|
|
56
|
+
check: service principal, bound to exactly that tenant, not retired, user and
|
|
57
|
+
home membership active. A membership added elsewhere never makes it valid
|
|
58
|
+
there.
|
|
59
|
+
- `getServicePrincipal`, `findServicePrincipal({ tenantId, key })`,
|
|
60
|
+
`listServicePrincipals({ tenantId, includeRetired? })` read records.
|
|
61
|
+
|
|
62
|
+
Concurrent creation is serialized per tenant on PostgreSQL (`FOR UPDATE` on
|
|
63
|
+
the tenant row) and arbitrated by the unique index everywhere.
|
package/dist/chunks/{PasswordCredentialService-BfYi-lfi.js → PasswordCredentialService-DODrdCBc.js}
RENAMED
|
@@ -547,6 +547,9 @@ Session = __decorateClass$11([smrt({
|
|
|
547
547
|
//#region src/models/User.ts
|
|
548
548
|
var __defProp$10 = Object.defineProperty;
|
|
549
549
|
var __getOwnPropDesc$10 = Object.getOwnPropertyDescriptor;
|
|
550
|
+
var __typeError = (msg) => {
|
|
551
|
+
throw TypeError(msg);
|
|
552
|
+
};
|
|
550
553
|
var __defNormalProp$10 = (obj, key, value) => key in obj ? __defProp$10(obj, key, {
|
|
551
554
|
enumerable: true,
|
|
552
555
|
configurable: true,
|
|
@@ -560,6 +563,24 @@ var __decorateClass$10 = (decorators, target, key, kind) => {
|
|
|
560
563
|
return result;
|
|
561
564
|
};
|
|
562
565
|
var __publicField$10 = (obj, key, value) => __defNormalProp$10(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
566
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
567
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
568
|
+
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
569
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
570
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
571
|
+
var _storedPrincipalKind;
|
|
572
|
+
var _storedRetiredAt;
|
|
573
|
+
var _User_instances;
|
|
574
|
+
var rememberStoredPrincipal_fn;
|
|
575
|
+
var SERVICE_PRINCIPAL_KIND = "service";
|
|
576
|
+
var ServicePrincipalError = class extends Error {
|
|
577
|
+
status;
|
|
578
|
+
constructor(message, status = 403) {
|
|
579
|
+
super(message);
|
|
580
|
+
this.name = "ServicePrincipalError";
|
|
581
|
+
this.status = status;
|
|
582
|
+
}
|
|
583
|
+
};
|
|
563
584
|
var EMAIL_REGEX = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
564
585
|
var USERNAME_REGEX = /^[a-z0-9](?:[a-z0-9._-]{0,62}[a-z0-9])?$/;
|
|
565
586
|
function isValidEmail(email) {
|
|
@@ -576,20 +597,58 @@ function normalizeUsername(username) {
|
|
|
576
597
|
return USERNAME_REGEX.test(normalized) ? normalized : "";
|
|
577
598
|
}
|
|
578
599
|
var User = class extends SmrtObject {
|
|
579
|
-
profileId = "";
|
|
580
|
-
email = "";
|
|
581
|
-
emailKey = null;
|
|
582
|
-
username = null;
|
|
583
|
-
usernameKey = null;
|
|
584
|
-
status = UserStatus.ACTIVE;
|
|
585
|
-
lastLoginAt = null;
|
|
586
600
|
constructor(options = {}) {
|
|
587
601
|
super(options);
|
|
602
|
+
__privateAdd(this, _User_instances);
|
|
603
|
+
__publicField$10(this, "profileId", "");
|
|
604
|
+
__publicField$10(this, "email", "");
|
|
605
|
+
__publicField$10(this, "emailKey", null);
|
|
606
|
+
__publicField$10(this, "username", null);
|
|
607
|
+
__publicField$10(this, "usernameKey", null);
|
|
608
|
+
__publicField$10(this, "status", UserStatus.ACTIVE);
|
|
609
|
+
__publicField$10(this, "lastLoginAt", null);
|
|
610
|
+
__publicField$10(this, "principalKind", null);
|
|
611
|
+
__publicField$10(this, "servicePrincipalTenantId", null);
|
|
612
|
+
__publicField$10(this, "servicePrincipalKey", null);
|
|
613
|
+
__publicField$10(this, "retiredAt", null);
|
|
614
|
+
/**
|
|
615
|
+
* `principalKind`/`retiredAt` as last read from or written to the
|
|
616
|
+
* database (#5245). A loaded service principal can never be saved back as
|
|
617
|
+
* a person, and a retirement can never be cleared, whatever the caller
|
|
618
|
+
* does to the in-memory fields.
|
|
619
|
+
*/
|
|
620
|
+
__privateAdd(this, _storedPrincipalKind, null);
|
|
621
|
+
__privateAdd(this, _storedRetiredAt, null);
|
|
588
622
|
if (options.profileId !== void 0) this.profileId = options.profileId;
|
|
589
623
|
if (options.email !== void 0) this.email = normalizeEmail(options.email);
|
|
590
624
|
if (options.username !== void 0) this.username = normalizeUsername(options.username) || null;
|
|
591
625
|
if (options.status !== void 0) this.status = options.status;
|
|
592
626
|
if (options.lastLoginAt !== void 0) this.lastLoginAt = options.lastLoginAt;
|
|
627
|
+
if (options.principalKind !== void 0) this.principalKind = options.principalKind;
|
|
628
|
+
if (options.servicePrincipalTenantId !== void 0) this.servicePrincipalTenantId = options.servicePrincipalTenantId;
|
|
629
|
+
if (options.servicePrincipalKey !== void 0) this.servicePrincipalKey = options.servicePrincipalKey;
|
|
630
|
+
if (options.retiredAt !== void 0) this.retiredAt = options.retiredAt;
|
|
631
|
+
}
|
|
632
|
+
async initialize() {
|
|
633
|
+
await super.initialize();
|
|
634
|
+
if (this.isPersisted) __privateMethod(this, _User_instances, rememberStoredPrincipal_fn).call(this);
|
|
635
|
+
return this;
|
|
636
|
+
}
|
|
637
|
+
async loadDataFromDb(data) {
|
|
638
|
+
const result = await super.loadDataFromDb(data);
|
|
639
|
+
__privateMethod(this, _User_instances, rememberStoredPrincipal_fn).call(this);
|
|
640
|
+
return result;
|
|
641
|
+
}
|
|
642
|
+
/** True for a non-login service principal (#5245); never holds a session. */
|
|
643
|
+
isServicePrincipal() {
|
|
644
|
+
return isServicePrincipalKind(this.principalKind);
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Whether this row may ever hold a session: only a person
|
|
648
|
+
* (`principalKind` null). Any other kind, known or not, fails closed.
|
|
649
|
+
*/
|
|
650
|
+
canHoldSession() {
|
|
651
|
+
return this.principalKind == null;
|
|
593
652
|
}
|
|
594
653
|
/**
|
|
595
654
|
* Validate the user's email format.
|
|
@@ -624,13 +683,41 @@ var User = class extends SmrtObject {
|
|
|
624
683
|
}
|
|
625
684
|
/** Keep the durable email key derived from the public email field. */
|
|
626
685
|
async save(options) {
|
|
686
|
+
if (__privateGet(this, _storedPrincipalKind) != null && this.principalKind !== __privateGet(this, _storedPrincipalKind)) throw new ServicePrincipalError("A service principal can never become another kind of principal");
|
|
687
|
+
if (__privateGet(this, _storedRetiredAt) != null && this.retiredAt == null) throw new ServicePrincipalError("A retired service principal cannot be reactivated");
|
|
688
|
+
this.assertServicePrincipalInvariants();
|
|
627
689
|
this.email = normalizeEmail(this.email);
|
|
628
690
|
this.emailKey = this.email || null;
|
|
629
691
|
this.username = normalizeUsername(this.username) || null;
|
|
630
692
|
this.usernameKey = this.username;
|
|
631
|
-
|
|
693
|
+
const saved = await super.save(options);
|
|
694
|
+
__privateMethod(this, _User_instances, rememberStoredPrincipal_fn).call(this);
|
|
695
|
+
return saved;
|
|
696
|
+
}
|
|
697
|
+
/**
|
|
698
|
+
* Service principal invariants (#5245), enforced on every ORM save: it has
|
|
699
|
+
* no login identifier (no email or username can address it), it is bound to
|
|
700
|
+
* a tenant and key, and once retired it can never be active or pending
|
|
701
|
+
* again. A person row (`principalKind` null) must not carry service fields.
|
|
702
|
+
*/
|
|
703
|
+
assertServicePrincipalInvariants() {
|
|
704
|
+
if (this.principalKind != null && !this.isServicePrincipal()) throw new ServicePrincipalError("Unknown principal kind", 400);
|
|
705
|
+
if (!this.isServicePrincipal()) {
|
|
706
|
+
if (this.servicePrincipalTenantId != null || this.servicePrincipalKey != null || this.retiredAt != null) throw new ServicePrincipalError("Only a service principal carries service principal fields", 400);
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
if (normalizeEmail(this.email) || normalizeUsername(this.username)) throw new ServicePrincipalError("A service principal has no email or username", 400);
|
|
710
|
+
if (!this.servicePrincipalTenantId || !this.servicePrincipalKey) throw new ServicePrincipalError("A service principal is bound to a tenant and key", 400);
|
|
711
|
+
if (this.retiredAt != null && (this.status === UserStatus.ACTIVE || this.status === UserStatus.PENDING)) throw new ServicePrincipalError("A retired service principal cannot be reactivated");
|
|
632
712
|
}
|
|
633
713
|
};
|
|
714
|
+
_storedPrincipalKind = /* @__PURE__ */ new WeakMap();
|
|
715
|
+
_storedRetiredAt = /* @__PURE__ */ new WeakMap();
|
|
716
|
+
_User_instances = /* @__PURE__ */ new WeakSet();
|
|
717
|
+
rememberStoredPrincipal_fn = function() {
|
|
718
|
+
__privateSet(this, _storedPrincipalKind, this.principalKind ?? null);
|
|
719
|
+
__privateSet(this, _storedRetiredAt, this.retiredAt ?? null);
|
|
720
|
+
};
|
|
634
721
|
__publicField$10(User, "__smrtPackage__", "@happyvertical/smrt-users");
|
|
635
722
|
__decorateClass$10([crossPackageRef("@happyvertical/smrt-profiles:Profile", { unique: true }), field({ description: "The personal profile linked to this account." })], User.prototype, "profileId", 2);
|
|
636
723
|
__decorateClass$10([field({
|
|
@@ -662,13 +749,49 @@ __decorateClass$10([field({
|
|
|
662
749
|
type: "text"
|
|
663
750
|
})], User.prototype, "status", 2);
|
|
664
751
|
__decorateClass$10([field({ description: "When this person most recently signed in." })], User.prototype, "lastLoginAt", 2);
|
|
752
|
+
__decorateClass$10([field({
|
|
753
|
+
description: "Empty for a person; \"service\" for an automated account that can never sign in.",
|
|
754
|
+
type: "text",
|
|
755
|
+
nullable: true,
|
|
756
|
+
readonly: true
|
|
757
|
+
})], User.prototype, "principalKind", 2);
|
|
758
|
+
__decorateClass$10([field({
|
|
759
|
+
description: "For an automated account, the organization it belongs to; empty for a person.",
|
|
760
|
+
sqlType: "UUID",
|
|
761
|
+
nullable: true,
|
|
762
|
+
readonly: true
|
|
763
|
+
})], User.prototype, "servicePrincipalTenantId", 2);
|
|
764
|
+
__decorateClass$10([field({
|
|
765
|
+
description: "For an automated account, the key its creator gave it; empty for a person.",
|
|
766
|
+
type: "text",
|
|
767
|
+
nullable: true,
|
|
768
|
+
readonly: true
|
|
769
|
+
})], User.prototype, "servicePrincipalKey", 2);
|
|
770
|
+
__decorateClass$10([field({
|
|
771
|
+
description: "When this automated account was permanently retired; empty while in use.",
|
|
772
|
+
nullable: true,
|
|
773
|
+
readonly: true
|
|
774
|
+
})], User.prototype, "retiredAt", 2);
|
|
665
775
|
User = __decorateClass$10([smrt({
|
|
666
776
|
api: { include: ["list", "get"] },
|
|
667
777
|
mcp: { include: ["list", "get"] },
|
|
668
|
-
cli: { include: ["list", "get"] }
|
|
778
|
+
cli: { include: ["list", "get"] },
|
|
779
|
+
indexes: [{
|
|
780
|
+
name: "users_service_principal_tenant_key",
|
|
781
|
+
columns: ["servicePrincipalTenantId", "servicePrincipalKey"],
|
|
782
|
+
unique: true
|
|
783
|
+
}]
|
|
669
784
|
})], User);
|
|
785
|
+
function isServicePrincipalKind(value) {
|
|
786
|
+
return value === SERVICE_PRINCIPAL_KIND;
|
|
787
|
+
}
|
|
670
788
|
//#endregion
|
|
671
789
|
//#region src/collections/SessionCollection.ts
|
|
790
|
+
async function isSessionlessPrincipalUser(db, userId) {
|
|
791
|
+
if (typeof userId !== "string" || userId === "") return false;
|
|
792
|
+
const kind = (await db.query("SELECT principal_kind FROM users WHERE id = ?", userId)).rows?.[0]?.principal_kind;
|
|
793
|
+
return kind !== null && kind !== void 0;
|
|
794
|
+
}
|
|
672
795
|
var SessionCollection = class extends SmrtCollection {
|
|
673
796
|
static _itemClass = Session;
|
|
674
797
|
async revokeWithRetry(sessionId) {
|
|
@@ -687,9 +810,21 @@ var SessionCollection = class extends SmrtCollection {
|
|
|
687
810
|
return false;
|
|
688
811
|
}
|
|
689
812
|
/**
|
|
690
|
-
*
|
|
813
|
+
* Whether `userId` names a principal that may never hold a session
|
|
814
|
+
* (#5245); see {@link isSessionlessPrincipalUser}.
|
|
815
|
+
*/
|
|
816
|
+
async isSessionlessPrincipal(userId) {
|
|
817
|
+
return isSessionlessPrincipalUser(this.db, userId);
|
|
818
|
+
}
|
|
819
|
+
/**
|
|
820
|
+
* Create a new session with a secure ID.
|
|
821
|
+
*
|
|
822
|
+
* Every session mint in this package funnels through here, so this is where
|
|
823
|
+
* a service principal (#5245) is refused: no sign-in method, layered PIN
|
|
824
|
+
* session, terminal approval, tenant switch or host call can mint one.
|
|
691
825
|
*/
|
|
692
826
|
async createSession(options) {
|
|
827
|
+
if (await this.isSessionlessPrincipal(options.userId)) throw new ServicePrincipalError("A service principal can never hold a session");
|
|
693
828
|
const ttl = options.ttl ?? 604800;
|
|
694
829
|
const session = await this.create({
|
|
695
830
|
id: generateSessionId(),
|
|
@@ -767,6 +902,7 @@ var SessionCollection = class extends SmrtCollection {
|
|
|
767
902
|
async findValidSession(sessionId) {
|
|
768
903
|
const session = await this.get(sessionId);
|
|
769
904
|
if (!session) return null;
|
|
905
|
+
if (await this.isSessionlessPrincipal(session.userId)) return null;
|
|
770
906
|
if (!session.isValid()) {
|
|
771
907
|
if (session.isExpired() && session.status === SessionStatus.ACTIVE) {
|
|
772
908
|
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
@@ -4134,6 +4270,7 @@ var UserCollection = class UserCollection extends SmrtCollection {
|
|
|
4134
4270
|
* Find user by email address
|
|
4135
4271
|
*/
|
|
4136
4272
|
async findByEmail(email) {
|
|
4273
|
+
if (typeof email !== "string" || email.trim() === "") return null;
|
|
4137
4274
|
const results = await this.list({
|
|
4138
4275
|
where: { email },
|
|
4139
4276
|
limit: 1
|
|
@@ -5529,14 +5666,16 @@ var SessionService = class SessionService {
|
|
|
5529
5666
|
for (let attempt = 0; attempt < 4; attempt += 1) {
|
|
5530
5667
|
const session = await this.sessionCollection.findValidSession(sessionId);
|
|
5531
5668
|
if (!session) return null;
|
|
5532
|
-
|
|
5669
|
+
const initialUser = await this.userCollection.get(session.userId);
|
|
5670
|
+
if (!initialUser?.isActive() || !initialUser.canHoldSession()) return null;
|
|
5533
5671
|
let parent = null;
|
|
5534
5672
|
if (session.isLayered()) {
|
|
5535
5673
|
const parentSession = await this.sessionCollection.findValidSession(session.parentSessionId);
|
|
5536
5674
|
if (!parentSession) return null;
|
|
5537
5675
|
if (parentSession.isLayered()) return null;
|
|
5538
5676
|
if (session.tenantId !== null && session.tenantId !== parentSession.tenantId) return null;
|
|
5539
|
-
|
|
5677
|
+
const parentUser = await this.userCollection.get(parentSession.userId);
|
|
5678
|
+
if (!parentUser?.isActive() || !parentUser.canHoldSession()) return null;
|
|
5540
5679
|
parent = {
|
|
5541
5680
|
sessionId: parentSession.id,
|
|
5542
5681
|
userId: parentSession.userId,
|
|
@@ -5548,7 +5687,7 @@ var SessionService = class SessionService {
|
|
|
5548
5687
|
const userId = session.userId;
|
|
5549
5688
|
const tenantId = session.tenantId;
|
|
5550
5689
|
const user = await this.userCollection.get(userId);
|
|
5551
|
-
if (!user?.isActive()) return null;
|
|
5690
|
+
if (!user?.isActive() || !user.canHoldSession()) return null;
|
|
5552
5691
|
let permissions = [];
|
|
5553
5692
|
let membership = null;
|
|
5554
5693
|
let tenantAuthorization = null;
|
|
@@ -6319,7 +6458,7 @@ var PasswordCredentialService = class PasswordCredentialService {
|
|
|
6319
6458
|
async assertCanManage(actor, targetUserId) {
|
|
6320
6459
|
if (!actor.permissions.includes(this.managePermission)) throw new PasswordCredentialForbiddenError();
|
|
6321
6460
|
const active = actor.tenantId && UUID_PATTERN.test(targetUserId) ? (await withSystemContext(() => this.memberships.findByUser(targetUserId))).filter((membership) => membership.isActive()) : [];
|
|
6322
|
-
if (active.length === 0 || active.some((membership) => membership.tenantId !== actor.tenantId)) throw new PasswordCredentialForbiddenError();
|
|
6461
|
+
if (active.length === 0 || active.some((membership) => membership.tenantId !== actor.tenantId) || await isSessionlessPrincipalUser(this.memberships.db, targetUserId)) throw new PasswordCredentialForbiddenError();
|
|
6323
6462
|
}
|
|
6324
6463
|
/** Returns the normalized password to hash, or throws {@link PasswordPolicyError}. */
|
|
6325
6464
|
async assertPolicy(password, user) {
|
|
@@ -6384,6 +6523,6 @@ var PasswordCredentialService = class PasswordCredentialService {
|
|
|
6384
6523
|
}
|
|
6385
6524
|
};
|
|
6386
6525
|
//#endregion
|
|
6387
|
-
export { PermissionCatalogService as $, InvalidCredentialsError as A,
|
|
6526
|
+
export { PermissionCatalogService as $, InvalidCredentialsError as A, normalizeEmail as At, backfillUserEmailKeys as B, __exportAll as Bt, DEFAULT_LOGIN_ATTEMPT_WINDOW_SECONDS as C, SessionCollection as Ct, DEFAULT_LOGIN_MAX_ATTEMPTS as D, User as Dt, DEFAULT_LOGIN_LOCKOUT_MAX_SECONDS as E, ServicePrincipalError as Et, OidcProvisioningError as F, Session as Ft, MAX_TENANT_HIERARCHY_DEPTH as G, TenantPermissionOverride as H, UserCollection as I, generateSessionId as It, assertTenantTableName as J, TenantHierarchyError as K, requireExistingOwnedPerson as L, Role as Lt, LoginRateLimitError as M, DEFAULT_SESSION_TTL as Mt, hashSecret as N, SESSION_DATA_KEYS as Nt, DEFAULT_SOURCE_LOCKOUT_AUDIT_SECONDS as O, isServicePrincipalKind as Ot, verifySecretHash as P, STEP_UP_SIGN_IN_AUTH_METHODS as Pt, RolePermissionCollection as Q, USER_EMAIL_KEY_BACKFILL_NAME as R, Permission as Rt, normalizeAncestorReadPolicy as S, UsersLoginAttempt as St, DEFAULT_LOGIN_LOCKOUT_FACTOR as T, SERVICE_PRINCIPAL_KIND 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, normalizeUsername as jt, DurableLoginAuditSink as k, isValidEmail 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, isSessionlessPrincipalUser as wt, isAncestorReadableSlug as x, UsersLoginAttemptCollection as xt, DEFAULT_ANCESTOR_READ_MAX_DEPTH as y, UsersLoginAuditEventCollection as yt, UserEmailKeyBackfillError as z, Membership as zt };
|
|
6388
6527
|
|
|
6389
|
-
//# sourceMappingURL=PasswordCredentialService-
|
|
6528
|
+
//# sourceMappingURL=PasswordCredentialService-DODrdCBc.js.map
|