{"success":true,"name":"validate-every-request-at-the-backend-door-before-it-touches","description":"Writing a backend endpoint that receives data from the frontend or outside","category":"ai-brimind","path":"ai-brimind/validate-every-request-at-the-backend-door-before-it-touches/SKILL.md","file":"SKILL.md","content":"---\nname: validate-every-request-at-the-backend-door-before-it-touches\ndescription: \"Writing a backend endpoint that receives data from the frontend or outside\"\n---\n\n# Validate Every Request at the Backend Door Before It Touches Logic or the DB\n\n## When to use\nProject has a backend API, and you are about to use req.body, query params, or uploaded data in logic or database calls without checking types, required fields, and allowed values first.\n\n## Example request\nsaving req.body straight to the database → a missing field creates a broken record you find weeks later; validation at the boundary would have rejected it with a clear 400. trusting the frontend already checked the form → anyone can call the API directly with curl; the backend is the real gate, the frontend is just comfort. using an id from the URL in a query without checking format or ownership → one user reads another user's data; that is missing input validation plus an authorization check. accepting any value for 'status' → the DB fills with typos like 'actif' and 'Active'; an allowed-values list (enum/whitelist) keeps data clean.\n\n## Instructions\nAct like a strict doorman for the backend: nothing from outside enters the logic or database unchecked. For every endpoint you write or touch, first list exactly what it accepts: each field, its type, whether it is required, and its allowed values or format. Then check the request against that list at the very top of the handler — before any logic, before any DB call — and reject bad input with a clear 400 and a human-readable message naming the wrong field. Never assume the frontend validated it: the API can be called directly by anyone. Check whether the project already has a validation tool or pattern (a schema library, an existing validate middleware, model-level checks) and reuse it instead of hand-writing checks differently on each route. Also confirm ownership/permission when an id belongs to a user's data. If the expected shape of the input is unclear, ask or read the frontend call — do not guess. Only proceed once the endpoint's accepted shape is written down and enforced, and explain why this stops bad data at the door instead of letting it become corrupted records and mystery bugs deep inside the system.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #515\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}