Summary
A path traversal vulnerability in the @apostrophecms/import-export module allows archive entries to escape the intended extraction directory during .tar.gz imports.
When a privileged CMS user uploads a crafted archive, attacker-controlled files can be written to arbitrary locations on the server filesystem reachable by the Node.js process.
Affected context
The issue arises in ApostropheCMS deployments that use the @apostrophecms/import-export module to handle .tar.gz imports through the CMS UI.
The vulnerable behavior occurs when archive entry names are directly joined with the configured export path using path.join(exportPath, header.name) without any normalization or traversal checks.
In such configurations, any user who has been granted Global Content Modify permission and can access the import interface may supply crafted archive entries whose paths resolve outside the expected extraction directory.
Exploit preconditions
- Attack surface: ApostropheCMS import/export functionality exposed via the standard CMS import UI.
- Required access: Valid authenticated account with Global Content Modify permission (commonly assigned to editors or site managers).
- Trigger point: Uploading and importing a crafted
.tar.gzfile containing entries with traversal segments (e.g.,../) in their names. - Why exploitation is possible: The extraction logic uses
fs.createWriteStream(path.join(exportPath, header.name))without canonical-path validation or rejection of traversal sequences, allowing archive entries to resolve to paths outside the intended export directory.
Why this happens
The core bug is a classic path traversal (Zip Slip) condition where user-controlled archive entry names are trusted as filesystem paths.
Instead of resolving and validating the canonical path, the code simply concatenates exportPath and header.name with path.join(), which does not sanitize .. segments or absolute paths.
This maps directly to CWE-22: Improper Limitation of a Pathname to a Restricted Directory, because the implementation fails to enforce that all extracted files remain within a designated base directory before opening write streams.
Potential impact
- Attacker-controlled files may be written to arbitrary locations accessible to the Node.js process.
- Overwriting of existing application files, configuration, or content stores.
- Planting of malicious server-side scripts or backdoors where a runtime or admin later executes or loads them.
- Tampering with logs, data files, or other assets to aid further compromise or concealment.
- Escalation of impact if the Node.js process has write access to sensitive system directories or shared volumes.
General mitigation guidance
Robust mitigation centers on strictly confining archive extraction to a known-safe directory and treating entry names as untrusted input.
Common defensive patterns include:
- Normalizing each archive entry path (e.g., resolving
.and..) and computing its canonical form before writing to disk. - Verifying that the canonical extraction path starts with the intended base directory; reject entries that escape this boundary.
- Rejecting or sanitizing absolute paths, drive roots, and any entry names containing traversal segments.
- Extracting only into dedicated, least-privilege directories with minimized filesystem access for the process.
- Implementing a clear allowlist of acceptable file types and locations where imported content may be written.
These patterns ensure that even if an attacker controls the archive, files cannot be written outside the designated import area.
How teams detect issues like this
Effective detection typically combines code-centric and operational approaches:
- Static analysis: Define rules to flag uses of
fs.createWriteStream,fs.writeFile, or similar APIs where paths are constructed from untrusted input (such as archive entry names) without canonicalization and boundary checks. - Code review signals: Look for archive extraction code that uses
path.join()directly on user-controlled names, lacks..and absolute path validation, or omits checks that the final path resides under a specific base directory. - Security testing: Incorporate Zip Slip test archives into routine QA and security testing to verify that extraction logic rejects traversal entries.
- Automated tooling: Integrate SAST or dependency scanning tools that recognize common Zip Slip patterns and flag risky extraction implementations in CI pipelines.

