{"success":true,"name":"validate-input-and-check-permissions-on-the-server-every-end","description":"Writing or editing any endpoint, form handler, or API route.","category":"ai-brimind","path":"ai-brimind/validate-input-and-check-permissions-on-the-server-every-end/SKILL.md","file":"SKILL.md","content":"---\nname: validate-input-and-check-permissions-on-the-server-every-end\ndescription: \"Writing or editing any endpoint, form handler, or API route.\"\n---\n\n# Validate Input and Check Permissions on the Server, Every Endpoint\n\n## When to use\nYou are creating or modifying server code that receives outside data or performs an action, and validation or permission checks are missing or frontend-only.\n\n## Example request\nFrontend blocks empty email, server accepts anything → attackers skip the frontend and call the API directly; the server check is the real one. User ID taken from the request body to fetch 'my orders' → anyone can send another user's ID; identity must come from the verified session, never from client input. Query built by gluing user text into SQL → classic injection; parameterized queries or the ORM's query builder already solve this. Uploaded file saved with its original name and type → someone uploads a script; check type, size, and rename on the server.\n\n## Instructions\nYou are a server-side guard who treats every incoming request as potentially hostile, no matter what the frontend promises. For every endpoint you write or touch: 1) Validate on the server: check type, length, format, and allowed values for every field — use an existing validation library or the framework's built-in validators rather than hand-rolled regex soup. Reject bad input with a clear error; never 'clean it up and hope'. 2) Authenticate: confirm who is calling using the session/token mechanism the project already has. 3) Authorize: confirm this specific user may do this specific action on this specific resource — ownership and role come from the server's own records, NEVER from IDs or flags the client sends. 4) Touch the database only through parameterized queries or the ORM — never concatenate user text into a query. 5) Escape or sanitize anything you render back into HTML so user text can't run as code. Before finishing, attack your own endpoint on paper: 'what happens if I send someone else's ID, a 10MB string, a negative number, or HTML in this field?' If any answer is 'it would work', the endpoint is not done. Explain each guard by naming the attack it blocks (injection, broken access control, XSS), not just 'for safety'.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #433\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}