Summary
A path traversal issue in the unzip() method of Quarkus OpenAPI Generator allows ZIP entries to be extracted to arbitrary filesystem locations outside the intended output directory.
When a crafted ZIP archive includes directory traversal sequences in entry names, an attacker can cause files to be written outside the target folder, potentially overwriting or planting code and configuration files under specific deployment conditions.
Affected context
The vulnerability appears in environments where Quarkus OpenAPI Generator is used to generate REST clients or server stubs from ZIP-based input.
It affects code paths that call the vulnerable unzip() method in ApicurioCodegenWrapper.java and pass ZIP archives that may not be fully trusted or validated.
The risk is most relevant where the generation output directory is on the same filesystem as application source, build artifacts, or sensitive configuration, and where generated files may subsequently be compiled, executed, or loaded by other tooling.
Exploit preconditions
- Attack surface: Components that invoke Quarkus OpenAPI Generator with externally supplied or modifiable ZIP archives (e.g., uploaded specs, integrated pipelines, or shared build artifacts).
- Required access: Ability to provide or influence the ZIP file processed by the unzip() method, either directly (file upload, URL input) or indirectly (compromised upstream artifact).
- Trigger point: Execution of the code generation process that unpacks the ZIP to an output directory.
- Why exploitation is possible: The code constructs destination paths with
new File(toOutputDir, entry.getName())and writes content without normalizing and validating the resulting path to ensure it stays within the intended output directory, enabling directory traversal via../segments.
Why this happens
The bug stems from insufficient validation of file paths derived from ZIP entry names during extraction.
The implementation trusts entry.getName() and directly concatenates it with the output directory, failing to normalize the resulting path and verify that it does not escape the designated root.
This maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where untrusted path components allow access to filesystem locations outside the intended directory.
In abstract terms, any archive extraction routine that does not canonicalize paths and explicitly enforce a "stay within this base directory" policy is vulnerable to this class of directory traversal.
Potential impact
- Arbitrary file creation in directories outside the intended generation output folder
- Overwriting of existing files accessible to the running process, such as source code, templates, or configuration files
- Planting of malicious Java or configuration files that may later be compiled or executed by build tools or runtime environments
- Interference with build pipelines or developer environments by corrupting generated sources or project metadata
- In some setups, potential escalation to remote code execution if overwritten files are subsequently executed with higher privileges or exposed via other services
General mitigation guidance
Effective mitigation focuses on enforcing strict directory boundaries and treating archive contents as untrusted.
Pattern-based hardening approaches include:
- Normalizing and canonicalizing the destination path for each ZIP entry, and verifying that it is still a descendant of the intended output directory before writing.
- Rejecting or skipping entries whose names contain path traversal sequences, absolute paths, or drive prefixes, and maintaining a strict allowlist of acceptable patterns (e.g., no
..segments). - Running code generation processes with the least filesystem privileges necessary, isolating their output to dedicated directories that do not contain sensitive files.
- Avoiding reuse of generation output directories that overlap with core application or system directories, helping to limit the impact of any unexpected files.
- Treating all archive input as untrusted and applying input validation policies at the boundary where ZIP files are accepted or assembled.
How teams detect issues like this
Detection can be approached at both code and process levels:
- Static analysis: Configure rules or custom checks to flag uses of ZIP/Archive extraction APIs where entry names are directly combined with target directories without canonicalization and boundary checks.
- Code review: Look for patterns like
new File(baseDir, entry.getName())followed by write operations, and verify that there is explicit logic to reject or sanitize entries with.., absolute paths, or unusual prefixes. - Policy enforcement: Establish internal secure coding guidelines around archive processing, and integrate automated linters into CI to detect non-compliant path handling.
- Runtime and pipeline monitoring: In build or generator environments, log extracted file paths and alert on writes that fall outside expected directories, helping to surface misuse or unexpected archive contents.

