@astram/guard 0.30.0 → 0.31.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/README.md +43 -0
- package/dist/enforcement/enforcement.module.d.ts +8 -1
- package/dist/enforcement/enforcement.module.d.ts.map +1 -1
- package/dist/enforcement/enforcement.module.js +9 -0
- package/dist/enforcement/global-enforcement.guard.d.ts.map +1 -1
- package/dist/enforcement/global-enforcement.guard.js +7 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/internal.d.ts +6 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +8 -1
- package/dist/request-auth/request-principal-als.d.ts +65 -0
- package/dist/request-auth/request-principal-als.d.ts.map +1 -0
- package/dist/request-auth/request-principal-als.js +83 -0
- package/package.json +5 -5
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ host's NestJS runtime.
|
|
|
18
18
|
| Core seam | `src/enforcement/core-seam.ts` | Type-only import of `@astram/core`'s `DecisionAuthority` (ADR-0003) + the fail-closed stub. |
|
|
19
19
|
| Boot-pool assertion | `src/boot/boot-sequence.ts` | ADR-0018 connection-pool budget check at boot (fail-closed). |
|
|
20
20
|
| App config | `src/config/app-config.ts` | Port / environment / ADR-0018 pool budget (env loader, pure). |
|
|
21
|
+
| Request principal | `src/request-auth/request-principal-als.ts` | Read-only `currentRequestPrincipal()`: the current request's `{ tenantId, userId }` (below). |
|
|
21
22
|
|
|
22
23
|
## The registration seam (ADR-0023 §4)
|
|
23
24
|
|
|
@@ -53,6 +54,48 @@ export class AppModule {}
|
|
|
53
54
|
in this layer): the factory resolves the same options at startup; the guard/boot
|
|
54
55
|
wiring is identical.
|
|
55
56
|
|
|
57
|
+
## Request principal (`currentRequestPrincipal`)
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
import { currentRequestPrincipal } from '@astram/guard';
|
|
61
|
+
|
|
62
|
+
const p = currentRequestPrincipal(); // Readonly<{ tenantId: string; userId: string }> | undefined
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
Framework code that runs inside a request but has no `req` in hand (for example `@astram/agent`'s
|
|
66
|
+
`createAuditedFetch`) reads the caller's tenant and principal id here. Spec:
|
|
67
|
+
`docs/features/capability-outbound-audit/SPEC.md` v6 §5 G.
|
|
68
|
+
|
|
69
|
+
- **Read-only.** A framework middleware (`EnforcementModule`, every route) opens a module-private
|
|
70
|
+
`AsyncLocalStorage` with an empty holder per request. The global enforcement guard is its only
|
|
71
|
+
writer: once, on the allow path, after authentication, from the principal it resolved from the
|
|
72
|
+
session or API key (never from the body, headers or query). The value is frozen. The storage, the
|
|
73
|
+
middleware and the writer are not exported, so app code cannot enter the scope or overwrite it.
|
|
74
|
+
- **`undefined`** outside a request (a scheduled job), on a `@Public()` route, for a request the
|
|
75
|
+
guard refused, and for a request that did not pass the middleware.
|
|
76
|
+
- **`userId` is the principal id**: a user or a service account. The value does not say which kind
|
|
77
|
+
(GAPS #46); look the id up if you need it.
|
|
78
|
+
- Work that resumes outside the request's async context (for example some stream consumers) reads
|
|
79
|
+
`undefined`, never another request's value (an interleaved four-request test holds this). Read it
|
|
80
|
+
in the request's own call chain; a callback run by shared code (a listener on an app-wide emitter)
|
|
81
|
+
runs in the context of whoever triggered it, so do not read it there.
|
|
82
|
+
- **Start background work at boot (`onApplicationBootstrap`), never lazily from inside a
|
|
83
|
+
request.** Async resources created inside a request (a timer, a promise chain, a queue drain a
|
|
84
|
+
handler starts on first use) keep that request's context, including its principal or its lack of
|
|
85
|
+
one.
|
|
86
|
+
- Routes excluded from `app.setGlobalPrefix(prefix, { exclude })` pass the middleware too (an e2e
|
|
87
|
+
test holds this).
|
|
88
|
+
- `@astram/guard/internal` (framework use only) also exports a read-only `insideRequest()`: `true`
|
|
89
|
+
inside a request that passed the middleware, with or without a principal. `@astram/agent`'s
|
|
90
|
+
audited fetch uses it to refuse calls from `@Public()` and refused requests.
|
|
91
|
+
- **Express only.** `currentRequestPrincipal` is proven on `@nestjs/platform-express`; Fastify is
|
|
92
|
+
unsupported until it has its own e2e test.
|
|
93
|
+
- **Nest routes only.** The holder is opened by a Nest middleware, so a handler mounted directly on
|
|
94
|
+
the HTTP adapter (outside Nest routing) runs "outside a request": `insideRequest()` is `false` and
|
|
95
|
+
`@astram/agent`'s `createAuditedFetch` takes the scheduled-job branch there (the app must then
|
|
96
|
+
supply a server-held tenant). Keep connector code in Nest handlers or boot-started jobs.
|
|
97
|
+
- In memory only: no database or Redis read is added to the request path (Shield #12).
|
|
98
|
+
|
|
56
99
|
## Peer dependencies (ADR-0023 §2)
|
|
57
100
|
|
|
58
101
|
`@astram/guard` **peer-depends** on the host runtime so the consumer owns exactly
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type MiddlewareConsumer, type NestModule } from '@nestjs/common';
|
|
1
2
|
/** Framework-module marker (G-036 M1, agent-read-capabilities SPEC §5 A); see `ShieldModule`. */
|
|
2
3
|
declare const FRAMEWORK_MODULE: unique symbol;
|
|
3
4
|
/**
|
|
@@ -15,8 +16,14 @@ declare const FRAMEWORK_MODULE: unique symbol;
|
|
|
15
16
|
* this the single `APP_GUARD` definition (instead of re-inlining it in
|
|
16
17
|
* `ShieldModule`) guarantees exactly one wiring path for the guard.
|
|
17
18
|
*/
|
|
18
|
-
export declare class EnforcementModule {
|
|
19
|
+
export declare class EnforcementModule implements NestModule {
|
|
19
20
|
static readonly [FRAMEWORK_MODULE] = true;
|
|
21
|
+
/**
|
|
22
|
+
* Request principal (capability-outbound-audit SPEC v6 §5 G): open the module-private request
|
|
23
|
+
* principal scope, with an empty holder, around every route. The global guard above is the only
|
|
24
|
+
* writer of that holder; `currentRequestPrincipal()` is the only reader the barrel exports.
|
|
25
|
+
*/
|
|
26
|
+
configure(consumer: MiddlewareConsumer): void;
|
|
20
27
|
}
|
|
21
28
|
export {};
|
|
22
29
|
//# sourceMappingURL=enforcement.module.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enforcement.module.d.ts","sourceRoot":"","sources":["../../src/enforcement/enforcement.module.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enforcement.module.d.ts","sourceRoot":"","sources":["../../src/enforcement/enforcement.module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAyB,KAAK,kBAAkB,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAMjG,iGAAiG;AACjG,QAAA,MAAM,gBAAgB,eAAwC,CAAC;AAE/D;;;;;;;;;;;;;;GAcG;AACH,qBAgBa,iBAAkB,YAAW,UAAU;IAClD,MAAM,CAAC,QAAQ,CAAC,CAAC,gBAAgB,CAAC,QAAQ;IAE1C;;;;OAIG;IACH,SAAS,CAAC,QAAQ,EAAE,kBAAkB,GAAG,IAAI;CAG9C"}
|
|
@@ -9,6 +9,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
9
|
exports.EnforcementModule = void 0;
|
|
10
10
|
const common_1 = require("@nestjs/common");
|
|
11
11
|
const core_1 = require("@nestjs/core");
|
|
12
|
+
const request_principal_als_js_1 = require("../request-auth/request-principal-als.js");
|
|
12
13
|
const global_enforcement_guard_js_1 = require("./global-enforcement.guard.js");
|
|
13
14
|
const engine_error_filter_js_1 = require("./engine-error.filter.js");
|
|
14
15
|
/** Framework-module marker (G-036 M1, agent-read-capabilities SPEC §5 A); see `ShieldModule`. */
|
|
@@ -30,6 +31,14 @@ const FRAMEWORK_MODULE = Symbol.for('astram.framework-module');
|
|
|
30
31
|
*/
|
|
31
32
|
let EnforcementModule = class EnforcementModule {
|
|
32
33
|
static [FRAMEWORK_MODULE] = true;
|
|
34
|
+
/**
|
|
35
|
+
* Request principal (capability-outbound-audit SPEC v6 §5 G): open the module-private request
|
|
36
|
+
* principal scope, with an empty holder, around every route. The global guard above is the only
|
|
37
|
+
* writer of that holder; `currentRequestPrincipal()` is the only reader the barrel exports.
|
|
38
|
+
*/
|
|
39
|
+
configure(consumer) {
|
|
40
|
+
consumer.apply(request_principal_als_js_1.requestPrincipalMiddleware).forRoutes({ path: '*', method: common_1.RequestMethod.ALL });
|
|
41
|
+
}
|
|
33
42
|
};
|
|
34
43
|
exports.EnforcementModule = EnforcementModule;
|
|
35
44
|
exports.EnforcementModule = EnforcementModule = __decorate([
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global-enforcement.guard.d.ts","sourceRoot":"","sources":["../../src/enforcement/global-enforcement.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAMjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAK5D,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAA2B,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOlF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;
|
|
1
|
+
{"version":3,"file":"global-enforcement.guard.d.ts","sourceRoot":"","sources":["../../src/enforcement/global-enforcement.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,gBAAgB,EAMjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAOzC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAK5D,OAAO,EAGL,KAAK,kBAAkB,EACxB,MAAM,yCAAyC,CAAC;AACjD,OAAO,KAAK,EAA2B,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAOlF,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AAQpF,OAAO,EAEL,KAAK,qBAAqB,EAC3B,MAAM,uCAAuC,CAAC;AAa/C;;;;;;;;;;GAUG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAGpE;AAYD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBACa,sBAAuB,YAAW,WAAW;IAEtD,OAAO,CAAC,QAAQ,CAAC,SAAS;IAG1B,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAC;IAGnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAM7B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAO7B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAC;IAMtC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAC;gBAzBf,SAAS,EAAE,SAAS,EAGpB,iBAAiB,CAAC,EAAE,qBAAqB,YAAA,EAGzC,WAAW,CAAC,EAAE,kBAAkB,YAAA,EAMhC,WAAW,CAAC,EAAE,oBAAoB,YAAA,EAOlC,oBAAoB,CAAC,GAAE,oBAAoB,GAAG,IAAI,aAAA,EAMlD,cAAc,CAAC,GAAE,qBAAqB,GAAG,IAAI,aAAA;IAG1D,WAAW,CAAC,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,OAAO,CAAC;IAuC9D,mFAAmF;YACrE,mBAAmB;IA0LjC;;;;OAIG;IACH,OAAO,CAAC,kBAAkB;IAW1B;;;;;OAKG;YACW,oBAAoB;IAuBlC;;;;;;;;;;;;;;;;OAgBG;YACW,4BAA4B;CA8C3C"}
|
|
@@ -23,6 +23,7 @@ const session_token_binder_js_1 = require("../request-auth/session-token-binder.
|
|
|
23
23
|
const request_principal_js_1 = require("../request-auth/request-principal.js");
|
|
24
24
|
const tokens_js_2 = require("../auth/tokens.js");
|
|
25
25
|
const session_facts_als_js_1 = require("../request-auth/session-facts-als.js");
|
|
26
|
+
const request_principal_als_js_1 = require("../request-auth/request-principal-als.js");
|
|
26
27
|
const reenroll_allowlist_js_1 = require("./reenroll-allowlist.js");
|
|
27
28
|
const session_restriction_js_1 = require("../session/session-restriction.js");
|
|
28
29
|
const mfa_requirement_service_js_1 = require("../session/mfa-requirement-service.js");
|
|
@@ -272,6 +273,12 @@ let GlobalEnforcementGuard = class GlobalEnforcementGuard {
|
|
|
272
273
|
if (enforced !== claims)
|
|
273
274
|
this.enforceRestriction(enforced, req);
|
|
274
275
|
if (decision.effect === 'allow') {
|
|
276
|
+
// Request principal (capability-outbound-audit SPEC v6 §5 G): this guard is its only writer,
|
|
277
|
+
// once, after authentication and the allow, from the principal resolved from the bearer token
|
|
278
|
+
// above (never body, headers or query; core #7). `userId` is the principal id for every kind
|
|
279
|
+
// (user, service account). A request with no holder (it did not pass the framework middleware)
|
|
280
|
+
// makes this a no-op. In-memory only: no DB or Redis read (Shield #12).
|
|
281
|
+
(0, request_principal_als_js_1.writeRequestPrincipal)(principal.tenantId, principal.id);
|
|
275
282
|
return true;
|
|
276
283
|
}
|
|
277
284
|
// Deny (or any non-allow) → 403. Do NOT leak the reason detail to the caller.
|
package/dist/index.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ export type { BoundPrincipalClaims, SessionTokenBinderOptions, } from './request
|
|
|
32
32
|
export { resolveRequestPrincipal, resolveRequestAuth, principalFromClaims, extractBearerToken, isApiKey, } from './request-auth/request-principal.js';
|
|
33
33
|
export { MariaDbApiKeyStore } from './authentication/mariadb-api-key-store.js';
|
|
34
34
|
export { SHIELD_SESSION_FACTS_ALS, NO_SESSION_FACTS, type SessionFactsStore, } from './request-auth/session-facts-als.js';
|
|
35
|
+
export { currentRequestPrincipal } from './request-auth/request-principal-als.js';
|
|
35
36
|
export { GlobalEnforcementGuard } from './enforcement/global-enforcement.guard.js';
|
|
36
37
|
export { stubDecisionAuthority, type Effect, type CoreDecisionAuthority, type CoreDecision, type Principal, } from './enforcement/core-seam.js';
|
|
37
38
|
export { Argon2idPasswordHasher, argon2idHasherProvider, SHIELD_PASSWORD_HASHER, lockedPasswordHash, isLockedHash, type Argon2idParams, } from './authentication/argon2id-password-hasher.js';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1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, `reflect-metadata`, `rxjs` so the host owns one copy of each.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
20
|
-
exports.
|
|
21
|
-
exports.
|
|
22
|
-
exports.
|
|
23
|
-
exports.ScopeUnknownParentError = exports.ScopeDepthError = exports.ScopeCycleError = exports.buildClosureRows = exports.ConfirmEmailController = exports.AccountController = exports.generateRecoveryCodes = exports.buildOtpauthUri = exports.generateTotpSecret = exports.SHIELD_LOGIN_TOTP_VERIFIER = exports.SHIELD_MFA_STEP_UP = exports.SHIELD_MFA_LIMITER = exports.challengeMatches = exports.credentialFingerprint = exports.CredentialMfaStepUp = exports.RedisPendingMfaStore = exports.PendingMfaStore = exports.AuthController = exports.SHIELD_SCOPE_SUBTREE_RESOLVER = exports.SHIELD_SESSION_FACTS_PROJECTOR = exports.ProfileNameTakenError = exports.maskPhone = exports.MAX_MESSAGE_SEND_TIMEOUT_MS = exports.DEFAULT_MESSAGE_SEND_TIMEOUT_MS = exports.EMAIL_PROVIDER_VALUES = exports.loadMessageConfig = exports.MariaDbEmailAddressChanger = exports.maskEmail = exports.isEmailShaped = exports.canonicalEmail = exports.hmacSha1 = exports.resolveTotpVerifier = exports.makeDefaultTotpVerifier = void 0;
|
|
19
|
+
exports.EncryptedFileSecretsProvider = exports.LocalKekCrypto = exports.resolveAuthLinkBaseUrls = exports.CredentialExistsError = exports.isLockedHash = exports.lockedPasswordHash = exports.SHIELD_PASSWORD_HASHER = exports.argon2idHasherProvider = exports.Argon2idPasswordHasher = exports.stubDecisionAuthority = exports.GlobalEnforcementGuard = exports.currentRequestPrincipal = exports.NO_SESSION_FACTS = exports.SHIELD_SESSION_FACTS_ALS = exports.MariaDbApiKeyStore = exports.isApiKey = exports.extractBearerToken = exports.principalFromClaims = exports.resolveRequestAuth = exports.resolveRequestPrincipal = exports.SessionTokenBinder = exports.SHIELD_SERVICE_AUTHENTICATOR = exports.SHIELD_SESSION_TOKEN_BINDER = exports.CatalogGatabilityError = exports.CatalogReconciler = exports.OperationInventoryScanner = exports.uuidArrayField = exports.optionalUuidField = exports.uuidField = exports.UuidPipe = exports.normalizeClassification = exports.DEFAULT_CLASSIFIED_ACTION = exports.CLASSIFICATION_METADATA = exports.Classified = exports.Public = exports.SHIELD_RECORD_AUTHORIZATION = exports.SHIELD_DECISION_AUTHORITY = exports.ShieldModule = exports.actionsOf = exports.actionsFor = exports.AGENT_TENANT_MODES = exports.AGENT_ACTIONS = exports.SERVICE_ACCOUNT_ACTIONS = exports.RECORD_SHARE_ACTIONS = exports.CROSS_TENANT_GRANT_ACTIONS = exports.IDENTITY_ACTIONS = exports.MODULE_KEY = exports.permissionTextByKey = exports.buildIdentityModuleRegistry = exports.guardMigrationsDir = void 0;
|
|
20
|
+
exports.MariaDbListScopeAdapter = exports.SHIELD_POLICY_STORE = exports.MariaDbPolicyStore = exports.SHIELD_RECORD_RULE_PORT = exports.MariaDbRecordPermissionRuleAdapter = exports.accessBindingTtlMs = exports.ROTATE_GRACE_MS = exports.SHIELD_SESSION_LIFETIMES = exports.HotRevokingSessionRecordStore = exports.SHIELD_CLOCK = exports.SHIELD_REFRESH_HASHER = exports.SHIELD_TOKEN_GENERATOR = exports.systemClockProvider = exports.refreshHasherProvider = exports.cryptoTokenGeneratorProvider = exports.SystemClock = exports.Sha256RefreshTokenHasher = exports.CryptoTokenGenerator = exports.RedisRecentRotationStore = exports.SHIELD_HOT_SESSION_STORE = exports.RedisHotSessionStore = exports.SHIELD_SESSION_RECORD_STORE = exports.MariaDbSessionRecordStore = exports.DEFAULT_OBJECT_STORAGE_MAX_BYTES = exports.loadObjectStorageConfig = exports.SHIELD_AGENT_FILE_READER = exports.SHIELD_FILE_INGEST = exports.SHIELD_OBJECT_STORE = exports.FILE_INTAKE_DEFAULT_MAX_BYTES = exports.FILE_INTAKE_REQUEST_KEY = exports.FileIntake = exports.ObjectStoreBootCheck = exports.SHIELD_NOTIFICATIONS = exports.loadNotificationConfig = exports.NotificationUnavailableError = exports.NotificationValidationError = exports.NotificationKindError = exports.NOTIFICATION_BULK_ACTIONS = exports.NOTIFICATION_STATUSES = exports.NOTIFICATION_SEVERITIES = exports.NOTIFICATION_CATEGORIES = exports.NotificationService = exports.loadAuditSealConfig = exports.NodeSha256Hash = exports.NodeSha256Digest = exports.S3ObjectStore = exports.wasResolvedFromSecretRef = exports.assertNoUnresolvedSecretRefs = exports.createSecretsProviderFromEnv = exports.resolveBootSecrets = void 0;
|
|
21
|
+
exports.loadRefreshHmacKey = exports.loadSessionLifetimes = exports.loadRedisConfig = exports.loadDbConfig = exports.SCHEMA_SVC_POOL_HARD_CAP = exports.DEFAULT_POOL_BUDGET = exports.evaluatePoolBudget = exports.loadPoolBudget = exports.loadAppConfig = exports.frameworkSchemasOf = exports.FRAMEWORK_SCHEMAS = exports.APP_CONFIG = exports.resolveMigrationLedgerCheck = exports.resolveMigrationLedger = exports.frameworkMigrationIds = exports.assertFrameworkMigrationsApplied = exports.SHIELD_MIGRATION_LEDGER_REGISTRY = exports.MigrationLedgerRegistry = exports.FrameworkMigrationLedgerCheck = exports.frameworkDatabasesLogLine = exports.assertPoolBudget = exports.BootSequence = exports.buildListScopeFn = exports.MariaDbSessionRestrictionStore = exports.SHIELD_SESSION_RESTRICTIONS = exports.SHIELD_PERMISSION_VERSION_CACHE = exports.DEFAULT_PERMISSION_VERSION_TTL_MS = exports.PERMISSION_VERSION_KEY_PREFIX = exports.RedisPermissionVersionCache = exports.withRedisPermissionVersion = exports.buildRecordAuthorization = exports.SHIELD_OPERATION_AUTHORITY_PORT = exports.ManifestOperationAuthorityAdapter = exports.GrantStoreUnavailableError = exports.InvalidGrantError = exports.GrantNotPermittedError = exports.SHIELD_CROSS_TENANT_GRANT_WRITER = exports.CrossTenantGrantWriter = exports.SHIELD_CROSS_TENANT_GRANT_PORT = exports.MariaDbCrossTenantGrantAdapter = exports.makeShareDeleteCascade = exports.ShareStoreUnavailableError = exports.ShareNotPermittedError = exports.SHIELD_RECORD_SHARE_WRITER = exports.RecordShareWriter = exports.SHIELD_RECORD_SHARE_PORT = exports.MariaDbRecordShareAdapter = exports.UnknownScopeFieldError = exports.translateListScope = exports.SHIELD_LIST_SCOPE_PORT = void 0;
|
|
22
|
+
exports.SHIELD_CAPTCHA_GATE = exports.RECAPTCHA_SITEVERIFY_URL = exports.RecaptchaVerifier = exports.TURNSTILE_SITEVERIFY_URL = exports.TurnstileVerifier = exports.MAX_CAPTCHA_TIMEOUT_MS = exports.DEFAULT_CAPTCHA_TIMEOUT_MS = exports.DEFAULT_CAPTCHA_MIN_SCORE = exports.DEFAULT_CAPTCHA_THRESHOLD = exports.CAPTCHA_FAIL_MODES = exports.CAPTCHA_MODES = exports.CAPTCHA_ENDPOINTS = exports.loadCaptchaConfig = exports.SHIELD_SIGN_IN_WITH = exports.DEFAULT_SIGN_IN_WITH = exports.resolveSignInWith = exports.MariaDbCredentialResolver = exports.SHIELD_TOTP_VERIFIER_OVERRIDE = exports.SHIELD_MFA_DEVICE_STORE = exports.SHIELD_AUDIT_SINK = exports.SHIELD_SESSION_SWEEPER = exports.SHIELD_PROFILE_WRITER = exports.SHIELD_RECOVERY_CODE_STORE = exports.SHIELD_MESSAGE_DISPATCHER = exports.SHIELD_EMAIL_SENDER = exports.SHIELD_EMAIL_CHANGE_TOKEN_STORE = exports.SHIELD_RESET_TOKEN_STORE = exports.SHIELD_CREDENTIAL_WRITER = exports.SHIELD_SESSION_AUTHORITY = exports.SHIELD_AUTHENTICATOR = exports.SHIELD_PROFILE_RESOLVER = exports.SHIELD_CREDENTIAL_RESOLVER = exports.SHIELD_REDIS = exports.withoutStatementTimeout = exports.mariadbPoolTuningOptions = exports.mariadbSslOption = exports.reservedOperationPrincipal = exports.RESERVED_OPERATION_PRINCIPALS = exports.assertNoReservedRootId = exports.ORG_BOOTSTRAP_PRINCIPAL_ID = exports.rootIdsFromEnv = exports.loadPoolTuning = exports.loadDbTlsConfig = exports.isDevOrTestNodeEnv = exports.DEFAULT_LOGIN_IP_LIMIT = exports.loadRefreshReplayWindowMs = exports.loadLoginIpLimit = exports.DEFAULT_REDIS_URL = exports.DEFAULT_DB_CONFIG = exports.assertRefreshHmacKey = void 0;
|
|
23
|
+
exports.ScopeUnknownParentError = exports.ScopeDepthError = exports.ScopeCycleError = exports.buildClosureRows = exports.ConfirmEmailController = exports.AccountController = exports.generateRecoveryCodes = exports.buildOtpauthUri = exports.generateTotpSecret = exports.SHIELD_LOGIN_TOTP_VERIFIER = exports.SHIELD_MFA_STEP_UP = exports.SHIELD_MFA_LIMITER = exports.challengeMatches = exports.credentialFingerprint = exports.CredentialMfaStepUp = exports.RedisPendingMfaStore = exports.PendingMfaStore = exports.AuthController = exports.SHIELD_SCOPE_SUBTREE_RESOLVER = exports.SHIELD_SESSION_FACTS_PROJECTOR = exports.ProfileNameTakenError = exports.maskPhone = exports.MAX_MESSAGE_SEND_TIMEOUT_MS = exports.DEFAULT_MESSAGE_SEND_TIMEOUT_MS = exports.EMAIL_PROVIDER_VALUES = exports.loadMessageConfig = exports.MariaDbEmailAddressChanger = exports.maskEmail = exports.isEmailShaped = exports.canonicalEmail = exports.hmacSha1 = exports.resolveTotpVerifier = exports.makeDefaultTotpVerifier = exports.AuthModule = void 0;
|
|
24
24
|
// Framework authz migrations (shield_authz DDL — permission / role_permission /
|
|
25
25
|
// authz_permission_version). Absolute path a consumer's `@astram/migrate` setup merges in.
|
|
26
26
|
var migrations_dir_js_1 = require("./migrations-dir.js");
|
|
@@ -104,6 +104,12 @@ Object.defineProperty(exports, "MariaDbApiKeyStore", { enumerable: true, get: fu
|
|
|
104
104
|
var session_facts_als_js_1 = require("./request-auth/session-facts-als.js");
|
|
105
105
|
Object.defineProperty(exports, "SHIELD_SESSION_FACTS_ALS", { enumerable: true, get: function () { return session_facts_als_js_1.SHIELD_SESSION_FACTS_ALS; } });
|
|
106
106
|
Object.defineProperty(exports, "NO_SESSION_FACTS", { enumerable: true, get: function () { return session_facts_als_js_1.NO_SESSION_FACTS; } });
|
|
107
|
+
// The request principal (capability-outbound-audit SPEC v6 §5 G): a READ-ONLY view of the current
|
|
108
|
+
// request's frozen `{ tenantId, userId }`, written once by the global enforcement guard. `undefined`
|
|
109
|
+
// outside a request, on public routes and for refused requests. The ALS, its middleware and its
|
|
110
|
+
// writer stay private to guard: app code cannot enter or overwrite it.
|
|
111
|
+
var request_principal_als_js_1 = require("./request-auth/request-principal-als.js");
|
|
112
|
+
Object.defineProperty(exports, "currentRequestPrincipal", { enumerable: true, get: function () { return request_principal_als_js_1.currentRequestPrincipal; } });
|
|
107
113
|
// The global enforcement guard (framework-owned; exported so the enforcement
|
|
108
114
|
// point is inspectable/testable, not so consumers re-wire it).
|
|
109
115
|
//
|
package/dist/internal.d.ts
CHANGED
|
@@ -70,6 +70,12 @@ export { RedisSessionLiveness, type SessionLiveness, type SessionLivenessState,
|
|
|
70
70
|
* caller fails closed. Recorded by the guard from what gate 5 reported; no read of its own.
|
|
71
71
|
*/
|
|
72
72
|
export { requestFactsVersion } from './enforcement/global-enforcement.guard.js';
|
|
73
|
+
/**
|
|
74
|
+
* For `@astram/agent` only (capability-outbound-audit SPEC v6 §5 G, QA P2-1): read-only, `true`
|
|
75
|
+
* inside a request that passed the framework middleware (with or without a principal). The audited
|
|
76
|
+
* fetch refuses a call made inside a request that has no principal (`@Public()` or refused).
|
|
77
|
+
*/
|
|
78
|
+
export { insideRequest } from './request-auth/request-principal-als.js';
|
|
73
79
|
/** For `@astram/agent` only (SPEC §5 `AgentModule` env): the runtime URL rule's loopback check. */
|
|
74
80
|
export { isLoopbackHost } from './config/loopback-host.js';
|
|
75
81
|
//# sourceMappingURL=internal.d.ts.map
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAC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,EAChB,KAAK,kBAAkB,GACxB,MAAM,iCAAiC,CAAC;AACzC,OAAO,EACL,kBAAkB,EAClB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,WAAW,GACjB,MAAM,0CAA0C,CAAC;AAClD,YAAY,EACV,cAAc,EACd,oBAAoB,EACpB,gBAAgB,GACjB,MAAM,sCAAsC,CAAC;AAC9C;;;GAGG;AACH,OAAO,EAAE,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,OAAO,EACL,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,oBAAoB,GAC1B,MAAM,+BAA+B,CAAC;AACvC;;;;GAIG;AACH,OAAO,EAAE,mBAAmB,EAAE,MAAM,2CAA2C,CAAC;AAChF;;;;GAIG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,yCAAyC,CAAC;AACxE,mGAAmG;AACnG,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC"}
|
package/dist/internal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isLoopbackHost = exports.requestFactsVersion = exports.RedisSessionLiveness = exports.SHIELD_SESSION_LIVENESS = exports.MariaDbMfaResetter = exports.accountUnlockKeys = exports.AdminControlUnavailableError = exports.SHIELD_ACCOUNT_UNLOCKER = exports.SHIELD_ADMIN_STEP_UP = exports.SHIELD_MFA_REQUIREMENT_SOURCE = exports.SHIELD_MFA_REQUIREMENT = exports.SHIELD_MFA_POLICY_FEATURE = exports.SHIELD_DEFAULT_SCOPE_SUBTREE_RESOLVER = exports.SHIELD_DEFAULT_AUTH_AUDIT_SINK = exports.SHIELD_ATTEMPT_LIMITER_FACTORY = exports.SHIELD_REDIS = exports.AttemptLimiter = exports.MariaDbCredentialProvisioner = exports.SHIELD_AUDIT_SEALER_POOL = exports.SHIELD_DB_POOL = exports.PersistenceModule = void 0;
|
|
3
|
+
exports.isLoopbackHost = exports.insideRequest = exports.requestFactsVersion = exports.RedisSessionLiveness = exports.SHIELD_SESSION_LIVENESS = exports.MariaDbMfaResetter = exports.accountUnlockKeys = exports.AdminControlUnavailableError = exports.SHIELD_ACCOUNT_UNLOCKER = exports.SHIELD_ADMIN_STEP_UP = exports.SHIELD_MFA_REQUIREMENT_SOURCE = exports.SHIELD_MFA_REQUIREMENT = exports.SHIELD_MFA_POLICY_FEATURE = exports.SHIELD_DEFAULT_SCOPE_SUBTREE_RESOLVER = exports.SHIELD_DEFAULT_AUTH_AUDIT_SINK = exports.SHIELD_ATTEMPT_LIMITER_FACTORY = exports.SHIELD_REDIS = exports.AttemptLimiter = exports.MariaDbCredentialProvisioner = exports.SHIELD_AUDIT_SEALER_POOL = exports.SHIELD_DB_POOL = exports.PersistenceModule = void 0;
|
|
4
4
|
/**
|
|
5
5
|
* @astram/guard/internal — framework-composition and test surface (Phase 8 #5).
|
|
6
6
|
*
|
|
@@ -91,6 +91,13 @@ Object.defineProperty(exports, "RedisSessionLiveness", { enumerable: true, get:
|
|
|
91
91
|
*/
|
|
92
92
|
var global_enforcement_guard_js_1 = require("./enforcement/global-enforcement.guard.js");
|
|
93
93
|
Object.defineProperty(exports, "requestFactsVersion", { enumerable: true, get: function () { return global_enforcement_guard_js_1.requestFactsVersion; } });
|
|
94
|
+
/**
|
|
95
|
+
* For `@astram/agent` only (capability-outbound-audit SPEC v6 §5 G, QA P2-1): read-only, `true`
|
|
96
|
+
* inside a request that passed the framework middleware (with or without a principal). The audited
|
|
97
|
+
* fetch refuses a call made inside a request that has no principal (`@Public()` or refused).
|
|
98
|
+
*/
|
|
99
|
+
var request_principal_als_js_1 = require("./request-auth/request-principal-als.js");
|
|
100
|
+
Object.defineProperty(exports, "insideRequest", { enumerable: true, get: function () { return request_principal_als_js_1.insideRequest; } });
|
|
94
101
|
/** For `@astram/agent` only (SPEC §5 `AgentModule` env): the runtime URL rule's loopback check. */
|
|
95
102
|
var loopback_host_js_1 = require("./config/loopback-host.js");
|
|
96
103
|
Object.defineProperty(exports, "isLoopbackHost", { enumerable: true, get: function () { return loopback_host_js_1.isLoopbackHost; } });
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-request **request principal** (capability-outbound-audit SPEC v6 §5 G, "Request principal").
|
|
3
|
+
*
|
|
4
|
+
* Framework code that runs inside a request (for example `@astram/agent`'s audited fetch) needs the
|
|
5
|
+
* caller's tenant and principal id without a `req` object in hand. This file holds them in a
|
|
6
|
+
* MODULE-PRIVATE `AsyncLocalStorage`:
|
|
7
|
+
*
|
|
8
|
+
* - {@link requestPrincipalMiddleware} (applied by `EnforcementModule` on every route) opens the
|
|
9
|
+
* scope for the whole request with an EMPTY holder;
|
|
10
|
+
* - {@link writeRequestPrincipal} fills the holder ONCE, frozen. Its only caller is the global
|
|
11
|
+
* enforcement guard, after successful authentication and an allow decision, from the principal
|
|
12
|
+
* the guard resolved from the bearer token (never from the body, headers or query; core #7);
|
|
13
|
+
* - {@link currentRequestPrincipal} reads it. It is the only name the guard barrel exports;
|
|
14
|
+
* - {@link insideRequest} (read-only, `@astram/guard/internal` only) tells whether a holder exists.
|
|
15
|
+
*
|
|
16
|
+
* The ALS instance, the holder, the middleware and the writer are NOT exported from the package, so
|
|
17
|
+
* app code can neither enter the scope nor overwrite the value. A request that did not pass the
|
|
18
|
+
* middleware has no holder: the guard's write is a no-op there and reads stay `undefined`.
|
|
19
|
+
*
|
|
20
|
+
* Pure in-memory scoping: no DB or Redis read is added to the request path (Shield #12).
|
|
21
|
+
*/
|
|
22
|
+
/** The request principal: the caller's tenant and principal id, as resolved by the guard. */
|
|
23
|
+
export interface RequestPrincipal {
|
|
24
|
+
/** The principal's tenant (the active scope node the session or API key is bound to). */
|
|
25
|
+
readonly tenantId: string;
|
|
26
|
+
/** The principal id: a user or a service account. */
|
|
27
|
+
readonly userId: string;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* The current request's principal, or `undefined` when there is none: outside a request (a
|
|
31
|
+
* scheduled job), on a `@Public()` route, for a request the guard refused, or for a request that did
|
|
32
|
+
* not pass the framework middleware.
|
|
33
|
+
*
|
|
34
|
+
* The value is frozen and read-only. `userId` is the principal id: a user or a service account.
|
|
35
|
+
*
|
|
36
|
+
* Async resources created inside a request (timers, promises, queue drains started lazily by a
|
|
37
|
+
* handler) keep that request's context. Start background work at boot (`onApplicationBootstrap`),
|
|
38
|
+
* never lazily from inside a request.
|
|
39
|
+
*/
|
|
40
|
+
export declare function currentRequestPrincipal(): Readonly<RequestPrincipal> | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* INTERNAL (`@astram/guard/internal` only, never the barrel): `true` while running inside a request
|
|
43
|
+
* that passed the framework middleware (a holder exists), whether or not the guard wrote a
|
|
44
|
+
* principal into it. Read-only: it lets framework code (`@astram/agent`'s audited fetch) tell a
|
|
45
|
+
* `@Public()` or refused request (`true`, no principal) from work outside any request, such as a
|
|
46
|
+
* scheduled job (`false`). Async resources created inside a request keep that request's context,
|
|
47
|
+
* so background work must start at boot (`onApplicationBootstrap`), never lazily from a request.
|
|
48
|
+
*/
|
|
49
|
+
export declare function insideRequest(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* INTERNAL (not exported from the barrel). Framework middleware: runs the rest of the request
|
|
52
|
+
* inside a fresh, empty holder. A new holder per request, so nothing carries over between requests
|
|
53
|
+
* on a kept-alive connection.
|
|
54
|
+
*/
|
|
55
|
+
export declare function requestPrincipalMiddleware(_req: unknown, _res: unknown, next: () => void): void;
|
|
56
|
+
/**
|
|
57
|
+
* INTERNAL (not exported from the barrel); the global enforcement guard is the only caller. Writes
|
|
58
|
+
* the request principal into the current request's holder, frozen, exactly once.
|
|
59
|
+
*
|
|
60
|
+
* Returns `false` (and writes nothing) when there is no holder (the request did not pass the
|
|
61
|
+
* middleware, or this runs outside a request), when the holder was already written (a second write
|
|
62
|
+
* is refused), or when either value is not a non-empty string.
|
|
63
|
+
*/
|
|
64
|
+
export declare function writeRequestPrincipal(tenantId: string, userId: string): boolean;
|
|
65
|
+
//# sourceMappingURL=request-principal-als.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-principal-als.d.ts","sourceRoot":"","sources":["../../src/request-auth/request-principal-als.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,6FAA6F;AAC7F,MAAM,WAAW,gBAAgB;IAC/B,yFAAyF;IACzF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,qDAAqD;IACrD,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAUD;;;;;;;;;;GAUG;AACH,wBAAgB,uBAAuB,IAAI,QAAQ,CAAC,gBAAgB,CAAC,GAAG,SAAS,CAEhF;AAED;;;;;;;GAOG;AACH,wBAAgB,aAAa,IAAI,OAAO,CAEvC;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,GAAG,IAAI,CAG/F;AAED;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAO/E"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The per-request **request principal** (capability-outbound-audit SPEC v6 §5 G, "Request principal").
|
|
4
|
+
*
|
|
5
|
+
* Framework code that runs inside a request (for example `@astram/agent`'s audited fetch) needs the
|
|
6
|
+
* caller's tenant and principal id without a `req` object in hand. This file holds them in a
|
|
7
|
+
* MODULE-PRIVATE `AsyncLocalStorage`:
|
|
8
|
+
*
|
|
9
|
+
* - {@link requestPrincipalMiddleware} (applied by `EnforcementModule` on every route) opens the
|
|
10
|
+
* scope for the whole request with an EMPTY holder;
|
|
11
|
+
* - {@link writeRequestPrincipal} fills the holder ONCE, frozen. Its only caller is the global
|
|
12
|
+
* enforcement guard, after successful authentication and an allow decision, from the principal
|
|
13
|
+
* the guard resolved from the bearer token (never from the body, headers or query; core #7);
|
|
14
|
+
* - {@link currentRequestPrincipal} reads it. It is the only name the guard barrel exports;
|
|
15
|
+
* - {@link insideRequest} (read-only, `@astram/guard/internal` only) tells whether a holder exists.
|
|
16
|
+
*
|
|
17
|
+
* The ALS instance, the holder, the middleware and the writer are NOT exported from the package, so
|
|
18
|
+
* app code can neither enter the scope nor overwrite the value. A request that did not pass the
|
|
19
|
+
* middleware has no holder: the guard's write is a no-op there and reads stay `undefined`.
|
|
20
|
+
*
|
|
21
|
+
* Pure in-memory scoping: no DB or Redis read is added to the request path (Shield #12).
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.currentRequestPrincipal = currentRequestPrincipal;
|
|
25
|
+
exports.insideRequest = insideRequest;
|
|
26
|
+
exports.requestPrincipalMiddleware = requestPrincipalMiddleware;
|
|
27
|
+
exports.writeRequestPrincipal = writeRequestPrincipal;
|
|
28
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
29
|
+
/** Module-private: never exported from this file's package entry points. */
|
|
30
|
+
const REQUEST_PRINCIPAL_ALS = new node_async_hooks_1.AsyncLocalStorage();
|
|
31
|
+
/**
|
|
32
|
+
* The current request's principal, or `undefined` when there is none: outside a request (a
|
|
33
|
+
* scheduled job), on a `@Public()` route, for a request the guard refused, or for a request that did
|
|
34
|
+
* not pass the framework middleware.
|
|
35
|
+
*
|
|
36
|
+
* The value is frozen and read-only. `userId` is the principal id: a user or a service account.
|
|
37
|
+
*
|
|
38
|
+
* Async resources created inside a request (timers, promises, queue drains started lazily by a
|
|
39
|
+
* handler) keep that request's context. Start background work at boot (`onApplicationBootstrap`),
|
|
40
|
+
* never lazily from inside a request.
|
|
41
|
+
*/
|
|
42
|
+
function currentRequestPrincipal() {
|
|
43
|
+
return REQUEST_PRINCIPAL_ALS.getStore()?.principal;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* INTERNAL (`@astram/guard/internal` only, never the barrel): `true` while running inside a request
|
|
47
|
+
* that passed the framework middleware (a holder exists), whether or not the guard wrote a
|
|
48
|
+
* principal into it. Read-only: it lets framework code (`@astram/agent`'s audited fetch) tell a
|
|
49
|
+
* `@Public()` or refused request (`true`, no principal) from work outside any request, such as a
|
|
50
|
+
* scheduled job (`false`). Async resources created inside a request keep that request's context,
|
|
51
|
+
* so background work must start at boot (`onApplicationBootstrap`), never lazily from a request.
|
|
52
|
+
*/
|
|
53
|
+
function insideRequest() {
|
|
54
|
+
return REQUEST_PRINCIPAL_ALS.getStore() !== undefined;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* INTERNAL (not exported from the barrel). Framework middleware: runs the rest of the request
|
|
58
|
+
* inside a fresh, empty holder. A new holder per request, so nothing carries over between requests
|
|
59
|
+
* on a kept-alive connection.
|
|
60
|
+
*/
|
|
61
|
+
function requestPrincipalMiddleware(_req, _res, next) {
|
|
62
|
+
const holder = { principal: undefined };
|
|
63
|
+
REQUEST_PRINCIPAL_ALS.run(holder, next);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* INTERNAL (not exported from the barrel); the global enforcement guard is the only caller. Writes
|
|
67
|
+
* the request principal into the current request's holder, frozen, exactly once.
|
|
68
|
+
*
|
|
69
|
+
* Returns `false` (and writes nothing) when there is no holder (the request did not pass the
|
|
70
|
+
* middleware, or this runs outside a request), when the holder was already written (a second write
|
|
71
|
+
* is refused), or when either value is not a non-empty string.
|
|
72
|
+
*/
|
|
73
|
+
function writeRequestPrincipal(tenantId, userId) {
|
|
74
|
+
const holder = REQUEST_PRINCIPAL_ALS.getStore();
|
|
75
|
+
if (holder === undefined || holder.principal !== undefined)
|
|
76
|
+
return false;
|
|
77
|
+
if (typeof tenantId !== 'string' || tenantId.length === 0)
|
|
78
|
+
return false;
|
|
79
|
+
if (typeof userId !== 'string' || userId.length === 0)
|
|
80
|
+
return false;
|
|
81
|
+
holder.principal = Object.freeze({ tenantId, userId });
|
|
82
|
+
return true;
|
|
83
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@astram/guard",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.31.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Astram framework — the enforcement guard + real-world adapters (the 'hands'). One global deny-by-default gate every request passes through (ADR-0002), classification decorators, boot-pool assertion (ADR-0018), the forRoot() registration seam, and the DB/Redis/crypto adapters that connect the sealed core to a real backend. Depends on @astram/core (ADR-0003, ADR-0023).",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
"argon2": "^0.41.1",
|
|
37
37
|
"ioredis": "^5.4.1",
|
|
38
38
|
"mariadb": "^3.5.4",
|
|
39
|
-
"@astram/
|
|
40
|
-
"@astram/
|
|
39
|
+
"@astram/core": "1.18.0",
|
|
40
|
+
"@astram/engine": "0.18.0"
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"@nestjs/common": "^11",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"@nestjs/platform-express": "^11",
|
|
46
46
|
"reflect-metadata": "^0.2",
|
|
47
47
|
"rxjs": "^7",
|
|
48
|
-
"@astram/messaging": "^0.1.
|
|
48
|
+
"@astram/messaging": "^0.1.19"
|
|
49
49
|
},
|
|
50
50
|
"peerDependenciesMeta": {
|
|
51
51
|
"@astram/messaging": {
|
|
@@ -68,7 +68,7 @@
|
|
|
68
68
|
"typescript": "^5.7.0",
|
|
69
69
|
"unplugin-swc": "^1.5.1",
|
|
70
70
|
"vitest": "^2.1.8",
|
|
71
|
-
"@astram/messaging": "0.1.
|
|
71
|
+
"@astram/messaging": "0.1.19"
|
|
72
72
|
},
|
|
73
73
|
"repository": {
|
|
74
74
|
"type": "git",
|