I Found a Path Traversal in InvenTree’s Report Engine — Here�
Three Django template tags in InvenTree's report engine joined a user-supplied filename onto the media directory and resolved it without checking that the result stayed inside that directory. A staff user could plant a template that reads any file the application process can access, and any authenticated user could then trigger a PDF report that embeds the file's contents.
Published on medium.com
InvenTree is a popular open-source inventory management system built on Django. It’s self-hosted, widely deployed in maker spaces, small businesses, and engineering teams — and it ships a powerful report template engine that lets staff users design PDF reports using Django template syntax.
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 joined user input onto a base directory and called Path.resolve() but never verified that the resolved path remained a descendant of that base directory.
Impact
An attacker could read arbitrary files the application process can access, including the Django secret key, which could allow forging session cookies and password reset tokens for any account; the vendor scored it lower because template creation requires a staff account.
What the attacker needed
A staff account to create the template; any authenticated account to trigger the print; self-hosted InvenTree instance
The fix
The patch adds a check after resolving the path that raises an error if the resolved path is not relative to the media root, applied to all three affected functions.
How it was found
- A staff user uploads a report template that uses one of the affected tags with a path that traverses outside the media directory.
- Any authenticated user sends a print request referencing that template's primary key.
- The generated PDF is downloaded from the media output location.
- The base64-encoded file contents are extracted from the PDF.
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 template tag is a small helper that runs when a web page or PDF is generated. These helpers took a filename from the template and opened it, but they did not confirm the file was inside the folder they were meant to use. By putting '../' in the filename, someone could make the helper walk up out of that folder and read other files on the server.
What is Path traversal?
Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.