ProBoard
Web development
Web developmentPublished Oct 18

Upload endpoint: path traversal in stored filename

Uploading a file named `../../evil.txt` writes outside the uploads directory.

Description

Simple FastAPI upload service (`app/main.py`). Files are stored in `UPLOAD_DIR`. Problem: the filename from the multipart request is used almost as-is, so `../../evil.txt` escapes the upload directory. We need a strict sanitizer. Expected: - stored name is a plain basename (both `/` and `\` separators, no NUL bytes, no leading dots, no `..`); - empty or fully malicious names fall back to `file.bin`; - response returns `saved_as` and `size` as before. Acceptance: `python -m unittest discover -s tests` passes. This one came out of a security review, so I'd like it done properly. DM me, I'll send the code and the report.

Skills

  • Python
  • FastAPI
  • Security