Summary
A directory traversal flaw in the extractFile method of org.codehaus.plexus.util.Expand (plexus-utils) allows crafted archive entries to escape the intended extraction directory.
When untrusted archives are processed, an attacker may leverage this to write files to arbitrary locations and, in some environments, reach arbitrary code execution via overwritten or planted executables, scripts, or configuration files.
Affected context
This vulnerability appears in Java applications that depend on plexus-utils and use org.codehaus.plexus.util.Expand to unpack archives (e.g., ZIPs) without enforcing safe extraction paths.
It is most relevant when:
- The application processes archives supplied or influenced by external users, CI/CD jobs, or plugins.
- Extracted content is written to directories that affect application behavior, build artifacts, or deployment outputs.
- Downstream tools may execute or load files from these locations after extraction.
Exploit preconditions
- Attack surface: Archive extraction functionality exposed via APIs, build tools, plugins, or web interfaces that call
Expand.extractFile. - Required access: Ability to provide or manipulate the archive being extracted (e.g., uploaded artifact, dependency bundle, plugin package, or build input).
- Trigger point: The application invokes
Expandon the attacker-controlled archive, and path normalization/validation does not prevent traversal sequences. - Why exploitation is possible: The implementation does not robustly sanitize or constrain file paths inside the archive, allowing use of
../or absolute path tricks to escape the intended extraction directory and write files elsewhere.
Why this happens
The core issue aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
The extractFile logic relies on archive entry names to construct filesystem paths but does not consistently validate that the resulting paths remain inside the designated target directory.
Attackers can craft archive entries with traversal sequences (../ segments) or special paths so that, after path resolution, files land outside the expected extraction root.
When those locations are sensitive (e.g., configuration folders, classpath directories, or executable locations), the bug shifts from a filesystem integrity issue into a code-execution primitive through subsequent use of the modified files.
Potential impact
- Overwriting existing files on the server, workstation, or build agent where extraction runs.
- Creating new files in directories outside the intended extraction root.
- Planting or modifying scripts, JARs, configuration files, or binaries that may later be executed.
- Tampering with build outputs and artifacts in CI/CD pipelines (supply-chain risk).
- Escalating to arbitrary code execution if overwritten or planted files are trusted and run by the system or application.
General mitigation guidance
Effective mitigation focuses on constraining file extraction paths and limiting trust in archive contents:
- Enforce strict path normalization and verification: resolve each target path and confirm it remains within the expected extraction root before writing.
- Reject archive entries containing
.., absolute paths, or platform-specific path escape tricks. - Use higher-level utilities or libraries that provide "zip-slip"-safe extraction routines by default.
- Run archive extraction in directories with limited privileges; avoid extracting directly into system paths, shared classpaths, or live application directories.
- Apply least-privilege OS permissions to the process performing extraction so that, even if traversal occurs, the impact is constrained.
- Treat all externally supplied archives as untrusted inputs and apply the same scrutiny as for other user-controlled data.
How teams detect issues like this
Organizations may identify this type of vulnerability through a combination of code inspection and automated analysis:
- Static analysis patterns:
- Flag uses of
org.codehaus.plexus.util.Expandor custom archive extraction code that concatenates paths without explicit root-bound checks. - Look for missing validation of archive entry names and absence of checks that resolved paths stay beneath a specific base directory.
- Code review signals:
- Manual inspection of any "unzip", "untar", or "expand" logic, especially in build tools, plugins, and artifact handling code.
- Attention to code that extracts directly into configuration or execution paths (e.g.,
bin/,lib/, plugin directories). - Policy enforcement:
- CI rules that disallow custom archive extraction helpers unless they pass a security review or conform to a standardized, vetted utility.
- Use of SAST/IDE plugins that highlight common "zip-slip" / directory traversal patterns in archive-handling code.

