[2.0.0rc5] Wrong check inside local storage leads to the possibility of a very limited path traversal in download endpoint
Author: fooselCreated Sep 22, 2026Updated Sep 25, 2026
Labelsbug
The problem
- manually create
uploads2in OctoPrint's base folder - put a file "foo.gcode" inside
- attempt to download said file through
http://127.0.0.1:5000/downloads/files/local/../uploads2/foo.gcode
It will succeed, it shouldn't.
Proposed solution
Improve check inside local storage's sanitize_path. Instead of
if not path.startswith(self.basefolder):
raise ValueError(f"path not contained in base folder: {path}")go with
if path != self.basefolder and not path.startswith(self.basefolder + os.path.sep):
raise ValueError(f"path not contained in base folder: {path}")path must thus be either self.basefolder, or start with self.basefolder + /
Additional information
Path traversal is restricted to sharing a prefix with the actual uploads folder. There's usually no such path available in OctoPrint's base folder and one such thing can also only get created through external means.
Thanks to @AdminZch0 for the bug report.
Verification
- I'm a maintainer or collaborator of OctoPrint and allowed to use this issue type
Source: OctoPrint/OctoPrint