
Mission 4 of 10
Close the four classic input bugs for good.
Every one of these bugs is a user's value being treated as code. You'll see each attack once against a lab app on your own machine, then apply the one change that closes it.
What you'll do
See SQL injection, XSS, SSRF and path traversal work against a deliberately broken app that only runs on your machine.
Parameterise, encode, allowlist and contain, then confirm each attack no longer works.
Use Row Level Security and least-privilege roles so a bug you miss still can't read another user's rows.
- One validation layer that rejects malformed input
- Safe file-upload rules
- Python 3.11+ and uv, and curl
- Having done the attacks overview helps but isn't required
- A browser, to see the XSS fire and then not fire
- Optional: a Postgres database (local or Supabase) for the RLS section. The code reads fine without one
Your progress0/6
- 01Stand up the lab, and the one idea behind every bug here8 min
- 02SQL injection: one f-string away, one parameter away from gone14 min
- 03Stored XSS: encode on output, and know when to sanitise instead14 min
- 04SSRF and path traversal: when input becomes a URL or a file path14 min
- 05Validate everything at the edge, and the file-upload rules12 min
- 06The database as the last line: RLS and least-privilege roles10 min
Stand up the lab, and the one idea behind every bug here
You'll run deliberately broken endpoints on your own machine. First, the sentence that explains all four.
The one idea
Every bug in this mission comes down to one idea, so it's worth having it clear before you touch any code.
A program has a boundary between code and data, and every bug in this mission is a value crossing from the data side to the code side.
A string becomes part of a SQL statement. A comment becomes part of the HTML. A link becomes a request your server makes. A filename becomes a path your server opens.
The fix is always the same shape: keep the value on the data side. Parameterise, encode, allowlist, contain.
Set up the lab
Now the lab itself. It's a local FastAPI app with a handful of endpoints, a throwaway SQLite database, and a files folder.
Nothing listens beyond your machine and nothing here touches the internet except one SSRF demo you point at your own ports.
Create the project folder, set it up with uv and add the packages the lab needs:
Terminalmkdir input-lab; cd input-lab uv init --bare uv add "fastapi[standard]" httpx pydanticYou'll build the vulnerable and the fixed version side by side as you go, one bug at a time, rather than pasting one big file.
Each step is: see the bug, understand why, apply the fix, confirm it's closed.
Start the lab app directory now and keep two terminals open, one for the server and one for curl.
WarningThis lab is for your machine only. The techniques here work against any site, and using them on a site you don't own is an offence under the Computer Misuse Act 1990. The whole point of a local lab is that the only system you attack is yours.
uv run python -c "import fastapi, httpx, pydantic; print('ok')" prints ok, and you have an empty input-lab folder ready. That means the packages are installed.