Summary
pf4j contains a path traversal (Zip Slip) vulnerability in the extract() function of Unzip.java, where zip entry names are not properly normalized and validated before being written to disk.
An attacker who can supply or influence the zip file content may cause files to be created or overwritten outside the intended extraction directory, leading to data corruption, configuration tampering, or potential code execution in certain deployments.
Affected context
This vulnerability appears in environments where pf4j is used to extract plugin archives or other zip bundles via the Unzip.extract() functionality.
It is relevant when the application accepts zip files from external or semi-trusted sources and extracts them on the server-side.
The risk increases when the extraction root is close to application binaries, configuration folders, or other sensitive directories, or when the running process has broad filesystem permissions.
Exploit preconditions
- Attack surface: Any server-side or build-time functionality that uses pf4j's
Unzip.extract()to unpack zip files. - Required access: Ability to provide or control a zip file that will be extracted (e.g., plugin upload, extension repository, or automated update mechanism).
- Trigger point: The vulnerable
extract()method processes zip entries whose names contain../or absolute paths. - Why exploitation is possible: The implementation lacks robust path normalization and post-normalization checks to ensure that the output path remains within the intended extraction directory, allowing crafted zip entries to escape the target folder.
Why this happens
The underlying bug is a classic path traversal during archive extraction (Zip Slip).
The extract() method in Unzip.java uses zip entry names directly to construct filesystem paths without enforcing that the final, normalized path remains confined to the designated extraction root.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where user-controlled or external input (zip entry names) influences file system paths without adequate canonicalization and boundary checks.
The abstract insecure pattern is: "Use of untrusted path components from archive metadata to create files on disk, without validating that the resolved path is within a trusted directory."
Potential impact
- Overwriting application or configuration files that the pf4j process can write to
- Creating new files in sensitive locations, which could be used to plant malicious scripts or code
- Tampering with plugin directories, logs, or data files, potentially affecting integrity and availability
- In some deployments, escalating to remote code execution if overwritten files are later executed or interpreted by the system
General mitigation guidance
Effective mitigation focuses on strictly confining archive extraction to a safe directory and rejecting unsafe paths:
- Normalize each zip entry path (e.g., using canonical path resolution) and verify that it remains a child of the intended extraction root before writing.
- Reject entries containing path traversal sequences (such as
../) or absolute paths, rather than attempting to "fix" them silently. - Use high-level archive extraction utilities or libraries that include built-in Zip Slip protections where possible.
- Run the extraction logic under least-privilege accounts with write access limited to non-sensitive directories.
- Treat all external archives as untrusted data and pair extraction with additional hardening (e.g., separate working directories, containerization).
How teams detect issues like this
Detection typically combines code-level review and behavioral monitoring:
- Static analysis: Flag file operations where paths are derived from zip entry names or other archive metadata without canonicalization and boundary checks.
- Code review signals: Look for direct concatenation of
ZipEntry.getName()(or equivalent) with target directories, missing checks that the resolved path starts with the extraction root, and absence of explicit traversal rejection logic. - Policy enforcement: Add secure extraction patterns to coding standards and apply automated checks in CI to prevent unvalidated path writes from archive data.
- Runtime monitoring: Optionally log extraction destinations and alert on attempts to write outside expected directories when extracting archives.

