Summary
termux-sync restore can extract files from a malicious or tampered backup outside the intended destination because archive members are not confined to a safe directory. If a user restores such a backup, files may be written anywhere the Termux user can write, potentially enabling code execution when an affected file is later used.
Affected context
The issue occurs during backup restoration when untrusted manifest values influence extraction destinations and archive members are extracted without enforcing a destination boundary. Risk depends on a user restoring a malicious or tampered backup, which may be stored locally or obtained through shared, GitHub, or Google Drive storage. Unsafe backup names can also affect temporary paths.
Exploit preconditions
- Attack surface: The termux-sync restore workflow.
- Required access: An attacker must be able to provide or tamper with a backup that the victim can access; the victim must initiate its restoration.
- Trigger point: Restore processing of manifest values and archive members.
- Why exploitation is possible: The restore process does not reliably constrain extraction paths to the intended destination, allowing crafted paths to resolve elsewhere within the Termux user's writable filesystem.
Why this happens
This is a path traversal weakness mapped to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal'). The underlying insecure pattern is using untrusted path values to determine extraction or temporary locations without validating and enforcing that resolved paths remain within an approved directory. Extracting archive members without a destination boundary can let member paths escape that directory.
Potential impact
- An attacker may cause files to be written to locations the Termux user can modify.
- Shell startup files or executable scripts could be replaced or altered.
- Malicious changes could lead to code execution when affected files are later loaded or run.
- User data or the Termux environment could be damaged or manipulated.
General mitigation guidance
Defensive patterns focus on treating backup contents and metadata as untrusted and confining all filesystem operations.
- Use archive extraction methods that prevent paths from escaping a designated destination.
- Resolve and validate each output path, rejecting paths outside the approved extraction root.
- Validate backup names and manifest paths before using them in temporary or destination paths.
- Prefer restrictive allowlists for expected archive entries and file types.
- Limit the permissions of the restore process and avoid restoring backups from untrusted sources without review.
How teams detect issues like this
- Use static analysis to identify archive extraction calls and filesystem operations that consume untrusted paths.
- Review whether resolved extraction paths are checked against a canonical destination boundary.
- Check that manifest fields and backup names are validated before being used in filesystem paths.
- Add tests and CI policy checks for path traversal attempts in archive entries and metadata.
- Monitor restore operations for unexpected writes outside the intended backup destination.

