Tenant context is set from authenticated session, not client input
Why it matters
Sourcing tenant context from client-supplied values — a request body tenantId, a query parameter, or an unverified path segment — is CWE-639 and OWASP A04 (Insecure Design) in combination: any user who can forge or swap that value gains access to an arbitrary tenant's data. This is not a theoretical risk; it is one of the most common multi-tenancy bugs because the attack requires only changing a single field in a normal API call. NIST AC-3 requires that access decisions be based on authoritative session state, not client assertions.
Severity rationale
Critical because any authenticated user can swap a single request parameter to impersonate a different tenant and read or write their data.
Remediation
Resolve tenant identity exclusively from the server-side session. If a tenant ID appears in the URL (e.g., /api/orgs/:orgId/), treat it as an untrusted assertion and cross-check it against the authenticated user's memberships before using it:
// src/middleware/tenantAuth.ts
const session = await getServerSession()
if (!session) return new Response('Unauthorized', { status: 401 })
const { orgId } = params
const membership = await db.memberships.findFirst({
where: { userId: session.user.id, organizationId: orgId }
})
if (!membership) return new Response('Forbidden', { status: 403 })
// Safe to use orgId now — membership is confirmed
Never pass tenantId from request bodies into database where clauses without this validation step. Centralize the membership check in middleware so no route can accidentally skip it.
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Multi-Tenancy Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-639 — Authorization Bypass Through User-Controlled Key
- cwe · CWE-807 — Reliance on Untrusted Inputs in a Security Decision
- owasp:2021 · A01 — Broken Access Control
- owasp:2021 · A04 — Insecure Design
- soc2:2017 · C1.1 — Identification and protection of confidential information
- soc2:2017 · CC6.1 — Logical access security software, infrastructure, and architectures
Taxons
History
- 2026-04-18·v1.0.0·Initial import from saas-multi-tenancy·automated
- 2026-07-06·v1.0.1·Add SOC 2 TSC mapping (C1.1, CC6.1) from the verified compliance crosswalk register (docs/compliance/).·by soc2-mapping-enrichment-ship-2