@adaptic/backend 0.0.1056 → 0.0.1058
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/Account.cjs +14 -0
- package/AccountLinkingRequest.cjs +14 -0
- package/AccountRiskMetrics.cjs +11 -0
- package/AdaConversation.cjs +14 -0
- package/Alert.cjs +11 -0
- package/Allocation.cjs +11 -0
- package/AlpacaAccount.cjs +36 -0
- package/Authenticator.cjs +14 -0
- package/AutoFollowRule.cjs +14 -0
- package/BrokerageAccount.cjs +11 -0
- package/Customer.cjs +14 -0
- package/DeskDecision.cjs +11 -0
- package/FeatureFlagOverride.cjs +14 -0
- package/Follow.cjs +14 -0
- package/Fund.cjs +56 -0
- package/FundAssignment.cjs +14 -0
- package/Investor.cjs +14 -0
- package/LinkedProvider.cjs +14 -0
- package/LlmConfiguration.cjs +14 -0
- package/Mandate.cjs +14 -0
- package/MandateApproval.cjs +14 -0
- package/MandateVersion.cjs +14 -0
- package/NotificationDelivery.cjs +14 -0
- package/NotificationPreference.cjs +14 -0
- package/OrgMembership.cjs +14 -0
- package/PolicyOverlay.cjs +64 -0
- package/PushSubscription.cjs +14 -0
- package/RiskEscalationEvent.cjs +33 -0
- package/Session.cjs +14 -0
- package/Strategy.cjs +28 -0
- package/StrategyHealthSnapshot.cjs +11 -0
- package/StrategySubscription.cjs +11 -0
- package/TradingPolicy.cjs +6 -0
- package/User.cjs +11 -0
- package/UserTotp.cjs +14 -0
- package/WaitlistEntry.cjs +14 -0
- package/auth/authorization-map.cjs +306 -0
- package/auth/authorization-map.d.ts +143 -0
- package/auth/cortex-auth-checker.cjs +172 -0
- package/auth/cortex-auth-checker.d.ts +114 -0
- package/auth/credential-fields.cjs +51 -0
- package/auth/credential-fields.d.ts +19 -0
- package/auth/credential-redaction.cjs +134 -0
- package/auth/credential-redaction.d.ts +60 -0
- package/auth/graphql-auth-shadow.cjs +317 -0
- package/auth/graphql-auth-shadow.d.ts +194 -0
- package/auth/membership-write-authority.cjs +131 -0
- package/auth/membership-write-authority.d.ts +110 -0
- package/auth/mutation-authorization.cjs +376 -0
- package/auth/mutation-authorization.d.ts +261 -0
- package/auth/nested-write-inspector.cjs +189 -0
- package/auth/nested-write-inspector.d.ts +94 -0
- package/auth/nested-write-policy.cjs +189 -0
- package/auth/nested-write-policy.d.ts +99 -0
- package/auth/service-token.cjs +316 -0
- package/auth/service-token.d.ts +94 -0
- package/auth/tenancy-scope.cjs +736 -0
- package/auth/tenancy-scope.d.ts +347 -0
- package/auth/token-verifier.cjs +451 -0
- package/auth/token-verifier.d.ts +153 -0
- package/auth/totp.cjs +265 -0
- package/auth/totp.d.ts +111 -0
- package/auth/user-write-content.cjs +116 -0
- package/auth/user-write-content.d.ts +47 -0
- package/auth/ws-auth-context.cjs +75 -0
- package/auth/ws-auth-context.d.ts +69 -0
- package/config/jwtConfig.cjs +52 -0
- package/config/jwtConfig.d.ts +16 -0
- package/config/metrics.cjs +356 -0
- package/config/metrics.d.ts +128 -0
- package/config/persisted-queries.cjs +122 -0
- package/config/persisted-queries.d.ts +40 -0
- package/config/server-only-models.cjs +166 -0
- package/config/server-only-models.d.ts +89 -0
- package/config/tracing.d.ts +24 -0
- package/esm/Account.mjs +14 -0
- package/esm/AccountLinkingRequest.mjs +14 -0
- package/esm/AccountRiskMetrics.mjs +11 -0
- package/esm/AdaConversation.mjs +14 -0
- package/esm/Alert.mjs +11 -0
- package/esm/Allocation.mjs +11 -0
- package/esm/AlpacaAccount.mjs +36 -0
- package/esm/Authenticator.mjs +14 -0
- package/esm/AutoFollowRule.mjs +14 -0
- package/esm/BrokerageAccount.mjs +11 -0
- package/esm/Customer.mjs +14 -0
- package/esm/DeskDecision.mjs +11 -0
- package/esm/FeatureFlagOverride.mjs +14 -0
- package/esm/Follow.mjs +14 -0
- package/esm/Fund.mjs +56 -0
- package/esm/FundAssignment.mjs +14 -0
- package/esm/Investor.mjs +14 -0
- package/esm/LinkedProvider.mjs +14 -0
- package/esm/LlmConfiguration.mjs +14 -0
- package/esm/Mandate.mjs +14 -0
- package/esm/MandateApproval.mjs +14 -0
- package/esm/MandateVersion.mjs +14 -0
- package/esm/NotificationDelivery.mjs +14 -0
- package/esm/NotificationPreference.mjs +14 -0
- package/esm/OrgMembership.mjs +14 -0
- package/esm/PolicyOverlay.mjs +64 -0
- package/esm/PushSubscription.mjs +14 -0
- package/esm/RiskEscalationEvent.mjs +33 -0
- package/esm/Session.mjs +14 -0
- package/esm/Strategy.mjs +28 -0
- package/esm/StrategyHealthSnapshot.mjs +11 -0
- package/esm/StrategySubscription.mjs +11 -0
- package/esm/TradingPolicy.mjs +6 -0
- package/esm/User.mjs +11 -0
- package/esm/UserTotp.mjs +14 -0
- package/esm/WaitlistEntry.mjs +14 -0
- package/esm/generated/typeStrings/PolicyOverlay.d.ts +1 -1
- package/esm/generated/typeStrings/PolicyOverlay.mjs +18 -0
- package/esm/generated/typeStrings/TradingPolicy.d.ts +1 -1
- package/esm/generated/typeStrings/TradingPolicy.mjs +18 -0
- package/esm/generated/typeStrings/index.d.ts +2 -2
- package/esm/generated/typegraphql-prisma/enhance.mjs +18 -18
- package/esm/generated/typegraphql-prisma/enums/TradingPolicyScalarFieldEnum.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/enums/TradingPolicyScalarFieldEnum.mjs +1 -0
- package/esm/generated/typegraphql-prisma/models/TradingPolicy.d.ts +20 -0
- package/esm/generated/typegraphql-prisma/models/TradingPolicy.mjs +27 -0
- package/esm/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/FindFirstTradingPolicyArgs.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/FindFirstTradingPolicyOrThrowArgs.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/FindManyTradingPolicyArgs.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/GroupByTradingPolicyArgs.d.ts +1 -1
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCountOrderByAggregateInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCountOrderByAggregateInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateManyInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateManyInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutAlpacaAccountInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutAlpacaAccountInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutOverlaysInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutOverlaysInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithAggregationInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithAggregationInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithRelationInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithRelationInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyScalarWhereWithAggregatesInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyScalarWhereWithAggregatesInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateManyMutationInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateManyMutationInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutAlpacaAccountInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutAlpacaAccountInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutOverlaysInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutOverlaysInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereUniqueInput.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereUniqueInput.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradingPolicy.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradingPolicy.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyCountAggregate.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyCountAggregate.mjs +7 -0
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyGroupBy.d.ts +1 -0
- package/esm/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyGroupBy.mjs +7 -0
- package/esm/index.d.ts +1 -0
- package/esm/index.mjs +2 -0
- package/esm/middleware/mutation-account-facts.d.ts +3 -0
- package/esm/middleware/mutation-account-facts.mjs +2 -0
- package/esm/middleware/trading-policy-audit.d.ts +16 -4
- package/esm/middleware/trading-policy-audit.mjs +40 -11
- package/esm/readers/index.d.ts +10 -0
- package/esm/readers/index.mjs +10 -0
- package/esm/readers/intraday-lane-prefs.d.ts +45 -0
- package/esm/readers/intraday-lane-prefs.mjs +71 -0
- package/esm/tests/trading-policy-lane-fields-roundtrip.harness.d.ts +14 -0
- package/esm/tests/trading-policy-lane-fields-roundtrip.harness.mjs +107 -0
- package/generated/typeStrings/PolicyOverlay.cjs +18 -0
- package/generated/typeStrings/PolicyOverlay.d.ts +1 -1
- package/generated/typeStrings/TradingPolicy.cjs +18 -0
- package/generated/typeStrings/TradingPolicy.d.ts +1 -1
- package/generated/typeStrings/index.d.ts +2 -2
- package/generated/typegraphql-prisma/enhance.cjs +21 -21
- package/generated/typegraphql-prisma/enums/TradingPolicyScalarFieldEnum.cjs +1 -0
- package/generated/typegraphql-prisma/enums/TradingPolicyScalarFieldEnum.d.ts +1 -0
- package/generated/typegraphql-prisma/index.cjs +6 -6
- package/generated/typegraphql-prisma/models/TradingPolicy.cjs +7 -0
- package/generated/typegraphql-prisma/models/TradingPolicy.d.ts +20 -0
- package/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/FindFirstTradingPolicyArgs.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/FindFirstTradingPolicyOrThrowArgs.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/FindManyTradingPolicyArgs.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/TradingPolicy/args/GroupByTradingPolicyArgs.d.ts +1 -1
- package/generated/typegraphql-prisma/resolvers/crud/args.index.cjs +95 -95
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCountOrderByAggregateInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCountOrderByAggregateInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateManyInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateManyInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutAlpacaAccountInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutAlpacaAccountInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutOverlaysInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyCreateWithoutOverlaysInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithAggregationInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithAggregationInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithRelationInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyOrderByWithRelationInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyScalarWhereWithAggregatesInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyScalarWhereWithAggregatesInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateManyMutationInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateManyMutationInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutAlpacaAccountInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutAlpacaAccountInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutOverlaysInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyUpdateWithoutOverlaysInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereUniqueInput.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/inputs/TradingPolicyWhereUniqueInput.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradingPolicy.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/outputs/CreateManyAndReturnTradingPolicy.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyCountAggregate.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyCountAggregate.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyGroupBy.cjs +6 -0
- package/generated/typegraphql-prisma/resolvers/outputs/TradingPolicyGroupBy.d.ts +1 -0
- package/generated/typegraphql-prisma/resolvers/outputs/index.cjs +1 -1
- package/generated/typegraphql-prisma/resolvers/relations/args.index.cjs +32 -32
- package/index.cjs +2 -0
- package/index.d.ts +1 -0
- package/middleware/audit-log-write-redaction.cjs +143 -0
- package/middleware/audit-log-write-redaction.d.ts +82 -0
- package/middleware/audit-logger.cjs +378 -0
- package/middleware/audit-logger.d.ts +158 -0
- package/middleware/audit-payload-guard.cjs +107 -0
- package/middleware/audit-payload-guard.d.ts +85 -0
- package/middleware/auth.cjs +66 -0
- package/middleware/auth.d.ts +41 -0
- package/middleware/credential-field-guard.cjs +514 -0
- package/middleware/credential-field-guard.d.ts +173 -0
- package/middleware/generated-type-names.cjs +77 -0
- package/middleware/generated-type-names.d.ts +44 -0
- package/middleware/graphql-validation-plugin.cjs +310 -0
- package/middleware/graphql-validation-plugin.d.ts +98 -0
- package/middleware/guard-log-throttle.cjs +89 -0
- package/middleware/guard-log-throttle.d.ts +80 -0
- package/middleware/index.cjs +57 -0
- package/middleware/index.d.ts +14 -0
- package/middleware/input-validator.cjs +220 -0
- package/middleware/input-validator.d.ts +63 -0
- package/middleware/mandate-version-validation.cjs +131 -0
- package/middleware/mandate-version-validation.d.ts +41 -0
- package/middleware/mutation-account-facts.cjs +223 -0
- package/middleware/mutation-account-facts.d.ts +143 -0
- package/middleware/mutation-auth-guard.cjs +536 -0
- package/middleware/mutation-auth-guard.d.ts +100 -0
- package/middleware/mutation-membership-facts.cjs +276 -0
- package/middleware/mutation-membership-facts.d.ts +133 -0
- package/middleware/mutation-tenant-facts.cjs +132 -0
- package/middleware/mutation-tenant-facts.d.ts +81 -0
- package/middleware/query-complexity.cjs +182 -0
- package/middleware/query-complexity.d.ts +56 -0
- package/middleware/rate-limiter.cjs +223 -0
- package/middleware/rate-limiter.d.ts +93 -0
- package/middleware/rate-tier.cjs +111 -0
- package/middleware/rate-tier.d.ts +56 -0
- package/middleware/soft-delete.cjs +175 -0
- package/middleware/soft-delete.d.ts +146 -0
- package/middleware/tenancy-scoping.cjs +229 -0
- package/middleware/tenancy-scoping.d.ts +67 -0
- package/middleware/trading-policy-audit.cjs +353 -0
- package/middleware/trading-policy-audit.d.ts +184 -0
- package/middleware/types.cjs +17 -0
- package/middleware/types.d.ts +87 -0
- package/middleware/validation-examples.cjs +398 -0
- package/middleware/validation-examples.d.ts +76 -0
- package/package.json +10 -2
- package/readers/index.cjs +15 -0
- package/readers/index.d.ts +10 -0
- package/readers/intraday-lane-prefs.cjs +76 -0
- package/readers/intraday-lane-prefs.d.ts +45 -0
- package/esm/config/__tests__/server-only-surface.harness.d.ts +0 -12
- package/esm/config/__tests__/server-only-surface.harness.mjs +0 -41
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.d.ts +0 -144
- package/esm/middleware/__tests__/audit-log-write-redaction.harness.mjs +0 -920
- package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts +0 -55
- package/esm/middleware/__tests__/credential-field-coverage.harness.mjs +0 -440
- package/esm/middleware/__tests__/credential-field-guard.harness.d.ts +0 -34
- package/esm/middleware/__tests__/credential-field-guard.harness.mjs +0 -212
- package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +0 -56
- package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +0 -570
- package/esm/middleware/__tests__/rate-limit-test-utils.d.ts +0 -60
- package/esm/middleware/__tests__/rate-limit-test-utils.mjs +0 -85
- package/esm/middleware/__tests__/ts-node-harness.d.ts +0 -10
- package/esm/middleware/__tests__/ts-node-harness.mjs +0 -71
- package/health.cjs +0 -274
- package/server.cjs +0 -607
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORTEX-P0-001 phase 2 — `@Authorized()` coverage for generated CRUD resolvers
|
|
3
|
+
* (audit B01-backend-legacy-03).
|
|
4
|
+
*
|
|
5
|
+
* The `cortexAuthChecker` registered in `buildSchema` is only invoked by
|
|
6
|
+
* TypeGraphQL for fields carrying an `@Authorized()` decorator; the
|
|
7
|
+
* auto-generated typegraphql-prisma resolvers carry none, so the checker was
|
|
8
|
+
* registered-but-inert. This module applies decorators via
|
|
9
|
+
* `applyResolversEnhanceMap`, making the checker actually execute:
|
|
10
|
+
*
|
|
11
|
+
* - FULL coverage (`_all`) for the five investor-relations models —
|
|
12
|
+
* regulated PII (tax documents, KYC status, LP capital ledger) that must
|
|
13
|
+
* never sit on an unauthenticated CRUD surface.
|
|
14
|
+
* - DELETE mutations (`deleteOne*` / `deleteMany*`) for every other model —
|
|
15
|
+
* the most destructive operations on the trading system-of-record.
|
|
16
|
+
*
|
|
17
|
+
* CRITICAL SAFETY CONTRACT — the checker itself remains SHADOW-FIRST: while
|
|
18
|
+
* `CORTEX_AUTHCHECKER_ENFORCE` is OFF (default) a would-deny operation is
|
|
19
|
+
* logged + counted and then ALLOWED, so engine service traffic cannot break.
|
|
20
|
+
* This module only determines WHERE the checker runs, not what it does.
|
|
21
|
+
* Graduation rule (audit B01-backend-legacy-07): enforce only after
|
|
22
|
+
* `cortex_authchecker_evaluations_total` > 0 and the would-deny series has
|
|
23
|
+
* been observed over a full trading week.
|
|
24
|
+
*
|
|
25
|
+
* Must be applied BEFORE `buildSchema` — decorators land in TypeGraphQL's
|
|
26
|
+
* global metadata storage, which `buildSchema` reads.
|
|
27
|
+
*/
|
|
28
|
+
import { type ResolversEnhanceMap } from '../generated/typegraphql-prisma';
|
|
29
|
+
/** Model names accepted by the generated {@link ResolversEnhanceMap}. */
|
|
30
|
+
type EnhanceModelName = keyof ResolversEnhanceMap;
|
|
31
|
+
/**
|
|
32
|
+
* The five investor-relations models receiving FULL (`_all`) coverage:
|
|
33
|
+
* every generated query and mutation on these models invokes the authChecker.
|
|
34
|
+
*/
|
|
35
|
+
export declare const IR_MODELS: readonly EnhanceModelName[];
|
|
36
|
+
/**
|
|
37
|
+
* The trading-desk models, admitted to {@link TENANT_SCOPED_READ_MODELS} at
|
|
38
|
+
* birth. The measurement criterion below exists to find surfaces that were
|
|
39
|
+
* already answering to anyone; these never did. Their row scope is the
|
|
40
|
+
* tenancy predicate in `src/auth/tenancy-scope.ts` (`DESK_MODELS`: a user's
|
|
41
|
+
* own rows for Follow, PushSubscription, UserTotp and an unshared
|
|
42
|
+
* AdaConversation; the fund tenant for DeskDecision, AutoFollowRule and a
|
|
43
|
+
* shared AdaConversation; the user or organization for FeatureFlagOverride),
|
|
44
|
+
* enforced in every mode, with an unauthenticated read refused outright by
|
|
45
|
+
* the tenancy middleware. Decorating them here puts the same reads on the
|
|
46
|
+
* checker's evaluation and would-deny series as the models below.
|
|
47
|
+
*/
|
|
48
|
+
export declare const DESK_READ_MODELS: readonly EnhanceModelName[];
|
|
49
|
+
/**
|
|
50
|
+
* Models whose READ actions are decorated as well as their deletes.
|
|
51
|
+
*
|
|
52
|
+
* These four answer to anyone today. A read-only probe of the deployed API
|
|
53
|
+
* with no Authorization header returns a real organisation name, a real user's
|
|
54
|
+
* email address, and a real membership row, so the standing escalation is not
|
|
55
|
+
* theoretical. They were outside the checker entirely: `_all` covers the five
|
|
56
|
+
* investor-relations models, everything else got delete coverage only, and a
|
|
57
|
+
* query the checker never runs for is a query it cannot even count.
|
|
58
|
+
*
|
|
59
|
+
* `AuditLog` joined them on 2026-09-26, on the same admission criterion and by
|
|
60
|
+
* measurement rather than by inspection. It is the largest of the four by some
|
|
61
|
+
* distance and the only one carrying correlatable personal data: a census of
|
|
62
|
+
* the anonymously readable rows found, across roughly 70,000 rows, at most five
|
|
63
|
+
* distinct email identities, 33 distinct IP addresses, at most four person
|
|
64
|
+
* names and two user agents. Report that as a small number of data subjects
|
|
65
|
+
* with a great many records about each, NOT as a large exposure — the row count
|
|
66
|
+
* is a true number answering a question nobody asked. Note also that 27,964
|
|
67
|
+
* `accountName` rows, first classified as an account label, were hash-matched
|
|
68
|
+
* in-database against the users table to three real email addresses, so
|
|
69
|
+
* per-subject completeness is higher than a field-name reading suggests.
|
|
70
|
+
*
|
|
71
|
+
* Decorating them changes NO behaviour while the checker is in shadow — a
|
|
72
|
+
* would-deny is logged and counted and then allowed. What it changes is that
|
|
73
|
+
* the exposure becomes measurable.
|
|
74
|
+
*
|
|
75
|
+
* `Fund` joined them on 2026-09-27, and it is the one admission that corrects a
|
|
76
|
+
* belief rather than adding a surface. The exposure is an unauthenticated
|
|
77
|
+
* request receiving HTTP 200 with every fund's P&L — measured on the deployed
|
|
78
|
+
* API by Sophie Nguyen at 02:42Z and independently by James Kirkland at
|
|
79
|
+
* 09:46:56Z, not inferred from the schema. `Fund` carries `aum`,
|
|
80
|
+
* `navPerShare` and `highWaterMarkNav`.
|
|
81
|
+
*
|
|
82
|
+
* The belief it corrects: this gap was being treated as something the
|
|
83
|
+
* `CORTEX_AUTHCHECKER_ENFORCE` flip would close. **It would not have.** `Fund`
|
|
84
|
+
* was in neither list, so its reads were never decorated, so the checker never
|
|
85
|
+
* ran for them — and per the paragraph above, a query the checker never runs
|
|
86
|
+
* for is a query it cannot even count. Waiting for the enforcement flip would
|
|
87
|
+
* have closed the four models here and left every fund's P&L answering to
|
|
88
|
+
* anyone, with nothing in the would-deny ratio to show it. Coverage and
|
|
89
|
+
* enforcement are separate axes and only one of them was being tracked.
|
|
90
|
+
*
|
|
91
|
+
* `FundAssignment` is a candidate and is deliberately NOT admitted here. It
|
|
92
|
+
* reveals which accounts belong to which fund, which is structural rather than
|
|
93
|
+
* P&L, and no anonymous probe of it has been run. Admitting it on inspection
|
|
94
|
+
* would break the criterion this list is built on — by measurement, not by
|
|
95
|
+
* reading the schema. Measure it, then admit it. Enforcement cannot be argued from a
|
|
96
|
+
* would-deny ratio that reflects only surfaces nobody ever authenticated to,
|
|
97
|
+
* and the measurement has to exist before the decision does.
|
|
98
|
+
*/
|
|
99
|
+
export declare const TENANT_SCOPED_READ_MODELS: readonly EnhanceModelName[];
|
|
100
|
+
/** Summary of the coverage applied, for the boot log and tests. */
|
|
101
|
+
export interface AuthorizationMapSummary {
|
|
102
|
+
/** Models decorated with `_all` (full CRUD coverage). */
|
|
103
|
+
readonly fullCoverageModels: number;
|
|
104
|
+
/** Models whose delete mutations were decorated. */
|
|
105
|
+
readonly deleteCoverageModels: number;
|
|
106
|
+
/** Models whose READ actions were decorated as well ({@link TENANT_SCOPED_READ_MODELS}). */
|
|
107
|
+
readonly readCoverageModels: number;
|
|
108
|
+
/** Total decorated resolver actions (delete actions + `_all` markers). */
|
|
109
|
+
readonly decoratedActions: number;
|
|
110
|
+
/**
|
|
111
|
+
* Delete-action names skipped because the generated CRUD resolver does not
|
|
112
|
+
* expose them — non-empty output means the naming convention drifted and the
|
|
113
|
+
* map must be updated. Never silently ignored: logged at warn on apply.
|
|
114
|
+
*/
|
|
115
|
+
readonly skippedActions: readonly string[];
|
|
116
|
+
}
|
|
117
|
+
/** Internal build output: the map plus its audit summary. */
|
|
118
|
+
interface BuiltAuthorizationMap {
|
|
119
|
+
readonly map: ResolversEnhanceMap;
|
|
120
|
+
readonly summary: AuthorizationMapSummary;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Builds the CORTEX authorization enhance-map. Pure (no metadata mutation) so
|
|
124
|
+
* tests can pin its contents without touching TypeGraphQL global state.
|
|
125
|
+
*
|
|
126
|
+
* @returns The enhance map and a summary of the coverage it encodes.
|
|
127
|
+
*/
|
|
128
|
+
export declare function buildCortexAuthorizationMap(): BuiltAuthorizationMap;
|
|
129
|
+
/**
|
|
130
|
+
* Applies the CORTEX authorization map to the generated resolvers. Idempotent:
|
|
131
|
+
* decorators land in TypeGraphQL's global metadata storage, so applying twice
|
|
132
|
+
* would duplicate `Authorized` metadata — subsequent calls return the cached
|
|
133
|
+
* summary without re-applying.
|
|
134
|
+
*
|
|
135
|
+
* Call BEFORE `buildSchema`. The registered `cortexAuthChecker` stays
|
|
136
|
+
* SHADOW-FIRST (log + count + allow) until `CORTEX_AUTHCHECKER_ENFORCE` is
|
|
137
|
+
* explicitly flipped on.
|
|
138
|
+
*
|
|
139
|
+
* @returns The {@link AuthorizationMapSummary} for the boot log.
|
|
140
|
+
*/
|
|
141
|
+
export declare function applyCortexAuthorizationMap(): AuthorizationMapSummary;
|
|
142
|
+
export {};
|
|
143
|
+
//# sourceMappingURL=authorization-map.d.ts.map
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* CORTEX-P0-001 — resolver-level authorization AuthChecker (SHADOW-FIRST).
|
|
4
|
+
*
|
|
5
|
+
* A TypeGraphQL {@link AuthChecker} that evaluates whether an operation WOULD be
|
|
6
|
+
* allowed under resolver-level authorization, closing the residual vector called
|
|
7
|
+
* out in the tenancy-scoping middleware docs: a governed model reached
|
|
8
|
+
* transitively through a non-governed root, and — more broadly — any
|
|
9
|
+
* `@Authorized()`-decorated field executed without a verified principal.
|
|
10
|
+
*
|
|
11
|
+
* CRITICAL SAFETY CONTRACT — this change is additive and default-OFF. When
|
|
12
|
+
* enforcement is OFF (the default), the checker NEVER denies: it returns `true`
|
|
13
|
+
* for every operation, emitting a structured warn log and incrementing a
|
|
14
|
+
* Prometheus counter for any operation that enforcement WOULD deny. Live
|
|
15
|
+
* behaviour is byte-identical to before this change until
|
|
16
|
+
* `CORTEX_AUTHCHECKER_ENFORCE` is flipped on. Additionally, TypeGraphQL only
|
|
17
|
+
* invokes an AuthChecker for fields decorated with `@Authorized()`; the
|
|
18
|
+
* auto-generated typegraphql-prisma resolvers carry no such decorator, so
|
|
19
|
+
* registering this checker via `buildSchema({ authChecker })` is inert at
|
|
20
|
+
* runtime until decorators are added in the separate enforcement phase.
|
|
21
|
+
*
|
|
22
|
+
* Decision model (mirrors the token-verifier principal kinds):
|
|
23
|
+
*
|
|
24
|
+
* - `server` — trusted server-to-server caller. ALWAYS allowed; the
|
|
25
|
+
* engine + utils call the CRUD resolvers with a server principal and must
|
|
26
|
+
* retain full access, bypassing any role gate.
|
|
27
|
+
* - `admin` / `user` — verified end-user. Allowed when the field requires no
|
|
28
|
+
* specific role, or when the principal carries one of the required roles;
|
|
29
|
+
* otherwise a would-deny with reason `insufficient_role`.
|
|
30
|
+
* - `null` (no verified principal) — a genuinely unauthenticated caller on a
|
|
31
|
+
* non-public (i.e. `@Authorized()`) operation. A would-deny with reason
|
|
32
|
+
* `unauthenticated`.
|
|
33
|
+
*
|
|
34
|
+
* @see src/auth/tenancy-scope.ts for the row-level (data-scope) counterpart.
|
|
35
|
+
* @see src/auth/token-verifier.ts for `BackendPrincipal`.
|
|
36
|
+
*/
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.cortexAuthChecker = exports.cortexAuthCheckerWouldDenyTotal = exports.cortexAuthCheckerEvaluationsTotal = exports.CORTEX_AUTHCHECKER_ENFORCE_ENV = void 0;
|
|
39
|
+
exports.isAuthCheckerEnforced = isAuthCheckerEnforced;
|
|
40
|
+
exports.evaluateWouldAllow = evaluateWouldAllow;
|
|
41
|
+
const prom_client_1 = require("prom-client");
|
|
42
|
+
const metrics_1 = require("../config/metrics.cjs");
|
|
43
|
+
const logger_1 = require("../utils/logger.cjs");
|
|
44
|
+
// -----------------------------------------------------------------------------
|
|
45
|
+
// Enforcement flag
|
|
46
|
+
// -----------------------------------------------------------------------------
|
|
47
|
+
/**
|
|
48
|
+
* Environment variable gating enforcement. When set to `true`/`1`, the checker
|
|
49
|
+
* fails closed (returns `false`) for any would-deny operation. Unset or any
|
|
50
|
+
* other value keeps the checker in SHADOW mode (observe + count + allow).
|
|
51
|
+
*/
|
|
52
|
+
exports.CORTEX_AUTHCHECKER_ENFORCE_ENV = 'CORTEX_AUTHCHECKER_ENFORCE';
|
|
53
|
+
/** The `admin` role string used to satisfy admin-gated `@Authorized()` fields. */
|
|
54
|
+
const ADMIN_ROLE = 'admin';
|
|
55
|
+
/**
|
|
56
|
+
* Whether resolver-level authorization enforcement is ON. Read fresh on each
|
|
57
|
+
* call (a cheap env read) so the shadow→enforce graduation can be flipped
|
|
58
|
+
* operationally without a process restart — the same pattern the tenancy-scoping
|
|
59
|
+
* middleware uses. Defaults to OFF (shadow) for any unset/unrecognised value.
|
|
60
|
+
*
|
|
61
|
+
* @param env - Environment source (defaults to `process.env`); injectable for tests.
|
|
62
|
+
* @returns `true` only when the flag is explicitly `true`/`1`.
|
|
63
|
+
*/
|
|
64
|
+
function isAuthCheckerEnforced(env = process.env) {
|
|
65
|
+
var _a;
|
|
66
|
+
const raw = ((_a = env[exports.CORTEX_AUTHCHECKER_ENFORCE_ENV]) !== null && _a !== void 0 ? _a : '').trim().toLowerCase();
|
|
67
|
+
return raw === 'true' || raw === '1';
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Counts EVERY AuthChecker invocation, regardless of outcome (audit
|
|
71
|
+
* B01-backend-legacy-07). A flat-zero {@link cortexAuthCheckerWouldDenyTotal}
|
|
72
|
+
* is ambiguous on its own: it can mean "no traffic would be denied" OR "the
|
|
73
|
+
* checker never ran" (no `@Authorized()` field was ever executed) — exactly the
|
|
74
|
+
* false-confidence pattern that preceded the beta-net-cap fail-open. Graduation
|
|
75
|
+
* rule: enforce only when this counter is > 0 and the would-deny series has
|
|
76
|
+
* been observed over a full trading week.
|
|
77
|
+
*/
|
|
78
|
+
exports.cortexAuthCheckerEvaluationsTotal = new prom_client_1.Counter({
|
|
79
|
+
name: 'cortex_authchecker_evaluations_total',
|
|
80
|
+
help: 'Total AuthChecker invocations, any outcome (zero means no @Authorized field was executed — distinct from "no would-denies")',
|
|
81
|
+
registers: [metrics_1.metricsRegistry],
|
|
82
|
+
});
|
|
83
|
+
/**
|
|
84
|
+
* Counts operations that resolver-level authorization WOULD deny. In shadow mode
|
|
85
|
+
* this is the primary signal proving whether flipping `CORTEX_AUTHCHECKER_ENFORCE`
|
|
86
|
+
* to `enforce` would reject any legitimate platform or engine traffic. Labelled
|
|
87
|
+
* by the discriminated {@link WouldDenyReason}.
|
|
88
|
+
*/
|
|
89
|
+
exports.cortexAuthCheckerWouldDenyTotal = new prom_client_1.Counter({
|
|
90
|
+
name: 'cortex_authchecker_would_deny_total',
|
|
91
|
+
help: 'Operations resolver-level authorization would deny, by reason (counted in shadow mode without denying)',
|
|
92
|
+
labelNames: ['reason'],
|
|
93
|
+
registers: [metrics_1.metricsRegistry],
|
|
94
|
+
});
|
|
95
|
+
/**
|
|
96
|
+
* Pure evaluation of whether a principal would satisfy the required roles for an
|
|
97
|
+
* operation. Performs no I/O and no logging.
|
|
98
|
+
*
|
|
99
|
+
* @param principal - The verified principal, or `null` for an unauthenticated caller.
|
|
100
|
+
* @param requiredRoles - Roles declared on the field's `@Authorized(...)` decorator
|
|
101
|
+
* (empty when the field only requires authentication).
|
|
102
|
+
* @returns The {@link AuthEvaluation}.
|
|
103
|
+
*/
|
|
104
|
+
function evaluateWouldAllow(principal, requiredRoles) {
|
|
105
|
+
if (!principal) {
|
|
106
|
+
return { wouldAllow: false, reason: 'unauthenticated' };
|
|
107
|
+
}
|
|
108
|
+
// Server-to-server callers are unconditionally allowed and bypass role gates.
|
|
109
|
+
if (principal.kind === 'server') {
|
|
110
|
+
return { wouldAllow: true };
|
|
111
|
+
}
|
|
112
|
+
// Authenticated user/admin with no specific role requirement -> allowed.
|
|
113
|
+
if (requiredRoles.length === 0) {
|
|
114
|
+
return { wouldAllow: true };
|
|
115
|
+
}
|
|
116
|
+
const principalRoles = principal.kind === 'admin'
|
|
117
|
+
? [...principal.roles, ADMIN_ROLE]
|
|
118
|
+
: principal.roles;
|
|
119
|
+
const roleSet = new Set(principalRoles);
|
|
120
|
+
const hasRequiredRole = requiredRoles.some((role) => roleSet.has(role));
|
|
121
|
+
return hasRequiredRole
|
|
122
|
+
? { wouldAllow: true }
|
|
123
|
+
: { wouldAllow: false, reason: 'insufficient_role' };
|
|
124
|
+
}
|
|
125
|
+
/** Describe an operation for structured logs, without leaking arguments. */
|
|
126
|
+
function describeOperation(resolverData) {
|
|
127
|
+
var _a, _b;
|
|
128
|
+
const { info } = resolverData;
|
|
129
|
+
return {
|
|
130
|
+
operationType: info.operation.operation,
|
|
131
|
+
operationName: (_b = (_a = info.operation.name) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : info.fieldName,
|
|
132
|
+
field: info.fieldName,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The CORTEX-P0-001 AuthChecker. Register via
|
|
137
|
+
* `buildSchema({ authChecker: cortexAuthChecker })`.
|
|
138
|
+
*
|
|
139
|
+
* SHADOW (default): a would-deny operation increments
|
|
140
|
+
* {@link cortexAuthCheckerWouldDenyTotal}, emits a warn log, and RETURNS TRUE —
|
|
141
|
+
* no behaviour change. ENFORCE (`CORTEX_AUTHCHECKER_ENFORCE=true`): a would-deny
|
|
142
|
+
* operation is logged, the counter is incremented, and the checker RETURNS FALSE
|
|
143
|
+
* (fail closed). Operations that would be allowed always return `true` with no
|
|
144
|
+
* metric or log emission.
|
|
145
|
+
*/
|
|
146
|
+
const cortexAuthChecker = (resolverData, roles) => {
|
|
147
|
+
var _a, _b, _c;
|
|
148
|
+
// Unconditional: proves the checker is actually reachable (see
|
|
149
|
+
// cortexAuthCheckerEvaluationsTotal TSDoc / audit B01-backend-legacy-07).
|
|
150
|
+
exports.cortexAuthCheckerEvaluationsTotal.inc();
|
|
151
|
+
const principal = (_a = resolverData.context.principal) !== null && _a !== void 0 ? _a : null;
|
|
152
|
+
const evaluation = evaluateWouldAllow(principal, roles);
|
|
153
|
+
if (evaluation.wouldAllow) {
|
|
154
|
+
return true;
|
|
155
|
+
}
|
|
156
|
+
const reason = (_b = evaluation.reason) !== null && _b !== void 0 ? _b : 'unauthenticated';
|
|
157
|
+
const enforced = isAuthCheckerEnforced();
|
|
158
|
+
const operation = describeOperation(resolverData);
|
|
159
|
+
exports.cortexAuthCheckerWouldDenyTotal.inc({ reason });
|
|
160
|
+
logger_1.logger.warn(enforced
|
|
161
|
+
? '[cortex-authchecker] denying operation (enforce)'
|
|
162
|
+
: '[cortex-authchecker] shadow would-deny (allowing)', {
|
|
163
|
+
...operation,
|
|
164
|
+
reason,
|
|
165
|
+
enforced,
|
|
166
|
+
principalKind: (_c = principal === null || principal === void 0 ? void 0 : principal.kind) !== null && _c !== void 0 ? _c : 'none',
|
|
167
|
+
requiredRoles: [...roles],
|
|
168
|
+
});
|
|
169
|
+
return !enforced;
|
|
170
|
+
};
|
|
171
|
+
exports.cortexAuthChecker = cortexAuthChecker;
|
|
172
|
+
//# sourceMappingURL=cortex-auth-checker.js.map
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CORTEX-P0-001 — resolver-level authorization AuthChecker (SHADOW-FIRST).
|
|
3
|
+
*
|
|
4
|
+
* A TypeGraphQL {@link AuthChecker} that evaluates whether an operation WOULD be
|
|
5
|
+
* allowed under resolver-level authorization, closing the residual vector called
|
|
6
|
+
* out in the tenancy-scoping middleware docs: a governed model reached
|
|
7
|
+
* transitively through a non-governed root, and — more broadly — any
|
|
8
|
+
* `@Authorized()`-decorated field executed without a verified principal.
|
|
9
|
+
*
|
|
10
|
+
* CRITICAL SAFETY CONTRACT — this change is additive and default-OFF. When
|
|
11
|
+
* enforcement is OFF (the default), the checker NEVER denies: it returns `true`
|
|
12
|
+
* for every operation, emitting a structured warn log and incrementing a
|
|
13
|
+
* Prometheus counter for any operation that enforcement WOULD deny. Live
|
|
14
|
+
* behaviour is byte-identical to before this change until
|
|
15
|
+
* `CORTEX_AUTHCHECKER_ENFORCE` is flipped on. Additionally, TypeGraphQL only
|
|
16
|
+
* invokes an AuthChecker for fields decorated with `@Authorized()`; the
|
|
17
|
+
* auto-generated typegraphql-prisma resolvers carry no such decorator, so
|
|
18
|
+
* registering this checker via `buildSchema({ authChecker })` is inert at
|
|
19
|
+
* runtime until decorators are added in the separate enforcement phase.
|
|
20
|
+
*
|
|
21
|
+
* Decision model (mirrors the token-verifier principal kinds):
|
|
22
|
+
*
|
|
23
|
+
* - `server` — trusted server-to-server caller. ALWAYS allowed; the
|
|
24
|
+
* engine + utils call the CRUD resolvers with a server principal and must
|
|
25
|
+
* retain full access, bypassing any role gate.
|
|
26
|
+
* - `admin` / `user` — verified end-user. Allowed when the field requires no
|
|
27
|
+
* specific role, or when the principal carries one of the required roles;
|
|
28
|
+
* otherwise a would-deny with reason `insufficient_role`.
|
|
29
|
+
* - `null` (no verified principal) — a genuinely unauthenticated caller on a
|
|
30
|
+
* non-public (i.e. `@Authorized()`) operation. A would-deny with reason
|
|
31
|
+
* `unauthenticated`.
|
|
32
|
+
*
|
|
33
|
+
* @see src/auth/tenancy-scope.ts for the row-level (data-scope) counterpart.
|
|
34
|
+
* @see src/auth/token-verifier.ts for `BackendPrincipal`.
|
|
35
|
+
*/
|
|
36
|
+
import { Counter } from 'prom-client';
|
|
37
|
+
import type { AuthChecker } from 'type-graphql';
|
|
38
|
+
import type { BackendPrincipal } from './token-verifier';
|
|
39
|
+
/**
|
|
40
|
+
* Environment variable gating enforcement. When set to `true`/`1`, the checker
|
|
41
|
+
* fails closed (returns `false`) for any would-deny operation. Unset or any
|
|
42
|
+
* other value keeps the checker in SHADOW mode (observe + count + allow).
|
|
43
|
+
*/
|
|
44
|
+
export declare const CORTEX_AUTHCHECKER_ENFORCE_ENV = "CORTEX_AUTHCHECKER_ENFORCE";
|
|
45
|
+
/**
|
|
46
|
+
* Whether resolver-level authorization enforcement is ON. Read fresh on each
|
|
47
|
+
* call (a cheap env read) so the shadow→enforce graduation can be flipped
|
|
48
|
+
* operationally without a process restart — the same pattern the tenancy-scoping
|
|
49
|
+
* middleware uses. Defaults to OFF (shadow) for any unset/unrecognised value.
|
|
50
|
+
*
|
|
51
|
+
* @param env - Environment source (defaults to `process.env`); injectable for tests.
|
|
52
|
+
* @returns `true` only when the flag is explicitly `true`/`1`.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isAuthCheckerEnforced(env?: Record<string, string | undefined>): boolean;
|
|
55
|
+
/**
|
|
56
|
+
* Finite set of reasons enforcement WOULD deny an operation. Used as the sole
|
|
57
|
+
* label on {@link cortexAuthCheckerWouldDenyTotal}.
|
|
58
|
+
*/
|
|
59
|
+
export type WouldDenyReason = 'unauthenticated' | 'insufficient_role';
|
|
60
|
+
/**
|
|
61
|
+
* Counts EVERY AuthChecker invocation, regardless of outcome (audit
|
|
62
|
+
* B01-backend-legacy-07). A flat-zero {@link cortexAuthCheckerWouldDenyTotal}
|
|
63
|
+
* is ambiguous on its own: it can mean "no traffic would be denied" OR "the
|
|
64
|
+
* checker never ran" (no `@Authorized()` field was ever executed) — exactly the
|
|
65
|
+
* false-confidence pattern that preceded the beta-net-cap fail-open. Graduation
|
|
66
|
+
* rule: enforce only when this counter is > 0 and the would-deny series has
|
|
67
|
+
* been observed over a full trading week.
|
|
68
|
+
*/
|
|
69
|
+
export declare const cortexAuthCheckerEvaluationsTotal: Counter<string>;
|
|
70
|
+
/**
|
|
71
|
+
* Counts operations that resolver-level authorization WOULD deny. In shadow mode
|
|
72
|
+
* this is the primary signal proving whether flipping `CORTEX_AUTHCHECKER_ENFORCE`
|
|
73
|
+
* to `enforce` would reject any legitimate platform or engine traffic. Labelled
|
|
74
|
+
* by the discriminated {@link WouldDenyReason}.
|
|
75
|
+
*/
|
|
76
|
+
export declare const cortexAuthCheckerWouldDenyTotal: Counter<"reason">;
|
|
77
|
+
/** The outcome of evaluating whether an operation would be allowed. */
|
|
78
|
+
interface AuthEvaluation {
|
|
79
|
+
readonly wouldAllow: boolean;
|
|
80
|
+
/** Populated only when `wouldAllow` is `false`. */
|
|
81
|
+
readonly reason?: WouldDenyReason;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Pure evaluation of whether a principal would satisfy the required roles for an
|
|
85
|
+
* operation. Performs no I/O and no logging.
|
|
86
|
+
*
|
|
87
|
+
* @param principal - The verified principal, or `null` for an unauthenticated caller.
|
|
88
|
+
* @param requiredRoles - Roles declared on the field's `@Authorized(...)` decorator
|
|
89
|
+
* (empty when the field only requires authentication).
|
|
90
|
+
* @returns The {@link AuthEvaluation}.
|
|
91
|
+
*/
|
|
92
|
+
export declare function evaluateWouldAllow(principal: BackendPrincipal | null, requiredRoles: readonly string[]): AuthEvaluation;
|
|
93
|
+
/**
|
|
94
|
+
* GraphQL context shape this checker reads. `principal` is the verified
|
|
95
|
+
* `BackendPrincipal` attached to the context in `server.ts` (`null` for an
|
|
96
|
+
* unauthenticated caller).
|
|
97
|
+
*/
|
|
98
|
+
export interface CortexAuthContext {
|
|
99
|
+
principal?: BackendPrincipal | null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The CORTEX-P0-001 AuthChecker. Register via
|
|
103
|
+
* `buildSchema({ authChecker: cortexAuthChecker })`.
|
|
104
|
+
*
|
|
105
|
+
* SHADOW (default): a would-deny operation increments
|
|
106
|
+
* {@link cortexAuthCheckerWouldDenyTotal}, emits a warn log, and RETURNS TRUE —
|
|
107
|
+
* no behaviour change. ENFORCE (`CORTEX_AUTHCHECKER_ENFORCE=true`): a would-deny
|
|
108
|
+
* operation is logged, the counter is incremented, and the checker RETURNS FALSE
|
|
109
|
+
* (fail closed). Operations that would be allowed always return `true` with no
|
|
110
|
+
* metric or log emission.
|
|
111
|
+
*/
|
|
112
|
+
export declare const cortexAuthChecker: AuthChecker<CortexAuthContext>;
|
|
113
|
+
export {};
|
|
114
|
+
//# sourceMappingURL=cortex-auth-checker.d.ts.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The stored credential columns, by Prisma model.
|
|
4
|
+
*
|
|
5
|
+
* One vocabulary for every place that has to know what a credential is: the
|
|
6
|
+
* credential-field guard (what may be read, filtered or grouped on), the
|
|
7
|
+
* redaction applied to audit payloads on write, and the redaction applied to
|
|
8
|
+
* audit payloads on read. It lives in a module that imports nothing, so each
|
|
9
|
+
* of those can depend on it without depending on the others.
|
|
10
|
+
*
|
|
11
|
+
* @module auth/credential-fields
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.CREDENTIAL_FIELDS = void 0;
|
|
15
|
+
/**
|
|
16
|
+
* Every stored credential column, by Prisma model. A column belongs here when
|
|
17
|
+
* its value lets the holder act as someone: a broker or vendor API secret, an
|
|
18
|
+
* OAuth access / refresh / id token, a session token, a one-time verification
|
|
19
|
+
* or invite token.
|
|
20
|
+
*/
|
|
21
|
+
exports.CREDENTIAL_FIELDS = new Map([
|
|
22
|
+
['AlpacaAccount', new Set(['APIKey', 'APISecret'])],
|
|
23
|
+
['BrokerageAccount', new Set(['apiKey', 'apiSecret'])],
|
|
24
|
+
[
|
|
25
|
+
'LlmConfiguration',
|
|
26
|
+
new Set([
|
|
27
|
+
'openaiApiKey',
|
|
28
|
+
'anthropicApiKey',
|
|
29
|
+
'deepseekApiKey',
|
|
30
|
+
'kimiApiKey',
|
|
31
|
+
'qwenApiKey',
|
|
32
|
+
'xaiApiKey',
|
|
33
|
+
'geminiApiKey',
|
|
34
|
+
'deepinfraApiKey',
|
|
35
|
+
]),
|
|
36
|
+
],
|
|
37
|
+
['User', new Set(['openaiAPIKey'])],
|
|
38
|
+
['Account', new Set(['refresh_token', 'access_token', 'id_token'])],
|
|
39
|
+
['LinkedProvider', new Set(['accessToken', 'refreshToken'])],
|
|
40
|
+
['Session', new Set(['sessionToken'])],
|
|
41
|
+
['VerificationToken', new Set(['token'])],
|
|
42
|
+
['AccountLinkingRequest', new Set(['verificationToken'])],
|
|
43
|
+
['InviteToken', new Set(['token'])],
|
|
44
|
+
// The TOTP secret (encrypted, but decryptable by whoever holds the key) and
|
|
45
|
+
// the recovery-code hashes are a second factor. The schema already omits
|
|
46
|
+
// them from every output and predicate type; listing them here also keeps
|
|
47
|
+
// them out of `groupBy` / `distinct` for non-service callers and redacts
|
|
48
|
+
// them from audit payloads copied from mutation variables.
|
|
49
|
+
['UserTotp', new Set(['secretEnc', 'recoveryCodesHash'])],
|
|
50
|
+
]);
|
|
51
|
+
//# sourceMappingURL=credential-fields.js.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The stored credential columns, by Prisma model.
|
|
3
|
+
*
|
|
4
|
+
* One vocabulary for every place that has to know what a credential is: the
|
|
5
|
+
* credential-field guard (what may be read, filtered or grouped on), the
|
|
6
|
+
* redaction applied to audit payloads on write, and the redaction applied to
|
|
7
|
+
* audit payloads on read. It lives in a module that imports nothing, so each
|
|
8
|
+
* of those can depend on it without depending on the others.
|
|
9
|
+
*
|
|
10
|
+
* @module auth/credential-fields
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* Every stored credential column, by Prisma model. A column belongs here when
|
|
14
|
+
* its value lets the holder act as someone: a broker or vendor API secret, an
|
|
15
|
+
* OAuth access / refresh / id token, a session token, a one-time verification
|
|
16
|
+
* or invite token.
|
|
17
|
+
*/
|
|
18
|
+
export declare const CREDENTIAL_FIELDS: ReadonlyMap<string, ReadonlySet<string>>;
|
|
19
|
+
//# sourceMappingURL=credential-fields.d.ts.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Redact stored-credential values from a payload before it is persisted or
|
|
4
|
+
* logged.
|
|
5
|
+
*
|
|
6
|
+
* The audit trail records what a mutation asked for, and a mutation that
|
|
7
|
+
* writes a broker key carries the key in its arguments. An audit row is read
|
|
8
|
+
* by far more people and processes than the credential column itself, so a
|
|
9
|
+
* credential copied into one is a second, unguarded copy of the secret. Every
|
|
10
|
+
* `AuditLog` write passes through here before it is stored, whoever makes it:
|
|
11
|
+
* the server's Prisma client applies it to each row an `AuditLog` operation
|
|
12
|
+
* writes (`middleware/audit-log-write-redaction`), so a writer that forgets to
|
|
13
|
+
* redact cannot store a key. The audit payload guard
|
|
14
|
+
* (`middleware/audit-payload-guard`) applies the same rule when a row is read,
|
|
15
|
+
* which also covers rows stored before any writer redacted.
|
|
16
|
+
*
|
|
17
|
+
* Key-directed rather than type-directed on purpose: audit payloads are
|
|
18
|
+
* persisted as JSON with no GraphQL type attached, and over-redacting a
|
|
19
|
+
* non-secret that shares a credential column's name costs an audit reader one
|
|
20
|
+
* field, while under-redacting leaks a key. The key set is exactly the
|
|
21
|
+
* credential columns {@link CREDENTIAL_FIELDS} guards on the read side.
|
|
22
|
+
*
|
|
23
|
+
* @module auth/credential-redaction
|
|
24
|
+
*/
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.CREDENTIAL_KEY_NAMES = exports.REDACTED = void 0;
|
|
27
|
+
exports.redactCredentials = redactCredentials;
|
|
28
|
+
exports.credentialKeyPaths = credentialKeyPaths;
|
|
29
|
+
// From the leaf module, not the guard: the guard redacts audit payloads on
|
|
30
|
+
// read, so importing it here would make the two modules import each other.
|
|
31
|
+
const credential_fields_1 = require("./credential-fields.cjs");
|
|
32
|
+
/** The placeholder a redacted value is replaced with. */
|
|
33
|
+
exports.REDACTED = '[REDACTED]';
|
|
34
|
+
/** Deepest nesting walked; anything deeper is replaced wholesale. */
|
|
35
|
+
const MAX_DEPTH = 12;
|
|
36
|
+
/** Every credential column name across all models. */
|
|
37
|
+
exports.CREDENTIAL_KEY_NAMES = new Set([...credential_fields_1.CREDENTIAL_FIELDS.values()].flatMap((fields) => [...fields]));
|
|
38
|
+
/**
|
|
39
|
+
* Whether `value` is Prisma's field-update form of an absent value: an object
|
|
40
|
+
* whose only key is `set`, holding `null` or nothing. `{ set: null }` is how a
|
|
41
|
+
* Prisma update clears a nullable column, and the generated CRUD functions
|
|
42
|
+
* send every clear in that form (`removeUndefinedProps` in `src/utils.ts`
|
|
43
|
+
* keeps it for that reason), so it is the same statement as a bare `null`.
|
|
44
|
+
*/
|
|
45
|
+
function isClearingUpdate(value) {
|
|
46
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value))
|
|
47
|
+
return false;
|
|
48
|
+
const keys = Object.keys(value);
|
|
49
|
+
if (keys.length !== 1 || keys[0] !== 'set')
|
|
50
|
+
return false;
|
|
51
|
+
const assigned = value.set;
|
|
52
|
+
return assigned === null || assigned === undefined;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Whether a credential key's value holds nothing: absent, `null`, or a
|
|
56
|
+
* clearing update ({@link isClearingUpdate}). Such a value discloses nothing,
|
|
57
|
+
* and replacing it would make a revoke read like a rotation.
|
|
58
|
+
*/
|
|
59
|
+
function holdsNoValue(value) {
|
|
60
|
+
if (value === null || value === undefined)
|
|
61
|
+
return true;
|
|
62
|
+
return isClearingUpdate(value);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* A deep copy of `value` with every credential-named key's value replaced by
|
|
66
|
+
* {@link REDACTED}. A credential value that holds nothing (absent, `null`, or
|
|
67
|
+
* an update's `{ set: null }`) is kept as-is, so the audit row still shows
|
|
68
|
+
* whether a credential was set, cleared or untouched.
|
|
69
|
+
*
|
|
70
|
+
* @param value - Any JSON-shaped value.
|
|
71
|
+
* @returns The redacted copy.
|
|
72
|
+
*/
|
|
73
|
+
function redactCredentials(value, depth = 0) {
|
|
74
|
+
if (value === null || value === undefined)
|
|
75
|
+
return value;
|
|
76
|
+
if (depth >= MAX_DEPTH)
|
|
77
|
+
return exports.REDACTED;
|
|
78
|
+
if (Array.isArray(value))
|
|
79
|
+
return value.map((item) => redactCredentials(item, depth + 1));
|
|
80
|
+
if (typeof value !== 'object')
|
|
81
|
+
return value;
|
|
82
|
+
if (value instanceof Date)
|
|
83
|
+
return value.toISOString();
|
|
84
|
+
const out = {};
|
|
85
|
+
for (const [key, child] of Object.entries(value)) {
|
|
86
|
+
out[key] =
|
|
87
|
+
exports.CREDENTIAL_KEY_NAMES.has(key) && !holdsNoValue(child)
|
|
88
|
+
? exports.REDACTED
|
|
89
|
+
: redactCredentials(child, depth + 1);
|
|
90
|
+
}
|
|
91
|
+
return out;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Every place {@link redactCredentials} replaces a value in `value`, in
|
|
95
|
+
* traversal order. It walks by the same rules (credential key names, the
|
|
96
|
+
* exemption for a value that holds nothing, the depth limit), so it is empty
|
|
97
|
+
* exactly when redaction leaves the payload as it was. Paths name keys only,
|
|
98
|
+
* never values.
|
|
99
|
+
*
|
|
100
|
+
* @param value - Any JSON-shaped value.
|
|
101
|
+
* @returns The replaced locations.
|
|
102
|
+
*/
|
|
103
|
+
function credentialKeyPaths(value, depth = 0, path = '') {
|
|
104
|
+
if (value === null || value === undefined)
|
|
105
|
+
return [];
|
|
106
|
+
if (depth >= MAX_DEPTH)
|
|
107
|
+
return [{ path: path || '<root>', carriesValue: carriesValue(value) }];
|
|
108
|
+
if (Array.isArray(value)) {
|
|
109
|
+
return value.flatMap((item, index) => credentialKeyPaths(item, depth + 1, joinPath(path, String(index))));
|
|
110
|
+
}
|
|
111
|
+
if (typeof value !== 'object' || value instanceof Date)
|
|
112
|
+
return [];
|
|
113
|
+
return Object.entries(value).flatMap(([key, child]) => exports.CREDENTIAL_KEY_NAMES.has(key) && !holdsNoValue(child)
|
|
114
|
+
? [{ path: joinPath(path, key), carriesValue: carriesValue(child) }]
|
|
115
|
+
: credentialKeyPaths(child, depth + 1, joinPath(path, key)));
|
|
116
|
+
}
|
|
117
|
+
function joinPath(parent, key) {
|
|
118
|
+
return parent === '' ? key : `${parent}.${key}`;
|
|
119
|
+
}
|
|
120
|
+
/** Whether `value` holds a non-empty string, a number or a boolean anywhere. */
|
|
121
|
+
function carriesValue(value, depth = 0) {
|
|
122
|
+
if (value === null || value === undefined)
|
|
123
|
+
return false;
|
|
124
|
+
if (typeof value === 'string')
|
|
125
|
+
return value.length > 0;
|
|
126
|
+
if (typeof value !== 'object')
|
|
127
|
+
return true;
|
|
128
|
+
// Too deep to inspect: assume it does, as the redaction assumes it must.
|
|
129
|
+
if (depth >= MAX_DEPTH)
|
|
130
|
+
return true;
|
|
131
|
+
const children = Array.isArray(value) ? value : Object.values(value);
|
|
132
|
+
return children.some((child) => carriesValue(child, depth + 1));
|
|
133
|
+
}
|
|
134
|
+
//# sourceMappingURL=credential-redaction.js.map
|