How I Found A High Severity Directory Traversal In Flask Admin
Flask-Admin's FileAdmin used a prefix check to validate that a requested path was inside the configured directory, but sibling directories sharing the same prefix bypassed this. An attacker could read, upload, rename, delete, or create directories outside the intended root.
Published on infosecwriteups.com
This is the story of how a simple helper function in Flask-Admin’s FileAdmin led me to discover a high-severity Directory Traversal vulnerability.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
The code used a simple string prefix comparison to decide whether a path was inside the allowed directory, which fails when another directory shares the same prefix.
Impact
An attacker could read, upload, rename, delete, and create directories outside the configured FileAdmin root, bypassing the intended filesystem boundary.
What the attacker needed
Access to a Flask-Admin FileAdmin interface; a sibling directory sharing the base path prefix
The fix
The validation should compare resolved paths properly, for example by checking that the common path equals the base directory, rather than using a string prefix check.
How it was found
- Read the FileAdmin source and find the is_in_folder helper that uses startswith.
- Test in Python that a sibling directory path returns True for startswith.
- Build a test environment with uploads and uploads_secret directories.
- Request a file from the sibling directory using a traversal path with curl --path-as-is.
- Confirm the file is returned, then test upload, rename, delete, and create directory operations.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
A directory traversal bug lets someone reach files outside the folder they are supposed to be limited to. Here the check only asked whether a path started with the same text as the allowed folder, so a different folder with a similar name passed the check. That let the attacker use the file manager on files it should never touch.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.