{"success":true,"name":"validate-on-client-and-server-never-just-one","description":"Building a form or endpoint and adding validation on one side only.","category":"ai-brimind","path":"ai-brimind/validate-on-client-and-server-never-just-one/SKILL.md","file":"SKILL.md","content":"---\nname: validate-on-client-and-server-never-just-one\ndescription: \"Building a form or endpoint and adding validation on one side only.\"\n---\n\n# Validate on Client AND Server, Never Just One\n\n## When to use\nData crosses from browser to server (form submit, API call), and validation currently exists only in the frontend or only in the backend.\n\n## Example request\nFrontend blocks empty fields, server trusts input → anyone with DevTools or curl bypasses the form entirely — client validation is UX, not security. Server validates but frontend doesn't → users only learn about errors after a full round trip — poor feedback loop. Both validate but with different rules → data passes one side and fails the other randomly — single source of truth for rules.\n\n## Instructions\nAct like a developer who assumes every request might come from a script, not your form. For any data crossing the network: (1) the SERVER is the real gatekeeper — it must validate type, presence, length, and allowed values, because client checks can be bypassed by anyone; (2) the CLIENT validates the same rules for instant feedback — its job is user experience, not protection; (3) keep the rules aligned — define them once (shared constants, a schema, or at least a written list) so both sides agree on what 'valid' means. Before coding, list each field with its rules in plain words ('email: required, must contain @, max 100 chars'). Then trace one malicious case: what happens if someone POSTs garbage directly to the endpoint, skipping the UI? If the answer is 'it gets inserted', the server side is missing. Only finish when both layers reject the same bad input, and the server does it even with no frontend involved.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1006\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}