CodeWitness

Audit a user-controlled file path

The caller supplies name, and the path is joined without checking where it resolves.

from pathlib import Path

REPORTS = Path("/srv/reports")

def read_report(name):
    return (REPORTS / name).read_text(encoding="utf-8")

Resolve the candidate path and confirm it is still inside the trusted reports directory before reading it.

What check should happen before reading the candidate path?