A database permission rule can only evaluate the context it receives. If the application supplies the wrong organisation or leaves stale state on a reused connection, a correct-looking session check may still lead to the wrong data boundary.
Trace identity from the incoming request to the actual database operation. Record which component verifies the user, resolves membership, sets tenant context, and clears or isolates that context afterward.
Distinguish identity claims from resource authority
A session identifies a user and may carry organisation information. The application still needs to confirm that the requested resource belongs to the intended organisation and that the action is permitted under the chosen freshness policy.
If database row security is used, review the actual runtime role. The PostgreSQL row-security reference describes circumstances where roles bypass policies. Policy definitions alone are insufficient evidence that application queries are constrained.
Run a fictional pooled-connection exercise
Create two organisations with distinct fixture values and a user who can access both. Send a request for organisation Larch, followed by one for organisation Ash, through the same application runtime. Repeat while requests overlap and while the connection pool reuses available connections.
Check the effective tenant context at the database boundary using safe diagnostics that avoid customer content. Confirm each response contains only the intended fixture. Then use an account that belongs to Larch only and request an Ash resource directly.
Change membership and repeat from an old session. The expected result depends on the documented revocation policy, but it should not depend on whichever connection happened to serve the request. Add a background job because workers may establish identity differently from web requests.
Keep context scoped to the operation
Use the database and framework mechanisms appropriate to your environment to bind context to a request or transaction. Verify cleanup and failure behaviour rather than assuming that an application-level variable controls every query.
Avoid executing unrelated tenant work under an unrestricted connection simply for convenience. If privileged maintenance is necessary, keep it separate, named, and auditable. The same database can legitimately serve both constrained application work and privileged administration, but their boundaries need explicit review.
The tradeoff is defence depth versus complexity. Adding database policies can reduce the consequences of a missed application filter, while also introducing context and role behaviour to test. Application checks remain useful for clear action semantics and user-facing errors.
The StackFlight product account provides related PostgreSQL-backed SaaS context. The pooled-connection scenario is a proposed test and makes no claim about its internal access architecture.
Questions about session and database consistency
Does a tenant filter replace membership validation?
No. Filtering by an untrusted organisation ID can consistently return the wrong tenant's data. Establish trusted authority before applying the filter.
Should tests use an administrator database role?
Use the actual application role for enforcement tests. Separately review privileged paths because their behaviour can differ.
What should a review trace contain?
Include request identity, intended tenant, effective database context, operation, and result category. Bring a redacted trace to a tenant-isolation review.