@adaptic/backend 0.0.1037 → 0.0.1039
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/esm/auth/credential-fields.d.ts +19 -0
- package/esm/auth/credential-fields.d.ts.map +1 -0
- package/esm/auth/credential-fields.js.map +1 -0
- package/esm/auth/credential-fields.mjs +42 -0
- package/esm/auth/credential-redaction.d.ts +56 -0
- package/esm/auth/credential-redaction.d.ts.map +1 -0
- package/esm/auth/credential-redaction.js.map +1 -0
- package/esm/auth/credential-redaction.mjs +99 -0
- package/esm/auth/mutation-authorization.d.ts +206 -0
- package/esm/auth/mutation-authorization.d.ts.map +1 -0
- package/esm/auth/mutation-authorization.js.map +1 -0
- package/esm/auth/mutation-authorization.mjs +271 -0
- package/esm/auth/nested-write-inspector.d.ts +94 -0
- package/esm/auth/nested-write-inspector.d.ts.map +1 -0
- package/esm/auth/nested-write-inspector.js.map +1 -0
- package/esm/auth/nested-write-inspector.mjs +185 -0
- package/esm/auth/nested-write-policy.d.ts +95 -0
- package/esm/auth/nested-write-policy.d.ts.map +1 -0
- package/esm/auth/nested-write-policy.js.map +1 -0
- package/esm/auth/nested-write-policy.mjs +154 -0
- package/esm/auth/service-token.d.ts +11 -1
- package/esm/auth/service-token.d.ts.map +1 -1
- package/esm/auth/service-token.js.map +1 -1
- package/esm/auth/service-token.mjs +31 -5
- package/esm/auth/token-verifier.d.ts +9 -1
- package/esm/auth/token-verifier.d.ts.map +1 -1
- package/esm/auth/token-verifier.js.map +1 -1
- package/esm/auth/user-write-content.d.ts +41 -0
- package/esm/auth/user-write-content.d.ts.map +1 -0
- package/esm/auth/user-write-content.js.map +1 -0
- package/esm/auth/user-write-content.mjs +100 -0
- package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts +55 -0
- package/esm/middleware/__tests__/credential-field-coverage.harness.d.ts.map +1 -0
- package/esm/middleware/__tests__/credential-field-coverage.harness.js.map +1 -0
- package/esm/middleware/__tests__/credential-field-coverage.harness.mjs +438 -0
- package/esm/middleware/__tests__/credential-field-guard.harness.d.ts +34 -0
- package/esm/middleware/__tests__/credential-field-guard.harness.d.ts.map +1 -0
- package/esm/middleware/__tests__/credential-field-guard.harness.js.map +1 -0
- package/esm/middleware/__tests__/credential-field-guard.harness.mjs +212 -0
- package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts +49 -0
- package/esm/middleware/__tests__/mutation-auth-guard.harness.d.ts.map +1 -0
- package/esm/middleware/__tests__/mutation-auth-guard.harness.js.map +1 -0
- package/esm/middleware/__tests__/mutation-auth-guard.harness.mjs +402 -0
- package/esm/middleware/__tests__/ts-node-harness.d.ts +10 -0
- package/esm/middleware/__tests__/ts-node-harness.d.ts.map +1 -0
- package/esm/middleware/__tests__/ts-node-harness.js.map +1 -0
- package/esm/middleware/__tests__/ts-node-harness.mjs +71 -0
- package/esm/middleware/audit-logger.d.ts +18 -1
- package/esm/middleware/audit-logger.d.ts.map +1 -1
- package/esm/middleware/audit-logger.js.map +1 -1
- package/esm/middleware/audit-logger.mjs +36 -13
- package/esm/middleware/audit-payload-guard.d.ts +85 -0
- package/esm/middleware/audit-payload-guard.d.ts.map +1 -0
- package/esm/middleware/audit-payload-guard.js.map +1 -0
- package/esm/middleware/audit-payload-guard.mjs +97 -0
- package/esm/middleware/credential-field-guard.d.ts +160 -0
- package/esm/middleware/credential-field-guard.d.ts.map +1 -0
- package/esm/middleware/credential-field-guard.js.map +1 -0
- package/esm/middleware/credential-field-guard.mjs +479 -0
- package/esm/middleware/generated-type-names.d.ts +44 -0
- package/esm/middleware/generated-type-names.d.ts.map +1 -0
- package/esm/middleware/generated-type-names.js.map +1 -0
- package/esm/middleware/generated-type-names.mjs +73 -0
- package/esm/middleware/guard-log-throttle.d.ts +80 -0
- package/esm/middleware/guard-log-throttle.d.ts.map +1 -0
- package/esm/middleware/guard-log-throttle.js.map +1 -0
- package/esm/middleware/guard-log-throttle.mjs +87 -0
- package/esm/middleware/mutation-account-facts.d.ts +140 -0
- package/esm/middleware/mutation-account-facts.d.ts.map +1 -0
- package/esm/middleware/mutation-account-facts.js.map +1 -0
- package/esm/middleware/mutation-account-facts.mjs +212 -0
- package/esm/middleware/mutation-auth-guard.d.ts +82 -0
- package/esm/middleware/mutation-auth-guard.d.ts.map +1 -0
- package/esm/middleware/mutation-auth-guard.js.map +1 -0
- package/esm/middleware/mutation-auth-guard.mjs +425 -0
- package/esm/middleware/mutation-tenant-facts.d.ts +58 -0
- package/esm/middleware/mutation-tenant-facts.d.ts.map +1 -0
- package/esm/middleware/mutation-tenant-facts.js.map +1 -0
- package/esm/middleware/mutation-tenant-facts.mjs +75 -0
- package/esm/middleware/trading-policy-audit.d.ts +172 -0
- package/esm/middleware/trading-policy-audit.d.ts.map +1 -0
- package/esm/middleware/trading-policy-audit.js.map +1 -0
- package/esm/middleware/trading-policy-audit.mjs +309 -0
- package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts +22 -0
- package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts.map +1 -0
- package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.js.map +1 -0
- package/esm/resolvers/custom/BrokerageAccountCredentialStatusResolver.mjs +63 -0
- package/esm/resolvers/custom/index.d.ts +1 -0
- package/esm/resolvers/custom/index.d.ts.map +1 -1
- package/esm/resolvers/custom/index.js.map +1 -1
- package/esm/resolvers/custom/index.mjs +1 -0
- package/package.json +1 -1
- package/resolvers/custom/BrokerageAccountCredentialStatusResolver.cjs +100 -0
- package/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts +22 -0
- package/resolvers/custom/BrokerageAccountCredentialStatusResolver.d.ts.map +1 -0
- package/resolvers/custom/BrokerageAccountCredentialStatusResolver.js.map +1 -0
- package/resolvers/custom/index.cjs +4 -1
- package/resolvers/custom/index.d.ts +1 -0
- package/resolvers/custom/index.d.ts.map +1 -1
- package/resolvers/custom/index.js.map +1 -1
- package/server.cjs +40 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation-auth-guard.js","sourceRoot":"","sources":["../../../src/middleware/mutation-auth-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EACL,oBAAoB,EACpB,YAAY,GAIb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAEtC,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAChB,sBAAsB,EACtB,iBAAiB,EACjB,mBAAmB,GAKpB,MAAM,gCAAgC,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAoB,MAAM,gCAAgC,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAE,qBAAqB,EAAsB,MAAM,6BAA6B,CAAC;AAC5G,OAAO,EAAE,eAAe,EAAsB,MAAM,uBAAuB,CAAC;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,uBAAuB,GAGxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACL,QAAQ,EACR,eAAe,EACf,uBAAuB,EACvB,mBAAmB,EACnB,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,EACf,cAAc,GAIf,MAAM,wBAAwB,CAAC;AAKhC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,IAAI,OAAO,CAAC;IACpD,IAAI,EAAE,sCAAsC;IAC5C,IAAI,EACF,6EAA6E;QAC7E,sFAAsF;IACxF,UAAU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H,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,EAAE,CAAC;IAC9B,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC;QAC3E,MAAM,KAAK,CAAC;IACd,CAAC;IACD,MAAM,YAAY,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,IAAI,CAAC,CAAC;IAChE,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,KAAK,UAAU,YAAY,CACzB,MAA0B,EAC1B,KAA8B,EAC9B,SAAwB,EACxB,OAA+B,EAC/B,SAAwB;IAExB,IAAI,CAAC;QACH,MAAM,cAAc,CAAC,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;IACrE,CAAC;IAAC,OAAO,KAAc,EAAE,CAAC;QACxB,MAAM,CAAC,KAAK,CAAC,gEAAgE,EAAE;YAC7E,QAAQ,EAAE,KAAK,CAAC,QAAQ;YACxB,SAAS;YACT,OAAO;YACP,KAAK,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CAAC;IACL,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Mutation authorization guard: every GraphQL mutation is admitted only for a
|
|
3
|
+
* principal authorised to write that model and, for a brokerage account's
|
|
4
|
+
* policy or account row, that account.
|
|
5
|
+
*
|
|
6
|
+
* The decision itself lives in `src/auth/mutation-authorization.ts` (pure);
|
|
7
|
+
* this module installs it on the built schema, resolves the ownership facts a
|
|
8
|
+
* user principal's write needs, counts and logs every decision, and writes the
|
|
9
|
+
* attributed TradingPolicy audit rows (`./trading-policy-audit.ts`).
|
|
10
|
+
*
|
|
11
|
+
* ## Why it wraps the Mutation fields instead of being a global middleware
|
|
12
|
+
*
|
|
13
|
+
* A TypeGraphQL global middleware is dispatched on EVERY field of every query.
|
|
14
|
+
* Measured on 500 rows x 8 fields, one extra global middleware — even one that
|
|
15
|
+
* returns after a single comparison — added ~0.35 us per field (4.2 → 5.6 ms
|
|
16
|
+
* per query), a cost the platform's read-heavy traffic would pay for a check
|
|
17
|
+
* that only ever applies to root Mutation fields. So the guard wraps the
|
|
18
|
+
* `resolve` of each root Mutation field on the built schema: reads pay nothing,
|
|
19
|
+
* and every mutation — generated or hand-written — is covered, because the
|
|
20
|
+
* set wrapped is the schema's own Mutation type, not a list someone maintains.
|
|
21
|
+
*
|
|
22
|
+
* Each root field of a multi-field (batched or aliased) operation is its own
|
|
23
|
+
* resolver call, so each is decided on its own: an allowed field never carries
|
|
24
|
+
* a refused sibling through with it. The guard runs outside the TypeGraphQL
|
|
25
|
+
* middleware chain, so it decides before the credential-field guard and the
|
|
26
|
+
* tenancy scoping see the field.
|
|
27
|
+
*
|
|
28
|
+
* ## Nested writes and modes
|
|
29
|
+
*
|
|
30
|
+
* A root field's arguments can write far beyond its own model (nested
|
|
31
|
+
* `create` / `update` / `connect` along relations). Every nested container is
|
|
32
|
+
* decided on its own hop (`src/auth/nested-write-policy.ts`), and the mutation
|
|
33
|
+
* is decided at the strictest mode among every model it writes, so an
|
|
34
|
+
* escalated model cannot be written through a shadow-mode root.
|
|
35
|
+
*
|
|
36
|
+
* @module middleware/mutation-auth-guard
|
|
37
|
+
*/
|
|
38
|
+
import { Prisma } from '@prisma/client';
|
|
39
|
+
import { defaultFieldResolver, GraphQLError, } from 'graphql';
|
|
40
|
+
import { Counter } from 'prom-client';
|
|
41
|
+
import { redactCredentials } from '../auth/credential-redaction.mjs';
|
|
42
|
+
import { classifyMutationField, effectiveModeFor, evaluateMutationAccess, getEnforcedModels, getMutationAuthMode, } from '../auth/mutation-authorization.mjs';
|
|
43
|
+
import { findNestedWrites } from '../auth/nested-write-inspector.mjs';
|
|
44
|
+
import { firstNestedRefusal, writesNestedModelRows } from '../auth/nested-write-policy.mjs';
|
|
45
|
+
import { GOVERNED_MODELS } from '../auth/tenancy-scope.mjs';
|
|
46
|
+
import { userContentRefusal } from '../auth/user-write-content.mjs';
|
|
47
|
+
import { metricsRegistry } from '../config/metrics.mjs';
|
|
48
|
+
import { logger } from '../utils/logger.mjs';
|
|
49
|
+
import { loadTouchedAccounts, ownershipOf, resolveNestedPolicyRows, } from './mutation-account-facts.mjs';
|
|
50
|
+
import { tenantScopeOf } from './mutation-tenant-facts.mjs';
|
|
51
|
+
import { actorFor, changeReasonFor, isDisarmOnlyPolicyWrite, mayTouchLiveAccount, mutationAuditBypassedTotal, touchesTradingSwitch, writeAttemptRow, writeResultRow, } from './trading-policy-audit.mjs';
|
|
52
|
+
/**
|
|
53
|
+
* Mutation decisions by mutation field, principal kind, decision and reason.
|
|
54
|
+
* Every label is bounded: the mutation field must exist in the schema to
|
|
55
|
+
* reach a resolver, and the other three are closed enums. The `would_deny`
|
|
56
|
+
* series is the list of callers enforcement would break.
|
|
57
|
+
*/
|
|
58
|
+
export const mutationAuthorizationTotal = new Counter({
|
|
59
|
+
name: 'graphql_mutation_authorization_total',
|
|
60
|
+
help: 'GraphQL mutation authorization decisions by mutation field, principal kind ' +
|
|
61
|
+
'(server | admin | user | none), decision (allowed | would_deny | denied) and reason.',
|
|
62
|
+
labelNames: ['mutation', 'principal_kind', 'decision', 'reason'],
|
|
63
|
+
registers: [metricsRegistry],
|
|
64
|
+
});
|
|
65
|
+
/**
|
|
66
|
+
* Foreign-key placement read from the Prisma data model: `Model.relation`
|
|
67
|
+
* holds the key when its `relationFromFields` is non-empty.
|
|
68
|
+
*/
|
|
69
|
+
export function prismaRelationFacts() {
|
|
70
|
+
const onParent = new Map();
|
|
71
|
+
for (const model of Prisma.dmmf.datamodel.models) {
|
|
72
|
+
for (const field of model.fields) {
|
|
73
|
+
if (field.kind !== 'object')
|
|
74
|
+
continue;
|
|
75
|
+
onParent.set(`${model.name}.${field.name}`, (field.relationFromFields ?? []).length > 0);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return { fkOnParent: (model, relation) => onParent.get(`${model}.${relation}`) };
|
|
79
|
+
}
|
|
80
|
+
const GOVERNED = new Set(GOVERNED_MODELS);
|
|
81
|
+
function isGovernedModel(model) {
|
|
82
|
+
return GOVERNED.has(model);
|
|
83
|
+
}
|
|
84
|
+
const LOG_THROTTLE_MS = 10 * 60 * 1000;
|
|
85
|
+
const LOG_THROTTLE_MAX_KEYS = 5_000;
|
|
86
|
+
const lastLoggedAt = new Map();
|
|
87
|
+
/** @internal Test hook: forget the log throttle state. */
|
|
88
|
+
export function resetMutationAuthLogThrottle() {
|
|
89
|
+
lastLoggedAt.clear();
|
|
90
|
+
}
|
|
91
|
+
function refusalError(evaluation) {
|
|
92
|
+
if (evaluation.refusal === 'unauthenticated') {
|
|
93
|
+
return new GraphQLError('Unauthenticated: this mutation requires a verified principal', {
|
|
94
|
+
extensions: { code: 'UNAUTHENTICATED', reason: evaluation.reason, http: { status: 401 } },
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
return new GraphQLError('Forbidden: this principal is not authorised for this mutation', {
|
|
98
|
+
extensions: { code: 'FORBIDDEN', reason: evaluation.reason, http: { status: 403 } },
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function guardUnavailableError() {
|
|
102
|
+
return new GraphQLError('Service unavailable: this mutation could not be authorised', {
|
|
103
|
+
extensions: { code: 'MUTATION_AUTH_UNAVAILABLE', http: { status: 503 } },
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function auditUnavailableError() {
|
|
107
|
+
return new GraphQLError('Service unavailable: the audit record for this trading-policy write could not be written', { extensions: { code: 'AUDIT_UNAVAILABLE', http: { status: 503 } } });
|
|
108
|
+
}
|
|
109
|
+
function errorCodeOf(error) {
|
|
110
|
+
if (error instanceof GraphQLError && typeof error.extensions?.code === 'string') {
|
|
111
|
+
return error.extensions.code;
|
|
112
|
+
}
|
|
113
|
+
if (error instanceof Prisma.PrismaClientKnownRequestError)
|
|
114
|
+
return error.code;
|
|
115
|
+
return error instanceof Error ? error.name : 'unknown';
|
|
116
|
+
}
|
|
117
|
+
function logRefusal(decision, target, evaluation, principal, info, req, nowMs) {
|
|
118
|
+
const actor = actorFor(principal, req);
|
|
119
|
+
const key = [decision, target.fieldName, actor.principalKind, evaluation.reason, actor.userAgent, actor.ip].join('|');
|
|
120
|
+
const previous = lastLoggedAt.get(key);
|
|
121
|
+
if (previous !== undefined && nowMs - previous < LOG_THROTTLE_MS)
|
|
122
|
+
return;
|
|
123
|
+
if (lastLoggedAt.size >= LOG_THROTTLE_MAX_KEYS)
|
|
124
|
+
lastLoggedAt.clear();
|
|
125
|
+
lastLoggedAt.set(key, nowMs);
|
|
126
|
+
logger.warn('[mutation-auth] mutation refused by authorization policy', {
|
|
127
|
+
decision,
|
|
128
|
+
mutation: target.fieldName,
|
|
129
|
+
model: target.model,
|
|
130
|
+
reason: evaluation.reason,
|
|
131
|
+
principalKind: actor.principalKind,
|
|
132
|
+
principalSub: actor.sub,
|
|
133
|
+
operationName: info.operation?.name?.value ?? '<unnamed>',
|
|
134
|
+
ip: actor.ip,
|
|
135
|
+
userAgent: actor.userAgent,
|
|
136
|
+
origin: actor.origin,
|
|
137
|
+
dedupWindowMs: LOG_THROTTLE_MS,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
/** Decide one mutation, resolving database facts only when the decision needs them. */
|
|
141
|
+
async function decide(principal, target, nested, args, touched, prisma, relations) {
|
|
142
|
+
if (principal?.kind !== 'user')
|
|
143
|
+
return evaluateMutationAccess(principal, target);
|
|
144
|
+
const facts = {
|
|
145
|
+
nestedRefusal: firstNestedRefusal(nested, principal.sub, relations),
|
|
146
|
+
contentRefusal: userContentRefusal(target, args, principal.sub),
|
|
147
|
+
targetsSelf: targetsSelf(principal, args),
|
|
148
|
+
};
|
|
149
|
+
const first = evaluateMutationAccess(principal, target, facts);
|
|
150
|
+
if (!prisma)
|
|
151
|
+
return first;
|
|
152
|
+
if (first.reason === 'account_unresolved') {
|
|
153
|
+
try {
|
|
154
|
+
const ownership = await ownershipOf(prisma, principal.sub, await touched());
|
|
155
|
+
return evaluateMutationAccess(principal, target, { ...facts, ownership });
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
logger.error('[mutation-auth] account ownership could not be read; refusing as unresolved', {
|
|
159
|
+
mutation: target.fieldName,
|
|
160
|
+
error: error instanceof Error ? error.message : String(error),
|
|
161
|
+
});
|
|
162
|
+
return first;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
if (first.reason === 'tenant_unresolved' && isGovernedModel(target.model)) {
|
|
166
|
+
try {
|
|
167
|
+
const tenantScope = await tenantScopeOf(prisma, target.model, target, args, principal.sub);
|
|
168
|
+
return evaluateMutationAccess(principal, target, { ...facts, tenantScope });
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
logger.error('[mutation-auth] tenant scope could not be read; refusing as unresolved', {
|
|
172
|
+
mutation: target.fieldName,
|
|
173
|
+
error: error instanceof Error ? error.message : String(error),
|
|
174
|
+
});
|
|
175
|
+
return first;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
return first;
|
|
179
|
+
}
|
|
180
|
+
function targetsSelf(principal, args) {
|
|
181
|
+
const where = args.where;
|
|
182
|
+
if (where === null || typeof where !== 'object')
|
|
183
|
+
return false;
|
|
184
|
+
const { id, email } = where;
|
|
185
|
+
if (id !== undefined)
|
|
186
|
+
return id === principal.sub;
|
|
187
|
+
return principal.email !== undefined && email === principal.email;
|
|
188
|
+
}
|
|
189
|
+
/** Fields already wrapped, so installing twice never double-guards a field. */
|
|
190
|
+
const guardedFields = new WeakSet();
|
|
191
|
+
/**
|
|
192
|
+
* Wrap every root Mutation field of a built schema with the guard.
|
|
193
|
+
*
|
|
194
|
+
* @param schema - The schema `buildSchema` returned; mutated in place.
|
|
195
|
+
* @param options - Optional overrides for tests.
|
|
196
|
+
* @returns How many Mutation fields are guarded (for the boot log; zero means
|
|
197
|
+
* the schema has no Mutation type and nothing is protected).
|
|
198
|
+
*/
|
|
199
|
+
export function installMutationAuthGuard(schema, options = {}) {
|
|
200
|
+
const mutationType = schema.getMutationType();
|
|
201
|
+
if (!mutationType)
|
|
202
|
+
return 0;
|
|
203
|
+
const guard = createMutationGuard(options);
|
|
204
|
+
let guarded = 0;
|
|
205
|
+
for (const field of Object.values(mutationType.getFields())) {
|
|
206
|
+
guarded += 1;
|
|
207
|
+
if (guardedFields.has(field))
|
|
208
|
+
continue;
|
|
209
|
+
const original = field.resolve ?? defaultFieldResolver;
|
|
210
|
+
field.resolve = (source, args, context, info) => guard(context, args, info, () => Promise.resolve(original(source, args, context, info)));
|
|
211
|
+
guardedFields.add(field);
|
|
212
|
+
}
|
|
213
|
+
return guarded;
|
|
214
|
+
}
|
|
215
|
+
/** The per-mutation decision + audit, closed over its configuration. */
|
|
216
|
+
function createMutationGuard(options) {
|
|
217
|
+
const resolveMode = options.modeProvider ?? (() => getMutationAuthMode());
|
|
218
|
+
const resolveEnforced = options.enforcedModelsProvider ?? (() => getEnforcedModels());
|
|
219
|
+
const models = new Set(options.models ?? Object.values(Prisma.ModelName));
|
|
220
|
+
const modelsLongestFirst = [...models].sort((a, b) => b.length - a.length);
|
|
221
|
+
const relations = options.relations ?? prismaRelationFacts();
|
|
222
|
+
const now = options.now ?? Date.now;
|
|
223
|
+
/**
|
|
224
|
+
* Whether a mutation the guard could not evaluate is refused. It is when
|
|
225
|
+
* anything is being enforced — globally, or any escalated model (the guard
|
|
226
|
+
* cannot know the failed mutation was not one of them) — and when the
|
|
227
|
+
* escalation list itself cannot be read. Only a pure-shadow or off guard
|
|
228
|
+
* lets it through, because in those modes the guard refuses nothing anyway.
|
|
229
|
+
*/
|
|
230
|
+
const failsClosedOnError = (baseMode) => {
|
|
231
|
+
if (baseMode === 'enforce')
|
|
232
|
+
return true;
|
|
233
|
+
if (baseMode === 'off')
|
|
234
|
+
return false;
|
|
235
|
+
try {
|
|
236
|
+
return resolveEnforced().size > 0;
|
|
237
|
+
}
|
|
238
|
+
catch {
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
return async (context, args, info, proceed) => {
|
|
243
|
+
const principal = context.principal ?? null;
|
|
244
|
+
const argRecord = (args ?? {});
|
|
245
|
+
// Cast justified: the context's `prisma` is the server's PrismaClient, whose
|
|
246
|
+
// delegates satisfy this structural slice; tests supply a fake of it.
|
|
247
|
+
const prisma = context.prisma;
|
|
248
|
+
let baseMode = 'enforce';
|
|
249
|
+
let target;
|
|
250
|
+
let mode;
|
|
251
|
+
let nested;
|
|
252
|
+
let evaluation;
|
|
253
|
+
let touchedPromise;
|
|
254
|
+
const touched = () => {
|
|
255
|
+
touchedPromise ??= prisma
|
|
256
|
+
? loadTouchedAccounts(prisma, target, argRecord)
|
|
257
|
+
: Promise.resolve({ accounts: [], policies: [] });
|
|
258
|
+
return touchedPromise;
|
|
259
|
+
};
|
|
260
|
+
try {
|
|
261
|
+
baseMode = resolveMode();
|
|
262
|
+
target = classifyMutationField(info.fieldName, models);
|
|
263
|
+
nested = findNestedWrites(info, argRecord, modelsLongestFirst, target);
|
|
264
|
+
const written = nested.filter((n) => writesNestedModelRows(n, relations)).map((n) => n.model);
|
|
265
|
+
mode = effectiveModeFor([target.model, ...written], baseMode, resolveEnforced());
|
|
266
|
+
evaluation =
|
|
267
|
+
mode === 'off'
|
|
268
|
+
? { allowed: true, reason: 'guard_off' }
|
|
269
|
+
: await decide(principal, target, nested, argRecord, touched, prisma, relations);
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
const refuse = failsClosedOnError(baseMode);
|
|
273
|
+
mutationAuthorizationTotal.inc({
|
|
274
|
+
mutation: info.fieldName,
|
|
275
|
+
principal_kind: principal?.kind ?? 'none',
|
|
276
|
+
decision: refuse ? 'denied' : 'allowed',
|
|
277
|
+
reason: 'guard_error',
|
|
278
|
+
});
|
|
279
|
+
logger.error('[mutation-auth] mutation could not be evaluated', {
|
|
280
|
+
mutation: info.fieldName,
|
|
281
|
+
refused: refuse,
|
|
282
|
+
error: error instanceof Error ? error.message : String(error),
|
|
283
|
+
});
|
|
284
|
+
if (refuse)
|
|
285
|
+
throw guardUnavailableError();
|
|
286
|
+
return proceed();
|
|
287
|
+
}
|
|
288
|
+
const decision = evaluation.allowed ? 'allowed' : mode === 'enforce' ? 'denied' : 'would_deny';
|
|
289
|
+
mutationAuthorizationTotal.inc({
|
|
290
|
+
mutation: target.fieldName,
|
|
291
|
+
principal_kind: principal?.kind ?? 'none',
|
|
292
|
+
decision,
|
|
293
|
+
reason: evaluation.reason,
|
|
294
|
+
});
|
|
295
|
+
if (decision !== 'allowed') {
|
|
296
|
+
logRefusal(decision, target, evaluation, principal, info, context.req, now());
|
|
297
|
+
}
|
|
298
|
+
const policyWrites = nested.filter((n) => n.model === 'TradingPolicy');
|
|
299
|
+
if (target.model !== 'TradingPolicy' && policyWrites.length === 0) {
|
|
300
|
+
if (decision === 'denied')
|
|
301
|
+
throw refusalError(evaluation);
|
|
302
|
+
return proceed();
|
|
303
|
+
}
|
|
304
|
+
return auditedPolicyWrite({
|
|
305
|
+
target,
|
|
306
|
+
policyWrites,
|
|
307
|
+
principal,
|
|
308
|
+
context,
|
|
309
|
+
info,
|
|
310
|
+
args: argRecord,
|
|
311
|
+
evaluation,
|
|
312
|
+
decision,
|
|
313
|
+
mode,
|
|
314
|
+
prisma,
|
|
315
|
+
touched,
|
|
316
|
+
next: proceed,
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
async function auditedPolicyWrite(input) {
|
|
321
|
+
const { target, principal, context, evaluation, decision, mode, prisma } = input;
|
|
322
|
+
let policies = [];
|
|
323
|
+
let policyReadFailed = false;
|
|
324
|
+
try {
|
|
325
|
+
const root = target.model === 'TradingPolicy' ? (await input.touched()).policies : [];
|
|
326
|
+
const nestedRows = input.policyWrites.length > 0 && prisma ? await resolveNestedPolicyRows(prisma, input.policyWrites) : [];
|
|
327
|
+
policies = [...root, ...nestedRows];
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
policyReadFailed = true;
|
|
331
|
+
logger.error('[mutation-auth] trading-policy before-state could not be read', {
|
|
332
|
+
mutation: target.fieldName,
|
|
333
|
+
error: error instanceof Error ? error.message : String(error),
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
const entry = {
|
|
337
|
+
mutation: target.fieldName,
|
|
338
|
+
action: target.action,
|
|
339
|
+
nestedPaths: input.policyWrites.map((w) => w.path),
|
|
340
|
+
actor: actorFor(principal, context.req),
|
|
341
|
+
changeReason: changeReasonFor(context.req),
|
|
342
|
+
decision,
|
|
343
|
+
authorizationReason: evaluation.reason,
|
|
344
|
+
effectiveMode: policyReadFailed ? `${mode}:before_state_unread` : mode,
|
|
345
|
+
graphqlOperationName: input.info.operation?.name?.value ?? null,
|
|
346
|
+
requested: input.args,
|
|
347
|
+
policies,
|
|
348
|
+
};
|
|
349
|
+
if ((policyReadFailed || mayTouchLiveAccount(policies)) && touchesTradingSwitch(input.args)) {
|
|
350
|
+
logger.warn('[mutation-auth] trading-switch write on a LIVE or unidentified account', {
|
|
351
|
+
mutation: target.fieldName,
|
|
352
|
+
decision,
|
|
353
|
+
reason: evaluation.reason,
|
|
354
|
+
actor: entry.actor,
|
|
355
|
+
changeReason: entry.changeReason,
|
|
356
|
+
accounts: policies,
|
|
357
|
+
});
|
|
358
|
+
}
|
|
359
|
+
if (!prisma) {
|
|
360
|
+
logger.error('[mutation-auth] no database client on the context; trading-policy write is unaudited', {
|
|
361
|
+
mutation: target.fieldName,
|
|
362
|
+
});
|
|
363
|
+
if (decision === 'denied')
|
|
364
|
+
throw refusalError(evaluation);
|
|
365
|
+
if (mode === 'enforce')
|
|
366
|
+
throw auditUnavailableError();
|
|
367
|
+
return input.next();
|
|
368
|
+
}
|
|
369
|
+
if (decision === 'denied') {
|
|
370
|
+
try {
|
|
371
|
+
await writeAttemptRow(prisma, entry, 'denied');
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
logger.error('[mutation-auth] audit row for a refused trading-policy write failed', {
|
|
375
|
+
mutation: target.fieldName,
|
|
376
|
+
error: error instanceof Error ? error.message : String(error),
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
throw refusalError(evaluation);
|
|
380
|
+
}
|
|
381
|
+
let attemptId = null;
|
|
382
|
+
try {
|
|
383
|
+
attemptId = await writeAttemptRow(prisma, entry, 'pending');
|
|
384
|
+
}
|
|
385
|
+
catch (error) {
|
|
386
|
+
const disarmOnly = isDisarmOnlyPolicyWrite(target, input.args);
|
|
387
|
+
logger.error('[mutation-auth] trading-policy attempt row could not be written', {
|
|
388
|
+
mutation: target.fieldName,
|
|
389
|
+
refused: mode === 'enforce' && !disarmOnly,
|
|
390
|
+
error: error instanceof Error ? error.message : String(error),
|
|
391
|
+
});
|
|
392
|
+
if (mode === 'enforce') {
|
|
393
|
+
if (!disarmOnly)
|
|
394
|
+
throw auditUnavailableError();
|
|
395
|
+
mutationAuditBypassedTotal.inc({ reason: 'disarm_during_audit_outage' });
|
|
396
|
+
logger.error('[mutation-auth] AuditLog unavailable; admitting a disarm-only trading-policy write unaudited', {
|
|
397
|
+
entry: redactCredentials(entry),
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
let result;
|
|
402
|
+
try {
|
|
403
|
+
result = await input.next();
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
await recordResult(prisma, entry, attemptId, 'failed', errorCodeOf(error));
|
|
407
|
+
throw error;
|
|
408
|
+
}
|
|
409
|
+
await recordResult(prisma, entry, attemptId, 'succeeded', null);
|
|
410
|
+
return result;
|
|
411
|
+
}
|
|
412
|
+
async function recordResult(prisma, entry, attemptId, outcome, errorCode) {
|
|
413
|
+
try {
|
|
414
|
+
await writeResultRow(prisma, entry, attemptId, outcome, errorCode);
|
|
415
|
+
}
|
|
416
|
+
catch (error) {
|
|
417
|
+
logger.error('[mutation-auth] trading-policy result row could not be written', {
|
|
418
|
+
mutation: entry.mutation,
|
|
419
|
+
attemptId,
|
|
420
|
+
outcome,
|
|
421
|
+
error: error instanceof Error ? error.message : String(error),
|
|
422
|
+
});
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
//# sourceMappingURL=mutation-auth-guard.js.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mutation guard's own tenancy check for a user principal's write to a
|
|
3
|
+
* tenancy-governed model (Organization, OrgMembership, Fund, FundAssignment,
|
|
4
|
+
* BrokerageAccount, Notification*).
|
|
5
|
+
*
|
|
6
|
+
* The tenancy-scoping middleware applies the same scope, but only as strongly
|
|
7
|
+
* as `TENANCY_SCOPING_MODE` (default `shadow`) and only on root fields. The
|
|
8
|
+
* guard cannot defer to it: fund entitlement — read from OrgMembership, Fund
|
|
9
|
+
* and FundAssignment — is what admits a user's write to every AlpacaAccount
|
|
10
|
+
* and TradingPolicy bridged to the fund, so an entitlement row a caller could
|
|
11
|
+
* write outside their own tenants would let them mint the access they are
|
|
12
|
+
* then checked against. The decision here is applied at the guard's own mode.
|
|
13
|
+
*
|
|
14
|
+
* - create: the payload's tenant must be one the caller is entitled to
|
|
15
|
+
* (`dataInScope`, the tenancy module's own create rule).
|
|
16
|
+
* - update / delete: the addressed row must match the caller's scope
|
|
17
|
+
* (`findUnique` on the caller's `where` AND the scope fragment).
|
|
18
|
+
* - upsert: if the row exists it must be in scope; if it does not, the
|
|
19
|
+
* create payload must be.
|
|
20
|
+
*
|
|
21
|
+
* @module middleware/mutation-tenant-facts
|
|
22
|
+
*/
|
|
23
|
+
import type { MutationTarget, TenantScope } from '../auth/mutation-authorization';
|
|
24
|
+
import { type EntitlementPrismaClient, type GovernedModel } from '../auth/tenancy-scope';
|
|
25
|
+
type Where = Record<string, unknown>;
|
|
26
|
+
/** A delegate that can say whether one row matching a unique `where` exists. */
|
|
27
|
+
export interface ScopedRowReader {
|
|
28
|
+
findUnique(args: {
|
|
29
|
+
where: Where;
|
|
30
|
+
select: {
|
|
31
|
+
id: true;
|
|
32
|
+
};
|
|
33
|
+
}): Promise<{
|
|
34
|
+
id: string;
|
|
35
|
+
} | null>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The slice of the Prisma client the tenancy check reads. Declared
|
|
39
|
+
* structurally so the guard can be exercised against a fake.
|
|
40
|
+
*/
|
|
41
|
+
export interface TenantScopePrisma extends EntitlementPrismaClient {
|
|
42
|
+
organization: ScopedRowReader;
|
|
43
|
+
orgMembership: EntitlementPrismaClient['orgMembership'] & ScopedRowReader;
|
|
44
|
+
fund: EntitlementPrismaClient['fund'] & ScopedRowReader;
|
|
45
|
+
fundAssignment: EntitlementPrismaClient['fundAssignment'] & ScopedRowReader;
|
|
46
|
+
brokerageAccount: ScopedRowReader;
|
|
47
|
+
notificationEvent: ScopedRowReader;
|
|
48
|
+
notificationDelivery: ScopedRowReader;
|
|
49
|
+
notificationPreference: ScopedRowReader;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Whether a user's write to a governed model stays inside their entitlement.
|
|
53
|
+
*
|
|
54
|
+
* @throws Whatever the database raised; the caller fails closed on it.
|
|
55
|
+
*/
|
|
56
|
+
export declare function tenantScopeOf(prisma: TenantScopePrisma, model: GovernedModel, target: MutationTarget, args: Record<string, unknown>, userId: string): Promise<TenantScope>;
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=mutation-tenant-facts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mutation-tenant-facts.d.ts","sourceRoot":"","sources":["../../../src/middleware/mutation-tenant-facts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,WAA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,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC;IAClF,CAAC;IACD,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IACnC,IAAI,CAAC,KAAK;QAAE,OAAO,cAAc,CAAC;IAClC,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACxC,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC;QACrC,KAAK,EAAE,gBAAgB,CAAC,KAAK,EAAE,eAAe,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QACnE,MAAM,EAAE,OAAO;KAChB,CAAC,CAAC;IACH,IAAI,MAAM;QAAE,OAAO,UAAU,CAAC;IAC9B,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,cAAc,CAAC;IACtD,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,UAAU,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IACrE,IAAI,QAAQ;QAAE,OAAO,cAAc,CAAC;IACpC,OAAO,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,cAAc,CAAC;AACpF,CAAC"}
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The mutation guard's own tenancy check for a user principal's write to a
|
|
3
|
+
* tenancy-governed model (Organization, OrgMembership, Fund, FundAssignment,
|
|
4
|
+
* BrokerageAccount, Notification*).
|
|
5
|
+
*
|
|
6
|
+
* The tenancy-scoping middleware applies the same scope, but only as strongly
|
|
7
|
+
* as `TENANCY_SCOPING_MODE` (default `shadow`) and only on root fields. The
|
|
8
|
+
* guard cannot defer to it: fund entitlement — read from OrgMembership, Fund
|
|
9
|
+
* and FundAssignment — is what admits a user's write to every AlpacaAccount
|
|
10
|
+
* and TradingPolicy bridged to the fund, so an entitlement row a caller could
|
|
11
|
+
* write outside their own tenants would let them mint the access they are
|
|
12
|
+
* then checked against. The decision here is applied at the guard's own mode.
|
|
13
|
+
*
|
|
14
|
+
* - create: the payload's tenant must be one the caller is entitled to
|
|
15
|
+
* (`dataInScope`, the tenancy module's own create rule).
|
|
16
|
+
* - update / delete: the addressed row must match the caller's scope
|
|
17
|
+
* (`findUnique` on the caller's `where` AND the scope fragment).
|
|
18
|
+
* - upsert: if the row exists it must be in scope; if it does not, the
|
|
19
|
+
* create payload must be.
|
|
20
|
+
*
|
|
21
|
+
* @module middleware/mutation-tenant-facts
|
|
22
|
+
*/
|
|
23
|
+
import { buildScopeWhere, dataInScope, injectScopeWhere, resolveEntitlement, } from '../auth/tenancy-scope.mjs';
|
|
24
|
+
function readerFor(prisma, model) {
|
|
25
|
+
switch (model) {
|
|
26
|
+
case 'Organization':
|
|
27
|
+
return prisma.organization;
|
|
28
|
+
case 'OrgMembership':
|
|
29
|
+
return prisma.orgMembership;
|
|
30
|
+
case 'Fund':
|
|
31
|
+
return prisma.fund;
|
|
32
|
+
case 'FundAssignment':
|
|
33
|
+
return prisma.fundAssignment;
|
|
34
|
+
case 'BrokerageAccount':
|
|
35
|
+
return prisma.brokerageAccount;
|
|
36
|
+
case 'NotificationEvent':
|
|
37
|
+
return prisma.notificationEvent;
|
|
38
|
+
case 'NotificationDelivery':
|
|
39
|
+
return prisma.notificationDelivery;
|
|
40
|
+
case 'NotificationPreference':
|
|
41
|
+
return prisma.notificationPreference;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function asRecord(value) {
|
|
45
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : undefined;
|
|
46
|
+
}
|
|
47
|
+
const ID_ONLY = { id: true };
|
|
48
|
+
/**
|
|
49
|
+
* Whether a user's write to a governed model stays inside their entitlement.
|
|
50
|
+
*
|
|
51
|
+
* @throws Whatever the database raised; the caller fails closed on it.
|
|
52
|
+
*/
|
|
53
|
+
export async function tenantScopeOf(prisma, model, target, args, userId) {
|
|
54
|
+
const entitlement = await resolveEntitlement(prisma, userId);
|
|
55
|
+
if (target.action === 'create') {
|
|
56
|
+
return dataInScope(model, args.data, entitlement) ? 'in_scope' : 'out_of_scope';
|
|
57
|
+
}
|
|
58
|
+
const where = asRecord(args.where);
|
|
59
|
+
if (!where)
|
|
60
|
+
return 'out_of_scope';
|
|
61
|
+
const reader = readerFor(prisma, model);
|
|
62
|
+
const scoped = await reader.findUnique({
|
|
63
|
+
where: injectScopeWhere(where, buildScopeWhere(model, entitlement)),
|
|
64
|
+
select: ID_ONLY,
|
|
65
|
+
});
|
|
66
|
+
if (scoped)
|
|
67
|
+
return 'in_scope';
|
|
68
|
+
if (target.action !== 'upsert')
|
|
69
|
+
return 'out_of_scope';
|
|
70
|
+
const existing = await reader.findUnique({ where, select: ID_ONLY });
|
|
71
|
+
if (existing)
|
|
72
|
+
return 'out_of_scope';
|
|
73
|
+
return dataInScope(model, args.create, entitlement) ? 'in_scope' : 'out_of_scope';
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=mutation-tenant-facts.js.map
|