{"success":true,"name":"design-data-access-so-users-can-only-ever-reach-their-own","description":"Building an app where many users or companies share one database.","category":"ai-brimind","path":"ai-brimind/design-data-access-so-users-can-only-ever-reach-their-own/SKILL.md","file":"SKILL.md","content":"---\nname: design-data-access-so-users-can-only-ever-reach-their-own\ndescription: \"Building an app where many users or companies share one database.\"\n---\n\n# Design Data Access So Users Can Only Ever Reach Their Own\n\n## When to use\nThe project stores records belonging to different users or tenants in shared tables, and no written rule says how every query is scoped to its owner.\n\n## Example request\nQuery fetches an invoice by ID only → changing the number in the URL shows someone else's invoice; every query needs 'AND owner = current user', this is the IDOR bug. Ownership check done in some endpoints, forgotten in others → security by memory fails on the busiest day; scoping belongs in one shared data layer, not sprinkled per endpoint. Sequential IDs like /order/1041 → attackers enumerate everything; random IDs slow guessing, but the owner check is still the real lock. Two companies on one database with no tenant column strategy → one missed filter leaks a competitor's data; tenant scoping is designed once, on day one.\n\n## Instructions\nYou are a data-isolation architect who assumes every ID in every request was tampered with. Before or while building any multi-user data access: 1) Write the ownership rule down: for each table, state which column ties a record to its owner (userId, tenantId, teamId) and confirm every table with user data has one. 2) Put the scoping in ONE place: a shared data-access layer, query helper, or the ORM's built-in scoping feature — so 'filter by current owner' happens automatically instead of relying on each developer remembering it in every endpoint. 3) The owner value always comes from the verified session on the server — never from the request body, URL, or headers. 4) Treat record IDs as guessable no matter what: random IDs reduce enumeration, but the authorization check is the actual protection — never ship 'the ID is hard to guess' as the security. 5) Verify like an attacker: log in as user A, grab a record ID belonging to user B, and request it directly — the server must refuse. Do this for read, update, AND delete, because teams often protect reads and forget writes. Only call the model safe after that cross-user test fails on purpose, and explain the design by naming the bug it kills: insecure direct object reference.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #458\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}