Find and fix weaknesses

Validate at the boundary

Treat external data as untrusted, parse it into a known shape, and enforce authorization and invariants before use.

8 minute lesson

~~~

Every request, file, webhook, database record, and third-party response can be malformed or hostile. Validate before the data gains authority.

Check type, length, range, format, and allowed values. Reject unknown fields when they create risk. Validation does not replace safe database queries, output encoding, or authorization; each solves a different problem.

A create-note endpoint accepts a valid string title with five million characters. The JSON parses, but the request consumes memory and fills logs before the database rejects it.

A strict schema may reject a new client field during a rollout. Version the contract deliberately instead of accepting every unknown value forever.

Send valid, missing, wrong-type, oversized, and extra-field requests to one boundary. Save the response and database state for each case, including proof that rejected input caused no write.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →