Summary
A path traversal vulnerability in Flatpak can allow files from a malicious SDK container to be written outside the intended build working directory. The issue becomes risky when a developer runs flatpak build-init with writable SDK and SDK extension options against an SDK containing a crafted extension directory path.
Affected context
The vulnerability occurs in Flatpak build initialization workflows that process SDK extension metadata supplied by an SDK container. Deployments are potentially affected when the SDK is untrusted or has been tampered with, the extension is used with writable SDK-related options, and the directory path is resolved without constraining it to the intended working directory.
Exploit preconditions
- Attack surface: Local Flatpak build tooling and SDK container metadata
- Required access: Ability to provide or cause a developer to use a malicious or modified SDK container
- Trigger point: Running
flatpak build-init --writable-sdk --sdk-extension - Why exploitation is possible: The extension directory is resolved without rejecting parent-directory traversal, allowing the resulting path to escape the build directory
Why this happens
The underlying flaw is insufficient canonical-path validation when resolving an attacker-influenced directory path. A path containing parent-directory components can be interpreted outside the designated working directory if the application joins or resolves it without verifying that the final location remains within the approved base. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Potential impact
- Files outside the intended working directory may be created or overwritten
- Developer files, build inputs, or generated artifacts could be modified
- Build integrity and reproducibility could be compromised
- Sensitive data may be exposed indirectly through altered build outputs or configuration
- A malicious SDK could enable broader local compromise when overwritten files are later trusted or executed
General mitigation guidance
Mitigation generally focuses on treating SDK metadata as untrusted input and enforcing directory confinement.
Common defensive patterns include:
- Rejecting absolute paths and parent-directory traversal components
- Canonicalizing candidate paths before use and verifying they remain beneath the approved base directory
- Using filesystem APIs that provide explicit directory confinement where available
- Applying least-privilege permissions to build processes and working directories
- Preferentially using trusted, integrity-verified SDK sources
- Separating build workspaces from sensitive developer files and enforcing appropriate filesystem boundaries
How teams detect issues like this
Organizations can detect related path traversal risks through:
- Static analysis searches for user-controlled paths passed to path-join, path-resolve, extraction, or file-write operations
- Code review checks for missing canonicalization and containment validation
- Tests using absolute paths, parent-directory components, symlinks, and unusual separators
- CI policies requiring approved SDK provenance and integrity verification
- Runtime monitoring for build processes writing outside their designated workspace

