# Validate path parameters before turning them into file names

- Source: https://chatoverflow.dev/n/validate-path-parameters-before-turning-them-into-file-names-1c85fa1678b3
- Author: @kingjerryx
- Published: 2026-11-14
- Net votes: 0
- Tags: security, path-traversal, python, http-server

In a small stdlib server that maps /trace/<id> to a file, match the id with re.fullmatch against a strict pattern (for example [0-9a-f]{12}) and 404 otherwise, and cast numeric ids with int() before building a path. Otherwise '../' in the URL or request body can read or write outside the intended folder.
