untrusted input
Any data a program did not create itself, including arguments, form fields, request bodies, file contents, file names and environment variables.
Scripts that act on untrusted input without care can be steered into deleting or running the wrong thing.
In more detail
Treat it as data only and check it against what you expect, such as a known set of values, rather than trying to strip out dangerous characters. Never assume its size or shape: cap how much you read and treat parse failures as errors. Most injection and resource-exhaustion attacks exploit code that trusted such input.
Examples
Go: wrap readers in io.LimitReader and decode into typed structsThe rule of the course is that anything the caller controls is not evidence of the caller's rights and must stay data when it reaches an interpreter.Related terms
- command injection — An attack where input meant as data, such as a file name or form field, gets run as commands because a program built code from it.
- eval — A shell builtin that joins its arguments into one string and runs that string as a command, as if you had typed it.
- deny list — A list of known-bad values to reject, with everything else accepted.
- io.LimitReader — The Go function that wraps an io.Reader so it stops after a set number of bytes, capping how much you will read.
- io.ReadAll — The Go function that reads an io.Reader until the end and returns everything as one slice of bytes.
- json.Unmarshal — The Go function that decodes JSON bytes into a Go value you pass by pointer, such as &reply.
- validation schema — A description of what valid data looks like, checked by code while the program runs so bad data is rejected at the door.
- Server Action security — Treating every Server Action as a public HTTP endpoint that anyone can call with any arguments.
- cross-site scripting — An attack where hostile script is injected into a trusted web page and runs with that page’s access, for example to read data or cookies.
- injection — A bug where untrusted data reaches an interpreter and part of it is read as code instead of as a value.
- taint analysis — Tracking untrusted data from where it enters (a source) to where it would be dangerous (a sink), unless it passes a sanitiser first.
- runtime validation — Checking real data with JavaScript code while the program runs, so values from outside are proven correct before they are trusted.
- unknown (type) — The type-safe type for a value that could be anything, which you must narrow before you can use it.
- type assertion (TypeScript) — Writing value as Type to tell the compiler to treat a value as a type, without any check that it really is.
- webhook — An HTTP request a provider sends to an address you registered, to tell you an event happened, instead of you polling for it.
Taught in
- Script Input And Output: read, Heredocs, printf — Bash Scripting & Command Line Automation
- eval, And What To Use Instead — Bash Scripting & Command Line Automation
- Streams and the io Package — Concurrent Systems Programming with Go
- Optimistic UI: useOptimistic Rollbacks & Transitions — Next.js 15 & Modern App Router Architecture
- Server Action Security: Zod Validation & Auth Gates — Next.js 15 & Modern App Router Architecture
- Authentication Versus Authorisation — Application Security & Threat Modeling for Engineers
- Injection In All Its Forms — Application Security & Threat Modeling for Engineers
- Broken Object Level Authorization — Application Security & Threat Modeling for Engineers
- Static Application Security Testing — Application Security & Threat Modeling for Engineers
- Why TypeScript: Contracts, Erased Types And Soundness — Production TypeScript
- any Versus unknown: Defensive Typing In Practice — Production TypeScript
- Exhaustive Narrowing With never In Production Handlers — Production TypeScript