Summary
Runtipi's BackupManager component allows authenticated users to execute arbitrary system commands on the host by injecting shell metacharacters into backup filenames.
Because user-controlled filenames are written directly to the host filesystem and later interpolated into restore commands without sanitization, a crafted backup file name can be used to trigger command execution during the restore process.
Affected context
This vulnerability affects Runtipi deployments (versions 3.7.0 and above, prior to the fix) where:
- Users can upload backup archives through the web UI or API.
- The BackupManager stores uploaded files on the host filesystem using the original, user-supplied filename.
- Restore operations later reference these stored files using shell-invoked commands.
The risk is most pronounced in multi-user or exposed deployments where non-admin or less-trusted authenticated accounts can upload and restore backups.
Exploit preconditions
- Attack surface: Runtipi backup upload and restore functionality exposed via HTTP(S) (web UI or API).
- Required access: An authenticated account with permissions to upload backups and trigger restore operations (or influence an operator to restore).
- Trigger point: Invocation of the backup restore process that uses the stored filename in a shell context.
- Why exploitation is possible: The BackupManager:
- Persists user-controlled
originalnamedirectly as the filesystem path. - Subsequently constructs shell commands or shell-interpreted arguments incorporating this filename without proper quoting, validation, or sanitization.
- Allows shell metacharacters (e.g.,
$(), backticks, pipes, redirects) in filenames to be interpreted as part of the OS command during restore.
Why this happens
The underlying flaw is a classic OS Command Injection problem as described by CWE-78. The application treats user input (backup filenames) as data initially, but later reuses it in a context where a command interpreter is involved without enforcing a strict separation between data and executable code.
Concretely:
- The BackupManager accepts a filename from the client (
originalname) and writes files to the host filesystem using this value unmodified. - When performing a restore, the implementation likely constructs a shell command (e.g., to extract an archive) by concatenating or interpolating this filename into a command string.
- Because the application neither validates allowed filename patterns nor reliably quotes or bypasses the shell, special characters in the filename are interpreted by the shell as command syntax.
This pattern aligns with CWE-78: passing unsanitized, user-controlled input into a shell command leads to unintended execution of arbitrary commands.
Potential impact
- Execution of arbitrary OS commands on the host server with the privileges of the Runtipi process.
- Reading, modification, or deletion of data stored on the host or accessible mounted volumes.
- Installation of backdoors, cryptominers, or other persistent malware on the homeserver.
- Pivoting to other services or containers orchestrated by Runtipi, potentially compromising the broader environment.
- Disruption of services (e.g., stopping, corrupting, or overwriting application data during malicious "restore" operations).
General mitigation guidance
Effective mitigation centers on eliminating the ability for user input to influence shell interpretation and tightening trust around backup handling:
- Avoid shell where possible:
- Prefer direct invocation of archival or restore libraries/APIs (e.g., language-native tar/zip libraries) instead of constructing shell commands.
- If external binaries must be used, call them via parameterized process execution APIs that do not invoke a shell (e.g.,
execve/spawnwith argument arrays).
- Enforce strict filename controls:
- Normalize filenames to a safe, internal format (e.g., UUIDs or timestamp-based names) irrespective of the user-provided
originalname. - Restrict characters allowed in persisted filenames to a minimal safe set (e.g., alphanumerics, hyphens, underscores, and dots).
- Strip or reject any input containing shell metacharacters (
$,;,&,|,<,>, backticks,(,), newline, etc.).
- Confine backup paths:
- Ensure all backup files are stored within a dedicated, fixed directory, and avoid constructing paths using unvalidated user input.
- Use path normalization and checks to prevent directory traversal or references outside the intended storage root.
- Privilege and isolation:
- Run Runtipi and its backup processes under a non-privileged account with minimal host permissions.
- Use container- or OS-level sandboxing to limit the blast radius of a compromised backup restore process.
- Secure-by-default operational practices:
- Treat backup upload and restore as sensitive operations, ideally restricted to trusted administrators.
- Implement least-privilege RBAC around backup functionality, especially in multi-user environments.
How teams detect issues like this
Detection can focus both on code-level patterns and runtime behaviors:
- Static analysis and code review:
- Search for uses of shell execution APIs (e.g.,
exec,spawnwithshell=true,system, backtick operators) where arguments include user-controlled values such as filenames or request parameters. - Flag any logic that interpolates or concatenates HTTP request fields (including
originalname,filename, or path segments) into command strings. - Enforce secure coding guidelines that require:
- Use of non-shell process APIs with argument arrays.
- Input validation and canonicalization for all filesystem-related parameters.
- Automated scanning and policy checks:
- Configure SAST tools to detect CWE-78 patterns, particularly shell-invoking functions fed by HTTP input or request body metadata.
- Add CI policies that block merges if new shell command construction is introduced without explicit security review.
- Runtime and log monitoring:
- Monitor application logs and system audit trails for unusual backup filenames containing shell metacharacters.
- Alert on restore operations involving suspicious filenames or unexpected command-line arguments.
- Use host-based intrusion detection to detect anomalous commands executed under the Runtipi service account during backup or restore operations.

