{"success":true,"name":"check-authorization-on-every-route-and-every-object-not-just","description":"Adding pages or APIs where different users may access different data","category":"ai-brimind","path":"ai-brimind/check-authorization-on-every-route-and-every-object-not-just/SKILL.md","file":"SKILL.md","content":"---\nname: check-authorization-on-every-route-and-every-object-not-just\ndescription: \"Adding pages or APIs where different users may access different data\"\n---\n\n# Check Authorization on Every Route and Every Object, Not Just at Login\n\n## When to use\nThe app has more than one user or role, and you are writing a route, API, or query that reads or changes data belonging to someone.\n\n## Example request\nLogin is checked, so all routes feel safe → login only proves who you are, not what you may touch; each route still needs its own permission check (authentication vs authorization). An order page loads /orders/1052 → any logged-in user can change the number and read other people's orders; the query must filter by the owner (IDOR / broken object-level access). Admin API trusts that only admins know the URL → URLs are guessable; the server must verify the role on every admin endpoint (no security by obscurity). An update endpoint accepts any fields the client sends → a user adds role:'admin' to the request body; the server must whitelist which fields can change (mass assignment).\n\n## Instructions\nAct like a reviewer whose only question is: 'who is allowed to do this, and where is that enforced?' For every route, API handler, or query you write, separate the two checks and do both: authentication (is there a valid logged-in identity?) and authorization (is THIS identity allowed to do THIS action on THIS specific record?). Authorization must be tied to the data itself: queries filter by the owner or team taken from the session, never from a client-sent ID; role checks run on the server for every protected endpoint, not once in the UI; update operations accept an explicit whitelist of fields so users cannot promote themselves. Check whether the framework offers middleware, guards, or policies to centralize these checks and prefer them over repeating if-statements everywhere. Test your work by role-playing the attacker: take a normal user's session and try another user's IDs, admin URLs, and extra JSON fields. If any of those succeed, the route is broken no matter how correct the UI looks. Only finish when every route names its rule (public, owner-only, role X) and you can explain where the server enforces it, not just where the interface hides it.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #531\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}