Vulnerability GHSA-x9x8-xcv7-5x5g

Medium Risk
MEDIUM RISK
CVSS Score: 5.5
Score Range: 4.0–6.9
Medium severity vulnerabilities (CVSS 4.0–6.9). Important issues that meaningfully reduce security confidence.
10 hours ago
December 03, 2026 at 02:36 AM UTC
termux-sync: Restore extracts archive members outside the backed-up directory because the extraction jail is the parent of each backup root
1.1.0 - 1.2.4 and 1.2.6 and 1.2.8 - 1.3.0 and 1.3.5 - 1.3.7
1.1.0 - 1.2.4 and 1.2.6 and 1.2.8 - 1.3.0 and 1.3.5 - 1.3.7

Summary

termux-sync: Restore extracts archive members outside the backed-up directory because the extraction jail is the parent of each backup root

Details

Summary

termux-sync restore extracts each archive into the parent of the directory that archive is supposed to hold. The containment check then compares members against that wider directory, so an archive declared as usr_etc or usr_lib can write anywhere under $PREFIX, including $PREFIX/bin.

This is a residual gap in the fix for GHSA-259w-wmqg-fp76 / CVE-2026-86046. The guards that advisory added all work. What survives is the choice of destination they are checked against.

Affected versions

Tested on:

  • Package version: termux-sync 1.3.6 installed from PyPI (termux_sync-1.3.6-py3-none-any.whl)
  • Repository commit: 054e6d88acf16c7d9b025846bcc2652b2975c68a on main
  • Python: 3.12.16, where tarfile.data_filter is available
  • Dependencies: rich==15.0.0, markdown-it-py==4.3.0, mdurl==0.1.2, Pygments==2.21.0
  • OS: Debian in a container, non-root, no network during the restore

Only 1.3.6 was tested. The primitive looks present in earlier releases, but unchecked. Releases before 9c8637b are already covered by CVE-2026-86046.

Main and the release differ only inside cmd_daemon. Lines 1 to 700, which hold all the archive and extraction code, are identical, so main has the same behaviour. termux-sync.py is a byte-identical copy of src/termux_sync/__init__.py, so the line numbers below apply to both.

Impact

An attacker who controls the content of a backup that a victim restores can write files anywhere under $PREFIX, overwriting existing ones. Replacing an executable such as $PREFIX/bin/sh gives code execution as the Termux user the next time anything invokes it, and it leaves dpkg's record of $PREFIX disagreeing with what is on disk.

Attacker requirements:

  • Write access to the backup the victim restores. Nothing on the victim's device. This is the same position GHSA-259w-wmqg-fp76 described: "a victim who restores a malicious backup (local, shared, or from a compromised GitHub/Google Drive storage backend)". A backup shared between people moving to a new device is the use the README describes, and SECURITY.md:41 already contemplates a GitHub storage repo being public.
  • The victim runs termux-sync restore and answers y at the prompt (__init__.py:1599).
  • No authentication, no root, and no non-default configuration. $PREFIX is writable by the Termux user by design, which is how pkg install works, so no privilege escalation is involved.

The restore preview (__init__.py:1587-1596) shows the backup name, date, package count and archive count. It does not list member paths, so a victim who inspects it cannot see bin/sh in a config archive.

Root cause

cmd_restore builds the destination for each manifest key by taking the parent of the backup root (src/termux_sync/__init__.py:1611-1614):

        allowed_roots = {}
        for item_key, _label, item_root in BACKUP_ITEMS:
            if item_root is not None:
                allowed_roots[item_key] = Path(item_root).resolve().parent

With BACKUP_ITEMS at :69-74 and TERMUX_HOME = $PREFIX, TERMUX_FILES = $HOME (:66-67):

manifest key backup root resulting jail what that jail holds
home $HOME …/files all of $PREFIX
usr_etc $PREFIX/etc $PREFIX bin/, lib/, libexec/, etc/
usr_lib $PREFIX/lib $PREFIX same

The extraction then passes that jail to extract_archive at :1631, and _safe_extract_member (:555-582) checks members against it:

    target = (dest_path / member_name).resolve()
    try:
        target.relative_to(dest_root)

That check is written correctly. Both sides are resolved, .. and absolute members are rejected, link targets are checked, device and FIFO entries are refused, and extract runs with filter="data" at :601 and :609. A member named bin/sh in a usr_etc archive simply is inside $PREFIX, so it passes and gets written.

The comment three lines above :1614 describes the invariant the code is meant to hold:

        # Build the set of destinations this app is actually willing to restore into.
        # Manifest-supplied "source" values are attacker-controlled backup content
        # and must never be trusted as an extraction root — only used to double
        # check they agree with the known-safe root for that item key.

The known-safe root for usr_etc is $PREFIX/etc. The code uses $PREFIX.

A backup the project's own code produces can never contain such a member. create_archive always adds one tree under arcname=source_path.name (:545, :547), so a real usr_etc archive holds only etc/.... Nothing checks that a member's first component matches the arcname the writer would have used.

$PREFIX/bin is not part of the documented restore surface. FAQ.md:80 lists the four components as the package list, the home directory, $PREFIX/etc and $PREFIX/lib, and README.md:49 and :272-276 say the same.

Reproduction

The PoC is local and non-destructive. It builds a fake Termux layout under a temp directory, points HOME, PREFIX and TMPDIR at it, and writes nothing outside it. Both roots come from those environment variables at :66-67, which is how the code behaves on a device.

The malicious backup has two archives. usr_etc.tar.gz, whose declared surface is $PREFIX/etc, contains etc/motd (legitimate), bin/MARKER_from_usr_etc, bin/sh at mode 0755 containing echo ATTACKER_CODE_RUNS, and two controls, ../escape_dotdot.txt and /abs_escape.txt. home.tar.gz, declared surface $HOME, contains home/.bashrc (legitimate) and usr/bin/MARKER_from_home. Manifest checksums are correct so no checksum prompt fires, and the package list is empty so no pkg call happens.

Install:

python -m venv /tmp/venv && /tmp/venv/bin/pip install termux-sync==1.3.6

Run the restore through the real entry point:

python -I poc.py /path/to/termux-sync-wrapper

Actual result:

1.3.6 /work/venv/lib/python3.12/site-packages/termux_sync/__init__.py

  Step 2/4  Verifying checksums…
  ✓ usr_etc.tar.gz  832a54b0130e…
  ✓ home.tar.gz  c2942b552bc8…
  ⚠ This will overwrite existing files.
  Proceed with restore? [y/n]:
  Step 3/4  Extracting archives…
  usr_etc.tar.gz ✓
  home.tar.gz ✓
  ✓ Restore completed successfully!

=== RESULT ===
  ESCAPE  $PREFIX/bin/MARKER_from_usr_etc      exists=True
  ESCAPE  $PREFIX/bin/MARKER_from_home         exists=True
  expected $PREFIX/etc/motd                    exists=True
  expected $HOME/.bashrc                       exists=True
  control files/escape_dotdot.txt              exists=False
  control run/escape_dotdot.txt                exists=False
  control /abs_escape.txt                      exists=False

$PREFIX/bin/sh contents after restore:
  #!/bin/sh
  echo ATTACKER_CODE_RUNS

log tail:
  [WARNING] Skipped unsafe archive member during restore: Path traversal attempt in archive: '../escape_dotdot.txt'
  [WARNING] Skipped unsafe archive member during restore: Unsafe absolute path in archive: '/abs_escape.txt'
  [INFO] Extracted usr_etc.tar.gz → /work/poc/run/files/usr
  [INFO] Extracted home.tar.gz → /work/poc/run/files
  [INFO] Restore completed from: termux_backup_evil

The two control members were rejected and logged, which is the project's existing guards working. The two escapes are members that never leave the wider jail, so nothing rejects them. The log lines also show the separate destinations, …/files/usr for the config archive and …/files for the home archive, so each escape is independently attributable.

The mode survives filter="data" and the replaced file runs:

-rw-r--r-- 1 1000 1000  7 MARKER_from_home
-rw-r--r-- 1 1000 1000  7 MARKER_from_usr_etc
-rwxr-xr-x 1 1000 1000 34 sh

Impacted packages

Timeline

Published
10 hours ago
December 03, 2026 at 02:36 AM UTC
Fixed (1.3.8)
14 days ago
November 19, 2026 at 02:12 AM UTC
Last Modified
10 hours ago
December 03, 2026 at 02:45 AM UTC