@nodii/db-rls 0.13.0 → 0.14.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +79 -1
- package/dist/claims-context.d.ts +100 -0
- package/dist/claims-context.d.ts.map +1 -0
- package/dist/claims-context.js +262 -0
- package/dist/claims-context.js.map +1 -0
- package/dist/context.d.ts +56 -15
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +56 -34
- package/dist/context.js.map +1 -1
- package/dist/drizzle-client.d.ts +21 -3
- package/dist/drizzle-client.d.ts.map +1 -1
- package/dist/drizzle-client.js +28 -7
- package/dist/drizzle-client.js.map +1 -1
- package/dist/index.d.ts +3 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/postgres-js-client.d.ts +26 -4
- package/dist/postgres-js-client.d.ts.map +1 -1
- package/dist/postgres-js-client.js +36 -8
- package/dist/postgres-js-client.js.map +1 -1
- package/dist/types.d.ts +161 -17
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +126 -3
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres-js-client.js","sourceRoot":"","sources":["../src/postgres-js-client.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,wEAAwE;AACxE,+DAA+D;AAC/D,oEAAoE;AACpE,sBAAsB;AACtB,EAAE;AACF,WAAW;AACX,0EAA0E;AAC1E,kEAAkE;AAClE,qBAAqB;AACrB,oEAAoE;AACpE,uEAAuE;AACvE,mEAAmE;AACnE,EAAE;AACF,6DAA6D;AAC7D,gCAAgC;AAChC,2DAA2D;AAC3D,sCAAsC;AACtC,6CAA6C;AAC7C,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAA2B,MAAM,yBAAyB,CAAC;AAG3E,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,GAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EAKpB,qBAAqB,
|
|
1
|
+
{"version":3,"file":"postgres-js-client.js","sourceRoot":"","sources":["../src/postgres-js-client.ts"],"names":[],"mappings":"AAAA,2EAA2E;AAC3E,EAAE;AACF,mEAAmE;AACnE,kEAAkE;AAClE,wEAAwE;AACxE,+DAA+D;AAC/D,oEAAoE;AACpE,sBAAsB;AACtB,EAAE;AACF,WAAW;AACX,0EAA0E;AAC1E,kEAAkE;AAClE,qBAAqB;AACrB,oEAAoE;AACpE,uEAAuE;AACvE,mEAAmE;AACnE,EAAE;AACF,6DAA6D;AAC7D,gCAAgC;AAChC,2DAA2D;AAC3D,sCAAsC;AACtC,6CAA6C;AAC7C,qEAAqE;AACrE,sCAAsC;AAEtC,OAAO,EAAE,GAAG,IAAI,UAAU,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,OAAO,EAA2B,MAAM,yBAAyB,CAAC;AAG3E,OAAO,EACL,sBAAsB,EACtB,gCAAgC,EAChC,2BAA2B,GAC5B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,yBAAyB,EACzB,sBAAsB,EACtB,mBAAmB,EACnB,4BAA4B,EAC5B,gBAAgB,EAChB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,oBAAoB,GAErB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,oBAAoB,EAKpB,qBAAqB,EAErB,yB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O,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,mBAAmB,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnE,OAAO,EACL,gBAAgB,EAChB,UAAU,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,eAAe,EACf,+BAA+B,EAC/B,qBAAqB,EACrB,qBAAqB,EACrB,gCAAgC,GACjC,MAAM,YAAY,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -33,21 +33,28 @@ export interface PgPool {
|
|
|
33
33
|
* `3-pool`.
|
|
34
34
|
*/
|
|
35
35
|
export type DbRlsMode = "3-pool" | "2-pool" | "3-pool-with-platform-ops";
|
|
36
|
-
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
36
|
+
/**
|
|
37
|
+
* The VERIFIED claim set for one request — the ONLY source of the tenant on
|
|
38
|
+
* the authenticated path.
|
|
39
|
+
*
|
|
40
|
+
* Bound once per request by auth middleware via
|
|
41
|
+
* `runWithVerifiedTenantClaims`, read by `withUserContext` /
|
|
42
|
+
* `withUserContextDb` / `withUserContextDbPostgresJs` / `autoDispatch`.
|
|
43
|
+
* These fields must come off the verified JWT claim set — never off the
|
|
44
|
+
* request body, path params, or headers.
|
|
45
|
+
*
|
|
46
|
+
* This REPLACES the removed `AuthContext` and `UserContextOpts`. Those two
|
|
47
|
+
* types existed to carry a tenant into the authenticated path as an
|
|
48
|
+
* argument, which is exactly the forgery this release removes; they are
|
|
49
|
+
* deleted rather than deprecated so that a consumer still importing them
|
|
50
|
+
* gets a compile error instead of a type that no longer does anything.
|
|
51
|
+
*/
|
|
52
|
+
export interface VerifiedTenantClaims {
|
|
53
|
+
/** Verified principal id — the JWT `sub`. */
|
|
49
54
|
userId: string;
|
|
55
|
+
/** Verified tenant id — the tenant claim the JWT was minted for. */
|
|
50
56
|
tenantId: string;
|
|
57
|
+
/** Optional source IP, bound to `app.source_ip` for forensics. */
|
|
51
58
|
sourceIp?: string;
|
|
52
59
|
}
|
|
53
60
|
/**
|
|
@@ -64,11 +71,50 @@ export interface UserMembershipContextOpts {
|
|
|
64
71
|
/** withSystemContext opts. */
|
|
65
72
|
export interface SystemContextOpts {
|
|
66
73
|
tenantId: string;
|
|
74
|
+
/**
|
|
75
|
+
* REQUIRED when calling from inside a claims-bound request (i.e. while
|
|
76
|
+
* `hasVerifiedTenantClaims()` is true) — otherwise the call throws
|
|
77
|
+
* `SystemContextUnderClaimsRefused` before any pool is touched.
|
|
78
|
+
*
|
|
79
|
+
* The services-pool predicate is the bare
|
|
80
|
+
* `tenant_id = auth.get_tenant_id()` with no membership proof, so an
|
|
81
|
+
* authenticated request that falls through to `withSystemContext` can aim
|
|
82
|
+
* the session at ANY tenant — the seam where the ₹250,000 cross-tenant
|
|
83
|
+
* refund reproduced. A non-blank `reason` names the deliberate escape and
|
|
84
|
+
* is emitted to telemetry
|
|
85
|
+
* (`db_rls.cross_pool_nesting_total{outer=authenticated,inner=services,reason}`).
|
|
86
|
+
*
|
|
87
|
+
* Outside any claims-bound context (workers, cron, S2S, webhooks, boot)
|
|
88
|
+
* this field is ignored and the helper behaves exactly as before.
|
|
89
|
+
*/
|
|
90
|
+
reason?: string;
|
|
67
91
|
}
|
|
68
|
-
/**
|
|
92
|
+
/**
|
|
93
|
+
* autoDispatch opts — the SYSTEM leg only.
|
|
94
|
+
*
|
|
95
|
+
* The field is `systemTenantId`, not `tenantId`, and it is REQUIRED. Both
|
|
96
|
+
* are deliberate: the old shape was `{ authContext?, tenantId? }` with
|
|
97
|
+
* everything optional, so dropping `authContext` alone would have left
|
|
98
|
+
* `autoDispatch(opts, fn)` compiling against a variable that still carried
|
|
99
|
+
* an `authContext` — the argument would just be ignored, which is a silent
|
|
100
|
+
* behaviour change with green CI. A renamed, required property is a
|
|
101
|
+
* compile error for every previous call shape, literal or not.
|
|
102
|
+
*
|
|
103
|
+
* Passing this selects the `services` pool explicitly, exactly as
|
|
104
|
+
* `withSystemContext({ tenantId }, fn)` does — including the
|
|
105
|
+
* under-claims fence: inside a claims-bound request the system leg needs
|
|
106
|
+
* a non-blank `reason` or it throws `SystemContextUnderClaimsRefused`.
|
|
107
|
+
* Omit the opts entirely (call `autoDispatch(fn)`) to run on the
|
|
108
|
+
* authenticated pool against the request's verified claims.
|
|
109
|
+
*/
|
|
69
110
|
export interface AutoDispatchOpts {
|
|
70
|
-
|
|
71
|
-
|
|
111
|
+
/** Tenant for the SYSTEM (services-pool) leg: workers, cron, S2S,
|
|
112
|
+
* webhooks. Named `systemTenantId` so a reviewer reading the call site
|
|
113
|
+
* can see that no user claim is involved. */
|
|
114
|
+
systemTenantId: string;
|
|
115
|
+
/** Passed through to `withSystemContext` — required when dispatching the
|
|
116
|
+
* system leg from inside a claims-bound request. */
|
|
117
|
+
reason?: string;
|
|
72
118
|
}
|
|
73
119
|
/**
|
|
74
120
|
* withPlatformOpsContext opts. Per hub decision D185:
|
|
@@ -116,7 +162,105 @@ export declare class PoolUnavailable extends DbRlsError {
|
|
|
116
162
|
constructor(pool: PoolKind);
|
|
117
163
|
}
|
|
118
164
|
export declare class MissingTenantContext extends DbRlsError {
|
|
119
|
-
constructor();
|
|
165
|
+
constructor(detail?: string);
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Thrown by the authenticated-pool helpers when NOTHING bound verified
|
|
169
|
+
* claims for the current request.
|
|
170
|
+
*
|
|
171
|
+
* Fail closed and loud. There is no default tenant, no fallback to a
|
|
172
|
+
* caller-supplied value, and no "return an empty result and carry on" — a
|
|
173
|
+
* silently-empty result is how the crm 85-policy blackout hid for weeks.
|
|
174
|
+
* If you see this, the cause is one of:
|
|
175
|
+
*
|
|
176
|
+
* 1. Your auth middleware does not call `runWithVerifiedTenantClaims`
|
|
177
|
+
* yet (the usual one — see the migration note in the README).
|
|
178
|
+
* 2. The DB call escaped the request's async context: it was scheduled
|
|
179
|
+
* with `setTimeout` / an unawaited promise / a queue callback that
|
|
180
|
+
* outlives the request, so the AsyncLocalStorage store is gone. Await
|
|
181
|
+
* the work inside the request, or run it as a worker on
|
|
182
|
+
* `withSystemContext({ tenantId }, fn)`.
|
|
183
|
+
* 3. It genuinely is not an authenticated request — a worker, cron job,
|
|
184
|
+
* S2S call, or webhook. Those have a legitimately resolved tenant and
|
|
185
|
+
* no user claim: use `withSystemContext({ tenantId }, fn)`.
|
|
186
|
+
*/
|
|
187
|
+
export declare class NoVerifiedTenantClaims extends DbRlsError {
|
|
188
|
+
readonly helper: string | null;
|
|
189
|
+
constructor(helper?: string);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Thrown when something tries to bind verified claims while claims are
|
|
193
|
+
* ALREADY bound in the current async context.
|
|
194
|
+
*
|
|
195
|
+
* Re-binding is refused unconditionally, including to identical claims.
|
|
196
|
+
* The whole point of deriving the tenant from a request-scoped store is
|
|
197
|
+
* that a handler downstream of auth middleware cannot choose a different
|
|
198
|
+
* one; a permitted nested bind would hand that ability straight back
|
|
199
|
+
* ("bind again with `req.body.tenantId`"), so it is refused rather than
|
|
200
|
+
* merged, warned about, or last-write-wins.
|
|
201
|
+
*/
|
|
202
|
+
export declare class VerifiedTenantClaimsAlreadyBound extends DbRlsError {
|
|
203
|
+
readonly boundTenantId: string;
|
|
204
|
+
readonly attemptedTenantId: string;
|
|
205
|
+
constructor(boundTenantId: string, attemptedTenantId: string);
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Thrown when the claim set handed to `runWithVerifiedTenantClaims` is not
|
|
209
|
+
* usable — a missing / non-string / blank `userId` or `tenantId` (or a
|
|
210
|
+
* blank `sourceIp`).
|
|
211
|
+
*
|
|
212
|
+
* Rejected at BIND time rather than at query time on purpose. A blank
|
|
213
|
+
* tenant binds an empty `app.tenant_id` GUC, and the RLS predicate then
|
|
214
|
+
* resolves nothing — which surfaces as "this user has no rows", not as
|
|
215
|
+
* "this request was refused".
|
|
216
|
+
*/
|
|
217
|
+
export declare class InvalidVerifiedTenantClaims extends DbRlsError {
|
|
218
|
+
readonly field: string;
|
|
219
|
+
constructor(field: string, detail: string);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Thrown when an authenticated-pool helper is called with the retired
|
|
223
|
+
* `helper(opts, fn)` shape — i.e. something passed a tenant.
|
|
224
|
+
*
|
|
225
|
+
* TypeScript rejects this at compile time (the helpers take the callback as
|
|
226
|
+
* their only argument). This error is the runtime backstop for consumers
|
|
227
|
+
* that do not typecheck against this package: plain JavaScript, a stale
|
|
228
|
+
* published `dist/`, or an `any`-typed wrapper. Without it the opts object
|
|
229
|
+
* would be invoked as the callback and the failure would read as
|
|
230
|
+
* `opts is not a function` — a db-rls bug rather than an unmigrated call.
|
|
231
|
+
*/
|
|
232
|
+
export declare class TenantArgumentRefused extends DbRlsError {
|
|
233
|
+
readonly helper: string;
|
|
234
|
+
constructor(helper: string, received: string);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* THE STEP-1 SEAM, refused by name. Thrown when a system-pool helper
|
|
238
|
+
* (`withSystemContext` / `withSystemContextDb` /
|
|
239
|
+
* `withSystemContextDbPostgresJs`, or `autoDispatch`'s system leg) is
|
|
240
|
+
* called INSIDE a request that has verified tenant claims bound, without
|
|
241
|
+
* an explicit non-blank `{ reason }`.
|
|
242
|
+
*
|
|
243
|
+
* The services-pool predicate is the bare
|
|
244
|
+
* `tenant_id = auth.get_tenant_id()` — it trusts the GUC completely and
|
|
245
|
+
* proves no membership. So an authenticated request that falls through to
|
|
246
|
+
* the system pool re-opens exactly the forgery the verified-claims binding
|
|
247
|
+
* closes on the authenticated pool: the handler supplies the tenant, and
|
|
248
|
+
* nothing checks the principal holds it. That fall-through is the seam
|
|
249
|
+
* where the ₹250,000 cross-tenant refund reproduced.
|
|
250
|
+
*
|
|
251
|
+
* This is a THROW, not a warning, and it fires BEFORE any pool is
|
|
252
|
+
* acquired. Deliberate system work inside a request (an outbox write, a
|
|
253
|
+
* cross-tenant rollup) passes `{ reason: "..." }`, which sanctions the
|
|
254
|
+
* escape AND emits it to telemetry
|
|
255
|
+
* (`db_rls.cross_pool_nesting_total{outer=authenticated,inner=services,reason}`)
|
|
256
|
+
* so every such crossing is named, counted, and audit-greppable. Unbound
|
|
257
|
+
* contexts (workers, cron, boot, S2S, webhooks) never see this error.
|
|
258
|
+
*/
|
|
259
|
+
export declare class SystemContextUnderClaimsRefused extends DbRlsError {
|
|
260
|
+
readonly helper: string;
|
|
261
|
+
readonly boundTenantId: string;
|
|
262
|
+
readonly requestedTenantId: string;
|
|
263
|
+
constructor(helper: string, boundTenantId: string, requestedTenantId: string);
|
|
120
264
|
}
|
|
121
265
|
/**
|
|
122
266
|
* Thrown when something asks for a database session that would let a tenant
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAoBA;;;;;wDAKwD;AACxD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,UAAU,GAAG,eAAe,GAAG,cAAc,CAAC;AAE/E;;wBAEwB;AACxB,MAAM,WAAW,IAAI;IACnB,6CAA6C;IAC7C,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9D,uDAAuD;IACvD,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,kEAAkE;IAClE,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;CAC7B;AAED,sEAAsE;AACtE,MAAM,WAAW,MAAM;IACrB,iDAAiD;IACjD,QAAQ,CAAC,IAAI,EAAE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EAAE,MAAM,CAAC;gBACd,QAAQ,EAAE,MAAM;CAO7B;AAED;;;;;;GAMG;AACH,qBAAa,gBAAiB,SAAQ,UAAU;gBAClC,OAAO,EAAE,MAAM;CAI5B"}
|
package/dist/types.js
CHANGED
|
@@ -40,11 +40,134 @@ export class PoolUnavailable extends DbRlsError {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
export class MissingTenantContext extends DbRlsError {
|
|
43
|
-
constructor() {
|
|
44
|
-
super(
|
|
43
|
+
constructor(detail) {
|
|
44
|
+
super(detail
|
|
45
|
+
? `missing_tenant_context: ${detail}`
|
|
46
|
+
: "missing_tenant_context: a tenant-scoped helper was called without a tenant.");
|
|
45
47
|
this.name = "MissingTenantContext";
|
|
46
48
|
}
|
|
47
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Thrown by the authenticated-pool helpers when NOTHING bound verified
|
|
52
|
+
* claims for the current request.
|
|
53
|
+
*
|
|
54
|
+
* Fail closed and loud. There is no default tenant, no fallback to a
|
|
55
|
+
* caller-supplied value, and no "return an empty result and carry on" — a
|
|
56
|
+
* silently-empty result is how the crm 85-policy blackout hid for weeks.
|
|
57
|
+
* If you see this, the cause is one of:
|
|
58
|
+
*
|
|
59
|
+
* 1. Your auth middleware does not call `runWithVerifiedTenantClaims`
|
|
60
|
+
* yet (the usual one — see the migration note in the README).
|
|
61
|
+
* 2. The DB call escaped the request's async context: it was scheduled
|
|
62
|
+
* with `setTimeout` / an unawaited promise / a queue callback that
|
|
63
|
+
* outlives the request, so the AsyncLocalStorage store is gone. Await
|
|
64
|
+
* the work inside the request, or run it as a worker on
|
|
65
|
+
* `withSystemContext({ tenantId }, fn)`.
|
|
66
|
+
* 3. It genuinely is not an authenticated request — a worker, cron job,
|
|
67
|
+
* S2S call, or webhook. Those have a legitimately resolved tenant and
|
|
68
|
+
* no user claim: use `withSystemContext({ tenantId }, fn)`.
|
|
69
|
+
*/
|
|
70
|
+
export class NoVerifiedTenantClaims extends DbRlsError {
|
|
71
|
+
helper;
|
|
72
|
+
constructor(helper) {
|
|
73
|
+
super(`no_verified_tenant_claims: ${helper ? `${helper}()` : "an authenticated-pool helper"} needs the request's VERIFIED claims, and none are bound in this async context. The tenant is derived from those claims — it is not an argument, and there is no default. Bind them ONCE in auth middleware, straight after JWT verification: runWithVerifiedTenantClaims({ userId: claims.sub, tenantId: claims.tenant_id }, () => next()). If this is a worker / cron / S2S / webhook with no user claim, use withSystemContext({ tenantId }, fn) instead. If it is a request whose DB work escaped the request scope (setTimeout, unawaited promise, queue callback), await the work inside the request.`);
|
|
74
|
+
this.name = "NoVerifiedTenantClaims";
|
|
75
|
+
this.helper = helper ?? null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Thrown when something tries to bind verified claims while claims are
|
|
80
|
+
* ALREADY bound in the current async context.
|
|
81
|
+
*
|
|
82
|
+
* Re-binding is refused unconditionally, including to identical claims.
|
|
83
|
+
* The whole point of deriving the tenant from a request-scoped store is
|
|
84
|
+
* that a handler downstream of auth middleware cannot choose a different
|
|
85
|
+
* one; a permitted nested bind would hand that ability straight back
|
|
86
|
+
* ("bind again with `req.body.tenantId`"), so it is refused rather than
|
|
87
|
+
* merged, warned about, or last-write-wins.
|
|
88
|
+
*/
|
|
89
|
+
export class VerifiedTenantClaimsAlreadyBound extends DbRlsError {
|
|
90
|
+
boundTenantId;
|
|
91
|
+
attemptedTenantId;
|
|
92
|
+
constructor(boundTenantId, attemptedTenantId) {
|
|
93
|
+
super(`verified_tenant_claims_already_bound: this request already has verified claims bound for tenant ${JSON.stringify(boundTenantId)}, and something tried to re-bind it to ${JSON.stringify(attemptedTenantId)}. Re-binding is refused unconditionally — it is the one shape that would let a handler downstream of auth middleware pick a different tenant, which is the forgery this fence exists to prevent. Bind exactly once, at the outermost auth boundary. A worker that needs a different tenant is not an authenticated request: use withSystemContext({ tenantId }, fn).`);
|
|
94
|
+
this.name = "VerifiedTenantClaimsAlreadyBound";
|
|
95
|
+
this.boundTenantId = boundTenantId;
|
|
96
|
+
this.attemptedTenantId = attemptedTenantId;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Thrown when the claim set handed to `runWithVerifiedTenantClaims` is not
|
|
101
|
+
* usable — a missing / non-string / blank `userId` or `tenantId` (or a
|
|
102
|
+
* blank `sourceIp`).
|
|
103
|
+
*
|
|
104
|
+
* Rejected at BIND time rather than at query time on purpose. A blank
|
|
105
|
+
* tenant binds an empty `app.tenant_id` GUC, and the RLS predicate then
|
|
106
|
+
* resolves nothing — which surfaces as "this user has no rows", not as
|
|
107
|
+
* "this request was refused".
|
|
108
|
+
*/
|
|
109
|
+
export class InvalidVerifiedTenantClaims extends DbRlsError {
|
|
110
|
+
field;
|
|
111
|
+
constructor(field, detail) {
|
|
112
|
+
super(`invalid_verified_tenant_claims: ${field} — ${detail}. These fields must come off the VERIFIED JWT claim set (sub / tenant claim), never off the request body, path params, or headers.`);
|
|
113
|
+
this.name = "InvalidVerifiedTenantClaims";
|
|
114
|
+
this.field = field;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Thrown when an authenticated-pool helper is called with the retired
|
|
119
|
+
* `helper(opts, fn)` shape — i.e. something passed a tenant.
|
|
120
|
+
*
|
|
121
|
+
* TypeScript rejects this at compile time (the helpers take the callback as
|
|
122
|
+
* their only argument). This error is the runtime backstop for consumers
|
|
123
|
+
* that do not typecheck against this package: plain JavaScript, a stale
|
|
124
|
+
* published `dist/`, or an `any`-typed wrapper. Without it the opts object
|
|
125
|
+
* would be invoked as the callback and the failure would read as
|
|
126
|
+
* `opts is not a function` — a db-rls bug rather than an unmigrated call.
|
|
127
|
+
*/
|
|
128
|
+
export class TenantArgumentRefused extends DbRlsError {
|
|
129
|
+
helper;
|
|
130
|
+
constructor(helper, received) {
|
|
131
|
+
super(`tenant_argument_refused: ${helper}() takes the callback as its ONLY argument and derives the tenant from the request's verified claims — it received ${received} where the callback was expected, which is the retired ${helper}(opts, fn) shape. The tenant was a parameter a handler passed in, so any handler that passed a request-derived tenant instead of the verified claim silently defeated RLS; it is no longer expressible. Bind claims once in auth middleware — runWithVerifiedTenantClaims({ userId, tenantId }, () => next()) — then call ${helper}(async (tx) => ...). Workers / cron / S2S / webhooks keep their explicit tenant: withSystemContext({ tenantId }, fn).`);
|
|
132
|
+
this.name = "TenantArgumentRefused";
|
|
133
|
+
this.helper = helper;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* THE STEP-1 SEAM, refused by name. Thrown when a system-pool helper
|
|
138
|
+
* (`withSystemContext` / `withSystemContextDb` /
|
|
139
|
+
* `withSystemContextDbPostgresJs`, or `autoDispatch`'s system leg) is
|
|
140
|
+
* called INSIDE a request that has verified tenant claims bound, without
|
|
141
|
+
* an explicit non-blank `{ reason }`.
|
|
142
|
+
*
|
|
143
|
+
* The services-pool predicate is the bare
|
|
144
|
+
* `tenant_id = auth.get_tenant_id()` — it trusts the GUC completely and
|
|
145
|
+
* proves no membership. So an authenticated request that falls through to
|
|
146
|
+
* the system pool re-opens exactly the forgery the verified-claims binding
|
|
147
|
+
* closes on the authenticated pool: the handler supplies the tenant, and
|
|
148
|
+
* nothing checks the principal holds it. That fall-through is the seam
|
|
149
|
+
* where the ₹250,000 cross-tenant refund reproduced.
|
|
150
|
+
*
|
|
151
|
+
* This is a THROW, not a warning, and it fires BEFORE any pool is
|
|
152
|
+
* acquired. Deliberate system work inside a request (an outbox write, a
|
|
153
|
+
* cross-tenant rollup) passes `{ reason: "..." }`, which sanctions the
|
|
154
|
+
* escape AND emits it to telemetry
|
|
155
|
+
* (`db_rls.cross_pool_nesting_total{outer=authenticated,inner=services,reason}`)
|
|
156
|
+
* so every such crossing is named, counted, and audit-greppable. Unbound
|
|
157
|
+
* contexts (workers, cron, boot, S2S, webhooks) never see this error.
|
|
158
|
+
*/
|
|
159
|
+
export class SystemContextUnderClaimsRefused extends DbRlsError {
|
|
160
|
+
helper;
|
|
161
|
+
boundTenantId;
|
|
162
|
+
requestedTenantId;
|
|
163
|
+
constructor(helper, boundTenantId, requestedTenantId) {
|
|
164
|
+
super(`system_context_under_verified_claims_refused: ${helper}() was called INSIDE a request that has verified tenant claims bound (tenant ${JSON.stringify(boundTenantId)}), asking the services pool for tenant ${JSON.stringify(requestedTenantId)} — with no { reason }. The services-pool predicate is the bare tenant_id = auth.get_tenant_id() with NO membership proof, so an authenticated request that falls through to it can aim the session at ANY tenant; this is the un-fenced seam where the ₹250,000 cross-tenant refund reproduced. If this really is deliberate system work inside a request (an outbox write, a cross-tenant rollup), pass an explicit { reason: "..." } — the escape is then emitted to telemetry (db_rls.cross_pool_nesting_total) and audit-greppable. Otherwise stay on the authenticated pool: withUserContext(fn). Workers / cron / S2S / webhooks with no bound claims are unaffected and need no reason.`);
|
|
165
|
+
this.name = "SystemContextUnderClaimsRefused";
|
|
166
|
+
this.helper = helper;
|
|
167
|
+
this.boundTenantId = boundTenantId;
|
|
168
|
+
this.requestedTenantId = requestedTenantId;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
48
171
|
/**
|
|
49
172
|
* Thrown when something asks for a database session that would let a tenant
|
|
50
173
|
* user reach more than one tenant's rows.
|
|
@@ -62,7 +185,7 @@ export class MissingTenantContext extends DbRlsError {
|
|
|
62
185
|
export class CrossTenantSessionRefused extends DbRlsError {
|
|
63
186
|
helper;
|
|
64
187
|
constructor(helper) {
|
|
65
|
-
super(`cross_tenant_session_refused: ${helper}() opened an authenticated-pool session with NO tenant bound, so the RLS predicate resolved across EVERY tenant the principal belonged to. That is the mechanism of the cross-tenant approval incident, and it is no longer available. Use withUserContext(
|
|
188
|
+
super(`cross_tenant_session_refused: ${helper}() opened an authenticated-pool session with NO tenant bound, so the RLS predicate resolved across EVERY tenant the principal belonged to. That is the mechanism of the cross-tenant approval incident, and it is no longer available. Use withUserContext(fn) — the tenant comes from the request's VERIFIED claims, bound once by auth middleware via runWithVerifiedTenantClaims, and is no longer an argument. To LIST a user's tenants (switcher / login picker), query auth.user_tenant_ids from a services-pool context — that function is intact; what is gone is opening a data session that spans them. Nodii staff cross-tenant access is unchanged: withPlatformOpsContext.`);
|
|
66
189
|
this.name = "CrossTenantSessionRefused";
|
|
67
190
|
this.helper = helper;
|
|
68
191
|
}
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,EAAE;AACF,gBAAgB;AAChB,qDAAqD;AACrD,uEAAuE;AACvE,0EAA0E;AAC1E,oDAAoD;AACpD,0EAA0E;AAC1E,wBAAwB;AACxB,+DAA+D;AAC/D,iDAAiD;AACjD,EAAE;AACF,uCAAuC;AACvC,0CAA0C;AAC1C,kDAAkD;AAClD,0EAA0E;
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,8CAA8C;AAC9C,EAAE;AACF,oEAAoE;AACpE,uEAAuE;AACvE,EAAE;AACF,gBAAgB;AAChB,qDAAqD;AACrD,uEAAuE;AACvE,0EAA0E;AAC1E,oDAAoD;AACpD,0EAA0E;AAC1E,wBAAwB;AACxB,+DAA+D;AAC/D,iDAAiD;AACjD,EAAE;AACF,uCAAuC;AACvC,0CAA0C;AAC1C,kDAAkD;AAClD,0EAA0E;AAqK1E,+EAA+E;AAC/E,yBAAyB;AAEzB,MAAM,OAAO,UAAW,SAAQ,KAAK;IACnC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,UAAU;IACjD;QACE,KAAK,CACH,uHAAuH,CACxH,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,C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sB,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,UAAU;IAC1C,KAAK,CAAU;IACxB,YAAY,KAAc;QACxB,KAAK,CACH,4BACE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CACvD,EAAE,CACH,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,uBAAuB,CAAC;QACpC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF;AAED;;;;;;;;GAQG;AACH,MAAM,OAAO,0BAA2B,SAAQ,UAAU;IAC/C,QAAQ,CAAS;IAC1B,YAAY,QAAgB;QAC1B,KAAK,CACH,4CAA4C,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,gOAAgO,CACrS,CAAC;QACF,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;QACzC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;CACF;AAED;;;;;;GAMG;AACH,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAC9C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nodii/db-rls",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.14.0",
|
|
4
4
|
"description": "Three-pool RLS dispatch + GUC-set + entry-point helpers + RLS policy DDL generator for the Nodii microservice stack. Polyglot per D159 (TS + Python + Go). Spec: planning hub docKey=db-rls.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -62,7 +62,7 @@
|
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
|
-
"@nodii/telemetry": "0.
|
|
65
|
+
"@nodii/telemetry": "0.29.0",
|
|
66
66
|
"@types/bun": "^1.3.13",
|
|
67
67
|
"@types/pg": "^8.11.10",
|
|
68
68
|
"drizzle-orm": "^0.45.2",
|