Input you do not control

A value from the query string is text until you make it something else, and it can be any text at all. This set checks that you know why a blocklist loses to an allowlist, and that you can write the check that keeps a value inside the shape you meant.

4 questions 1 task Read the lesson

Questions

Each one is marked as you go, and the explanation arrives straight after, which is the part worth reading.

4 questions, marked as you go.

1 Why does a value from the query string need checking before it is used?
2 Why does an allowlist beat a blocklist for validating input?
3 What does re.fullmatch(r"[0-9]{1,3}", n) reject that a length check alone would allow?
4 Why does the fixed server answer a bad value with 400 rather than 500?

Tasks

These need your own device. Run the command in Termux, then paste what it printed. The marking looks at what the output means, so spacing, version numbers and ordering do not matter. If you have not installed anything yet, the lesson covers the setup.

Let an allowlist refuse the hostile filenames

This feeds five filenames through a single allowlist: the first character must be a letter or a digit, and the rest may be letters, digits, dots, dashes or underscores. Run it and paste the filenames that survive.

Run this in Termux On your own device. Nothing on this page executes it. The command runs in your terminal, and this box only reads what you paste back.

printf '%s\n' 'report.pdf' '../secret' 'a%2e%2e' 'notes.txt' '..' | grep -E '^[A-Za-z0-9][A-Za-z0-9_.-]*$'
Marking your own work Both halves of this are checked in your browser, with no server involved, so nothing stops you from pasting output you did not run. The tasks are written so that the easiest way to pass one is to actually do it and read the result, which is the whole intention.

All sets Read the lesson