- Finding
- Path traversal
- Component
- Internal file service
- Input
- Advisory and source
- Verification
- Your lab
01/Analysis
Model
read_reportjoins a user-supplied name to the reports directory without resolving it. A name containing../reads files outside that directory. Any route that passes a request parameter toread_reportis affected.02/Proposed patch
Model
def read_report(name: str) -> bytes: path = os.path.join(REPORT_DIR, name) base = os.path.realpath(REPORT_DIR) path = os.path.realpath( os.path.join(base, name)) if os.path.commonpath([path, base]) != base: raise PermissionError("Outside reports") with open(path, "rb") as f: return f.read()
Review note: check the other callers that build paths from request input.
03/Cases to run
Your lab
Requested name Expected ../settings.yaml Rejected A link in reports/ that points outside it Rejected 2026-q3/summary.pdf Returned