{"success":true,"name":"secure-the-endpoint-by-asking-who-may-call-it-and-what-they-","description":"Creating or exposing an endpoint that touches user data or actions","category":"ai-brimind","path":"ai-brimind/secure-the-endpoint-by-asking-who-may-call-it-and-what-they-/SKILL.md","file":"SKILL.md","content":"---\nname: secure-the-endpoint-by-asking-who-may-call-it-and-what-they-\ndescription: \"Creating or exposing an endpoint that touches user data or actions\"\n---\n\n# Secure the Endpoint by Asking Who May Call It and What They May See\n\n## When to use\nYou are adding or modifying an endpoint, and you haven't explicitly decided its authentication and authorization rules yet.\n\n## Example request\nEndpoint checks login but not ownership → any logged-in user can read others' data by changing the id; that's broken object-level authorization (IDOR). — Admin route relies on the frontend hiding the button → direct calls bypass it; authorization must live on the server. — Internal endpoint 'nobody knows about' left open → attackers scan, they don't guess from the UI; security by obscurity is not a mechanism. — Token accepted but never checked for expiry or scope → old or weak tokens work forever; the auth middleware already handles this if actually used.\n\n## Instructions\nAct as a security-minded gatekeeper who treats every endpoint as reachable by anyone on the internet until proven otherwise. For the endpoint: 1) Answer two separate questions in writing — WHO may call it (authentication) and WHAT that caller may see or change (authorization). They are different checks; passing the first never implies the second. 2) Reuse the project's existing auth mechanism (middleware, guards, token verification) — never hand-roll a check when one exists, and never trust anything the frontend hides or sends about the user's role. 3) For any resource fetched by id, verify the caller owns it or has a role that allows it — check object-level access, not just login. 4) Return only the fields this caller needs; strip internal or other-users' data before responding. 5) If the access rules are not specified, ask the owner — do not guess and do not default to open. Only expose the endpoint once both checks are confirmed in place, and explain why each check blocks the real attack path, not just satisfies a checklist.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #888\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}