Skip to content

[finding][drivers] SqlDriver.findWithWindowFunctions and analyzeQuery skip applyTenantScope — a row-returning read door outside the driver's "single chokepoint" for tenant isolation #6792

Description

@os-zhuang

Found while implementing #6577 (the limit: 0 presence fix), whose file surface was these exact two methods. Out of that card's scope — a different defect with a different blast radius, and folding a tenant-isolation fix into a limit: 0 PR would bury it — so filed rather than fixed, per Prime Directive #10.

Fact (located by inspection on origin/main @ 3172831, not executed)

applyTenantScope says of itself, verbatim:

This is the single chokepoint for read-side tenant isolation in the SQL driver; every CRUD method routes through it.

It is called at 13 sites in packages/drivers/driver-sql/src/sql-driver.tsfindRows (the door find() uses), the readbacks, count, distinct, the write paths. It is not called by two:

So the declared invariant is false as written: two doors bypass the chokepoint.

Why the two are not equally severe

What is NOT claimed here

Not measured end-to-end. I did not build a multi-tenant fixture and read another tenant's rows through this door — this is located by reading the call sites and the method's own contract, and it is stated at that strength deliberately. What reaches findWithWindowFunctions in practice needs checking before grading severity: it is not on IDataDriver (it is callable only on a SQL driver instance, per its own docstring), so the exposure depends on who calls it and whether they pass options.tenantId. A grader should measure that reachability first — it is the difference between a latent trap and a live P0.

Also note the layers above: ADR-0021 RLS and the Layer 0 authorization wall may or may not already constrain the callers of this door. "The layer above catches it" is a reason to grade lower, not a reason for the driver's own stated chokepoint to have a hole.

Suggested shape of a fix (not prescriptive)

Add this.applyTenantScope(builder, object, options) to both, beside the getBuilder call, as every other door does. The interesting question is not the two lines but the missing enforcement: nothing makes a new read door route through the chokepoint, which is exactly how these two got out. A gate that asserts every method taking (object, …, options) and returning rows calls applyTenantScope would be the durable version — the check:-script shape this repo already uses for the same class of claim.

Dedup

Searched applyTenantScope, findWithWindowFunctions, and tenant-scope/read-door phrasings across the repo's issues. Nearest neighbours are all closed and different: #3724 (driver-mongodb has no row-level isolation at all), #3249 / #2754 (tenant scope hiding NULL-org platform rows — the opposite direction), #4286 (window-function door liveness, not its tenancy). No open card covers this.

Filed unassigned, finding posture.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions