{"canonical_url":"https://engineer.company/glossary/validation/","content_markdown":"# Validation\n\n## What it is\n\nValidation is the step in which a program compares incoming data with the rules\nthat data is meant to follow and refuses it when it falls short, before anything\nis stored, executed or sent on. It goes by several names depending on the layer:\ninput validation for form fields and API requests, schema validation when the\nrules are written down as a JSON Schema or an OpenAPI description, and markup\nvalidation when a web page is checked against the grammar of HTML. A piece of\ninput that passes is called valid.\n\nOWASP's guidance splits the work into two questions. Syntax asks whether a value\nhas the expected type and format: is this a date, is this an integer, does this\nbody parse as JSON. Semantics asks \"whether the value makes sense for the\noperation\", so a hotel booking needs two valid dates and also an end date after\nits start date. Converting the string \"500\" into an integer settles the first\nquestion and says nothing about whether 500 nights is an acceptable stay.\n\nMarkup validation is the oldest public form of the idea on the web. The W3C\nMarkup Validation Service describes validation as checking a document against\nthe grammar it claims to use, and compares its validator to lint for C. Its\ndocumentation is careful about what that proves: a valid page is not necessarily\na good one, only one that a tool found compliant with a specific set of rules.\nThe same caution applies to every other kind. Validation tells you the data fits\nthe rules you wrote; it does not tell you the rules were the right ones.\n\nTwo neighbouring ideas are often confused with it. Sanitisation changes input to\nmake it acceptable, by stripping or rewriting parts of it, where validation\naccepts or rejects it as it stands. Encoding and parameterisation make data safe\nfor the place it is going, an HTML page or an SQL query, and they are still\nneeded after validation has passed.\n\n## Why it matters\n\nThe decision behind validation is where a system draws its trust boundary and\nwhat it checks there. Every request from a browser, every message from a queue,\nevery file from a partner and every configuration change from a colleague\narrives with assumptions attached. Checking those assumptions at the edge means\nthe rest of the code can rely on them; skipping the check means every function\ndownstream has to defend itself, and in practice most of them will not.\n\nThe second decision is how the rules are written. Checks written out by hand,\nendpoint by endpoint, start out cheap and drift apart as the system grows,\nbecause each one is its own small piece of code. Rules declared once, as types\nor as a schema, can be enforced by a library and published as documentation from\nthe same source, reducing the risk that the description and the behaviour drift apart. The price\nis a framework to learn and defaults to understand, because a schema enforces\nexactly what it says and nothing it leaves unsaid.\n\nStrictness is the last choice. An allowlist describes what is acceptable and\nrejects everything else, which OWASP recommends over trying to recognise every\nmalicious string. Rejecting fields a schema does not know about catches typos\nand stale clients early. Rejecting the whole request on the first problem, with\na clear error, is safer than carrying on with data that was only partly checked.\n\n## What it looks like in practice\n\nOne API began with request validation written by hand for each endpoint. At the\ndocumented implementation stage,\n[moving it to Huma v2 turned the checks into types across 649 paths and 760 operations](/portfolio/migrated-the-api-to-huma-v2-at-100-parity/).\nEach endpoint had input and output structs, Huma generated the request\nvalidation from them, and an OpenAPI description came from the same types.\nTwo WebSocket endpoints stayed on raw Fiber, where the request and response\nmodel did not fit. A CI check compared the routes the server registered with\nthe ones the description advertised. Recorded route parity was 100%; checks declared in the input types replaced the\ncorresponding hand-written validation.\n\nConfiguration needs the same treatment, and\n[SSH hardening on the company's host now runs three stages of validation on every converge](/portfolio/hardened-ssh-to-24-validated-directives/).\nThe candidate file is syntax-checked before it is installed, the assembled\nconfiguration is checked after installation, and then the daemon's own resolved\nsettings are read back and 24 directives asserted against them. The third stage\nexists because an access report in September 2026 found two settings that the\nautomation had been writing on every converge and the daemon had been\noverriding, because the operating system's own defaults were read first and, for\nthose two, the first occurrence wins. As the page puts it, grepping for a\ndirective only proves it was written.\n\nMarkup validation was part of the documented August 2026 implementation stage:\n[HTML validation was one of the checks in a 22-linter commit gate](/portfolio/built-a-22-linter-commit-gate/)\nwith no warning tier, where every diagnostic was an error and inline\nsuppressions were prohibited, so an invalid page could not be committed by\nmarking the error as acceptable.\n\n## Where it goes wrong\n\n**The server trusts what the browser already checked.** A form that refuses a\nbad email address in the browser looks validated, but the request can be sent\nwithout the form at all. OWASP lists client-only checks as a common pitfall:\nvalidate on the server, and treat the browser check as a quick hint for the\nperson typing.\n\n**A schema accepts everything it does not mention.** In JSON Schema, listing a\nproperty neither makes it required nor forbids other fields, and under the\ndefault 2020-12 vocabulary the `format` keyword is collected as an annotation,\nwith format checking off by default. This schema looks strict:\n\n```json\n{\n    \"type\": \"object\",\n    \"properties\": {\n        \"email\": { \"type\": \"string\", \"format\": \"email\" }\n    }\n}\n```\n\nIt accepts `{}`, `{\"email\": \"nope\"}` and `{\"emial\": \"a@example.com\"}`. Add\n`required` and `\"additionalProperties\": false`, and turn on format assertion in\nthe validator, or check the format in code. Huma, for its part, rejects unknown\nbody fields by default, documents `readOnly` and `writeOnly` without enforcing\nthem, and ignores unknown query parameters unless told otherwise.\n\n**The check passes on one version of the data and the program uses another.** A\nvalidator that reads the raw request while the handler reads a decoded copy, or\na test that inspects the file on disk while the daemon applies a different\nsetting, has checked something the system never uses. OWASP's advice reads:\n\"Validate the representation that will actually be used\". The SSH work above is\nthe same lesson in configuration: only the daemon's read-back showed what was in\nforce.\n\n**A denylist meets the next variant.** Blocking known bad characters rejects\nlegitimate input, an apostrophe in a surname for instance, and still leaves the\nquery unsafe. Define what each field accepts, and reject the rest.\n\n**Valid input is treated as safe input.** A string that passed every rule can\nstill break an SQL statement or a page when it is pasted into one. Validation\nnarrows what arrives; parameterised queries and output encoding protect the\nplace where it ends up, and both are needed.\n\n## Further reading\n\n- [OWASP Input Validation Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/Input_Validation_Cheat_Sheet.html)\n  — syntax and semantics, allowlists, parsing limits and common pitfalls.\n- [W3C Markup Validator documentation](https://validator.w3.org/docs/) — the\n  validator's own account of markup validation, with its help pages on what\n  validity does and does not prove.\n- [JSON Schema Validation, draft 2020-12](https://json-schema.org/draft/2020-12/json-schema-validation)\n  — the validation keywords, including how `format` behaves by default.\n- [Huma: Request Validation](https://huma.rocks/features/request-validation/) —\n  validation generated from Go struct tags, with the strict and loose field\n  settings.\n- [OpenAPI Specification](https://spec.openapis.org/oas/latest.html) — the\n  description format whose schemas many API validators enforce.\n\n\u003chttps://engineer.company/glossary/validation/\u003e\n","date_modified":"2026-11-12T05:34:23Z","description":"What validation is, where a system should check its input and against which rules, and the schema defaults and client-side checks that let bad data in.","formats":{"gemtext":"https://engineer.company/glossary/validation/index.gmi","gopher":"https://engineer.company/glossary/validation/gophermap","html":"https://engineer.company/glossary/validation/","json":"https://engineer.company/glossary/validation/index.json","markdown":"https://engineer.company/glossary/validation/index.md","pdf":"https://engineer.company/glossary/validation/index.pdf"},"kind":"page","language":"en","title":"What is validation?","url":"https://engineer.company/glossary/validation/","version":1}