Work effectively with AI coding agents. Understand them as language models running in a tool loop with limited context, which is why they guess, game the visible signal and report confidently. Recognise the shortcut and correctness tells in their code across Python, TypeScript/JavaScript, Rust, Java and Go, and know the damage each one does later. Verify changes instead of trusting them, review diffs fast for quality and security, judge when work is truly finished, and choose, design and steer tasks so agents can finish them well.
Trust boundaries and untrusted input card 5 of 6

Fixing it at the boundary

BETTER: validate on entry. `re.fullmatch` accepts only word characters or `-` followed by `.pdf`, so anything else gets a 400. As a second layer, resolve the full path and confirm it still lies inside the folder with `is_relative_to` (Python 3.9+). Flask's `send_from_directory` also joins paths safely. Ask the agent to test hostile names such as `../x` and `/etc/passwd`, not just `q1.pdf`.
// Python
@app.get("/report")
def report():
    name = request.args.get("name", "")
    if not re.fullmatch(r"[\w-]+\.pdf", name):
        abort(400)
    base = Path(REPORT_DIR).resolve()
    path = (base / name).resolve()
    if not path.is_relative_to(base):
        abort(400)
    return path.read_bytes()
Terms on this card
re.fullmatch
Python function that succeeds only if a regular expression matches the whole string, not just part of it.
is_relative_to
Python 3.9+ Path method that is true if a path lies inside another path. Used after resolve() to confirm a file stays in its folder.
Flask
A widely used Python web framework for building HTTP endpoints.
send_from_directory
Flask helper that serves a file from a given folder and refuses names that escape that folder.
400
HTTP status code 'Bad Request': the server rejects the request because its input is invalid.
Learn this step by step on Bytewise
Lesson goal: Identify where data crosses from an untrusted source (users, network, files, third parties) into your code. Explain that injection bugs come from treating that data as code or commands, and that the defence is to validate and encode at the boundary. · the whole lesson