Summary
A path traversal vulnerability in Melange's workspace retrieval allows crafted tar archives from a QEMU guest VM to write files outside the intended workspace directory on the host.
If an attacker can influence the tar stream, they can abuse ../ sequences in file paths to escape the workspace and overwrite or create arbitrary files on the host system.
Affected context
This vulnerability affects Melange environments that:
- Use versions 0.11.3 through 0.40.2.
- Build APK packages using pipelines that rely on QEMU guest VMs producing tar streams.
- Trust the contents and paths within those tar archives to be safe.
The issue specifically occurs when the retrieveWorkspace function extracts tar entries into a workspace directory without verifying that the resulting file paths remain confined within that directory.
Exploit preconditions
- Attack surface: Host system running Melange and processing tar streams from QEMU guest VMs.
- Required access: Ability to control or significantly influence the contents of the tar archive generated inside the guest VM (e.g., control over build scripts, filesystem layout, or pipeline inputs in the guest).
- Trigger point: Execution of the
retrieveWorkspacelogic that untars the guest-produced archive into the host workspace. - Why exploitation is possible: The extraction code does not normalize and validate tar entry paths;
../segments and absolute-like paths are honored, allowing files to be written outside the intended workspace boundary.
Why this happens
The root cause is a classic directory traversal flaw in archive extraction logic, mapped to CWE-22: Improper Limitation of a Pathname to a Restricted Directory.
The retrieveWorkspace function trusts file paths contained in the tar stream and directly joins them with the workspace root, without:
- Canonicalizing the resulting paths, and
- Verifying that the final resolved path is still within the designated workspace directory.
This insecure pattern allows tar entries with path components such as ../ to escape the workspace root and target arbitrary locations on the host filesystem.
Potential impact
- Overwriting of host files that the Melange process has permission to modify.
- Creation of new files in sensitive host directories (e.g., configuration directories, build outputs, or service-related paths).
- Potential introduction of malicious configuration or scripts that may later be executed by automated jobs or other system components.
- Manipulation of build artifacts, leading to supply-chain compromise of generated APK packages.
- Escalation of impact if overwritten files are used by privileged services or security-sensitive tooling.
General mitigation guidance
Effective mitigation focuses on enforcing strict path confinement when extracting archives and reducing trust in guest-produced data:
- Normalize and resolve each tar entry path (e.g., using canonical/realpath equivalents) before extraction.
- Verify that the resolved path remains inside the designated workspace directory, rejecting or sanitizing entries that attempt to escape via
../or absolute paths. - Prefer extraction APIs or helper utilities that natively support secure extraction with directory traversal protection.
- Run Melange builds, including extraction logic, with the least filesystem privileges necessary, limiting which host paths are writable even in the event of a flaw.
- Treat all artifacts from guest VMs as untrusted input and apply validation, filtering, or sandboxing before interacting with the host filesystem.
How teams detect issues like this
Detection generally involves reviewing archive-handling code and enforcing policies around filesystem access:
- Static analysis: Configure rules to flag archive extraction patterns where:
- Paths from tar entries or similar formats are concatenated directly onto base directories.
- There is no normalization and boundary check for the resulting paths.
- Code review signals: During review, pay close attention to:
- Any
untar-like logic or custom archive walkers. - Lack of checks to ensure
joined_pathstarts with or resides under the workspace root after canonicalization. - Error handling that silently ignores suspicious paths instead of rejecting them.
- Runtime monitoring: Use filesystem auditing or sandboxing tools to:
- Detect unexpected writes outside known build workspaces during Melange runs.
- Enforce mandatory access control policies that constrain build processes to specific directories.
- Automated tooling: Integrate security-focused linters or SAST tools in CI to detect insecure path handling patterns and missing validation around archive extraction.

