examples
Tenant ID Trusted from Client examples
These examples show how Tenant ID Trusted from Client problems ship in real apps — and what fixes actually work when tested via direct API access.
Why Tenant ID Trusted from Client examples matter
Cross-tenant data leaks happen as soon as the client controls the tenant dimension. If Tenant ID Trusted from Client remains unresolved, attackers can automate enumeration and unauthorized writes at API speed. Treat it as a production reliability risk as well as a data security risk, because incidents spread quickly once clients discover weak access boundaries.
Examples about Tenant ID Trusted from Client
| Example | Summary | URL |
|---|---|---|
| Tenant ID Trusted from Client: direct API bypass | Trusting the tenant_id parameter let attackers read other tenants’ data. | /examples/tenant-id-trust-in-client/direct-api-bypass-tenant-id-trust-in-client |
| Tenant ID Trusted from Client: migration drift regression | A migration introduced a new endpoint that accepted tenant IDs from the client and reopened exposure. | /examples/tenant-id-trust-in-client/migration-drift-tenant-id-trust-in-client |
Root cause → fix pattern analysis for Tenant ID Trusted from Client
Examples are most useful when you can translate them into a repeatable fix pattern. This table highlights the “why” behind each fix:
| Example | Root cause | Fix pattern | URL |
|---|---|---|---|
| Tenant ID Trusted from Client: direct API bypass | Attackers changed the tenant_id value and the backend returned rows for other tenants. | Derive the tenant from the authenticated token or server context and ignore client-provided IDs. | /examples/tenant-id-trust-in-client/direct-api-bypass-tenant-id-trust-in-client |
| Tenant ID Trusted from Client: migration drift regression | The client-supplied value allowed cross-tenant reads because the server accepted it as authoritative. | Require backend code to map the authenticated user to their tenant and include tenant checks in migration processes. | /examples/tenant-id-trust-in-client/migration-drift-tenant-id-trust-in-client |
How Tenant ID Trusted from Client failures typically happen
- Using
tenant_idquery parameters as the source of truth. - Not binding tenant claims in policies.
- Assuming tenant IDs remain constant without validation.
Fix patterns that tend to work for Tenant ID Trusted from Client
Across these examples, the highest-leverage fixes share a theme: remove direct client access and make verification repeatable.
- Backend-only access for sensitive operations (server endpoints enforce authorization).
- Least-privilege grants: revoke broad privileges from anon/authenticated.
- Small, testable policies if you intentionally keep client access — avoid complex conditions.
- A verification step that proves direct access fails (not just that the UI hides data).
How to spot Tenant ID Trusted from Client in your own project (signals)
- A direct API call returns rows/files even when the UI is supposed to restrict them.
- RLS/policies exist, but access still succeeds (often because RLS is disabled or policies are too broad).
- Permissions depend on the client behaving “nicely” (UI checks) rather than the database enforcing access.
- After a migration, access behavior changes unexpectedly (drift).
How to use these examples to fix your own app
- Match the scenario to your table/bucket/function setup.
- Identify the root cause (not just the symptom).
- Apply the relevant template or conversion guide.
- Verify direct access fails for client credentials.
- Document the rule so it doesn’t regress.
Verification checklist for Tenant ID Trusted from Client fixes
- Reproduce the issue once using direct API access (anon/authenticated) so you know it’s real.
- Apply the fix pattern (backend-only access + least privilege) using a template.
- Repeat the same direct access call and confirm it now fails.
- Confirm the app still works via backend endpoints for authorized users.
- Re-scan after the fix and add a drift guard for the next migration.
Preventing Tenant ID Trusted from Client regressions (drift guard)
- Re-run the same direct access test after every migration that touches auth, policies, grants, Storage, or functions.
- Keep a short inventory of sensitive resources and treat them as server-only by default.
- Review new tables/buckets/functions in code review with an access-control checklist.
- If you intentionally allow client access, document the policy rationale and add tests for it.
Optional SQL checks for Tenant ID Trusted from Client (extra confidence)
If you like having a repeatable “proof”, add a small set of SQL checks to your process.
- Confirm RLS status for tables involved (enabled/forced where appropriate).
- List policies and read them as plain language: who can do what under what condition?
- Audit grants to anon/authenticated and PUBLIC for tables, views, and functions tied to this topic.
- If Storage/RPC is involved, explicitly audit bucket settings and EXECUTE grants.
These checks complement (not replace) the direct access tests shown in the examples.
Decision guide for Tenant ID Trusted from Client: template vs conversion vs integration
If you’re here because you found this topic in a scan, the fastest path depends on whether the fix is a small config change or a workflow change.
- Choose a template when you need a copy/paste change plus verification (tighten a policy/grant/bucket setting).
- Choose a conversion when you need to change an access model end-to-end (unsafe → backend-only) with example transformations.
- Choose an integration when the fix is a workflow pattern you’ll repeat (signed URLs, server-only RPC, backend endpoints).
If you’re unsure, start with the smallest template that removes direct client access, then add integrations for durability.
Evidence to keep after fixing Tenant ID Trusted from Client (makes reviews faster)
Teams often “fix” a topic but can’t prove it later. Save a few small artifacts so you can re-verify after migrations:
- The direct access request you used before the fix (and the expected denial after).
- A short boundary statement (who can access what, through which server endpoint).
- The change you applied (policy/grant/bucket setting/EXECUTE revoke) and why.
- The drift guard you’ll run after migrations (scan, checklist query, or release checklist item).
Related pages
- Glossary: Tenant ID Trusted from Client →
/glossary/tenant-id-trust-in-client - Template: Lock down a public table (backend-only access) →
/templates/access-control/lock-down-public-table - Template: Remove over-permissive RLS policies (adopt deny-by-default) →
/templates/access-control/remove-over-permissive-policies
What to do after you fix one example (so it stays fixed)
One fixed example is great — but the real win is preventing drift.
- Write a one-sentence boundary statement (who can access what, through which server path).
- Keep the one direct access test you used before the fix (and expect it to fail after).
- Re-run the same test after migrations that touch policies, grants, buckets, or functions.
If you can re-run the test and it still fails, you’ve turned a one-time fix into a durable control.
FAQ
What’s the fastest fix pattern when Tenant ID Trusted from Client shows up in a scan?
Prefer backend-only access and remove direct client privileges. Then add verification checks that prove direct access fails.
Can I fix Tenant ID Trusted from Client with policies alone?
Sometimes, but it’s easy to get subtly wrong. Use these examples to learn the failure modes, and verify with direct API tests.
How do I choose between examples, templates, and conversions?
Examples explain the pattern, templates show concrete implementation, and conversions describe the whole transformation from unsafe to safe.
Next step
Want to know if your project matches any of these scenarios? Run a Mockly scan and compare your findings to the examples here.