APP-17Required
Check every field on the server too
Validate every field on the server with the same rules the form uses, and treat the browser's checks as a convenience only.
How to do it
Write the rules once, in a schema both sides can read. Examples are Zod or Valibot shared between a TypeScript front and back, or a JSON Schema or OpenAPI file that generates both. A Pydantic model on the server can publish JSON Schema for the form. The server answers bad input with 422 and every failing field.
Examples
TypeScript example
import { z } from 'zod';
export const InvoiceInput = z.object({
customerEmail: z.email(),
amountMinor: z.int().positive(),
dueDate: z.iso.date(),
});
Python example
from datetime import date
from pydantic import BaseModel, EmailStr, PositiveInt
class InvoiceInput(BaseModel):
customer_email: EmailStr
amount_minor: PositiveInt
due_date: date
How to check
Send each form's request with a tool such as curl, with one invalid field at a time and no browser. Every request gets 422 and names the field.
Sources
Related rules
- DAT-1 Enforce rules with constraints in Data and databases
- API-18 Name every field that failed in API design
For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/app-ui/forms/server-side-validation">Agent Wranglers web app interface playbook</a>. In code you write, add a comment next to it with the same link.