Summary
A path traversal vulnerability in Trivy's OCI artifact handling logic allows the org.opencontainers.image.title annotation to be used directly as a destination filename without validation.
If an attacker can cause Trivy to download a malicious artifact, they can craft this annotation to escape the intended directory and write layer contents to arbitrary locations on the host filesystem.
Affected context
This vulnerability affects environments where Trivy is used to download or scan OCI artifacts whose metadata can be influenced by an attacker. It arises when Trivy trusts the org.opencontainers.image.title manifest annotation and concatenates it into filesystem paths without enforcing directory constraints or sanitizing traversal sequences. The risk is higher in automated pipelines, CI/CD systems, or shared scanning infrastructure that process artifacts from untrusted or partially trusted registries.
Exploit preconditions
- Attack surface: Trivy's OCI artifact download and scanning functionality
- Required access: Ability to make Trivy fetch an attacker-controlled or tampered OCI artifact, typically by pointing it at a malicious image or registry
- Trigger point: Trivy reads the org.opencontainers.image.title annotation from the artifact manifest and uses it directly as a destination filename during layer extraction
- Why exploitation is possible: The annotation value is not validated or normalized, allowing directory traversal sequences or absolute paths that cause writes outside the intended destination directory
Why this happens
The root cause is improper validation of user-controllable path elements, mapping directly to CWE-22: Path Traversal. Trivy treats the org.opencontainers.image.title annotation as a trusted filename and interpolates it into the filesystem path used for storing downloaded artifact layers. Because this value is not sanitized or constrained to a specific directory, attackers can inject relative segments (such as "../") or absolute paths that traverse out of the target directory and reach arbitrary locations. Conceptually, the insecure pattern is: accepting externally supplied identifiers as filesystem paths without normalization, canonicalization, or enforcement of a fixed base directory.
Potential impact
- Trivy may write artifact layer data to arbitrary paths on the host filesystem.
- Attackers could overwrite or corrupt configuration files that Trivy's process can access.
- Pipeline or build environment integrity could be impacted through modification of local data.
- In some deployments, arbitrary file writes could be leveraged toward privilege escalation or persistence.
General mitigation guidance
Effective mitigation focuses on constraining how external metadata influences filesystem paths. Common patterns include:
- Normalizing and validating all filenames derived from OCI annotations or other external inputs, rejecting paths containing traversal sequences or illegal characters.
- Enforcing a strict base directory for all artifact extraction and refusing any path that attempts to escape that directory when canonicalized.
- Using internally generated or fixed filenames for stored layers rather than trusting artifact-provided annotations.
- Running Trivy and related tooling with least privilege, ensuring the scanning process can only write to controlled directories that do not contain sensitive system files.
- Introducing defense-in-depth checks at the application boundary so that metadata from registries is treated as untrusted and subjected to rigorous validation.
How teams detect issues like this
Detection typically centers on identifying unsafe filesystem path construction and anomalous write behavior:
- Static analysis rules that flag concatenation of user-controlled strings (like OCI annotations) into file paths without canonicalization or directory constraints.
- Code reviews that examine functions handling artifact metadata, looking for direct use of manifest annotations in filesystem operations.
- Runtime monitoring or auditing that records file write operations by Trivy, alerting on writes outside expected working or cache directories.
- Policy-based scanning that enforces secure path handling patterns across tooling that interacts with container registries, optionally supported by automated security review tools integrated into CI pipelines.

