Summary
Rollup's core engine contains a path traversal flaw in its filename handling that allows arbitrary file writes when generating bundle outputs.
If an attacker can influence output filenames—through CLI input names, manual chunk aliases, or malicious plugins—they may use traversal sequences (e.g., ../) to overwrite files anywhere the build process has write access, potentially enabling persistent remote code execution via modified configuration or code files.
Affected context
This vulnerability affects environments where Rollup is used as a JavaScript module bundler and untrusted or semi-trusted parties can influence output filenames.
Typical risk scenarios include:
- Build pipelines that accept user-controlled entry points or file names via CLI or configuration
- Projects that rely on external or third-party Rollup plugins which may manipulate chunk names or aliases
- Multi-tenant or CI/CD environments where different teams or services share the same build infrastructure and filesystem
The issue is present in Rollup versions prior to 2.80.0, 3.30.0, and 4.59.0 (including affected 4.x releases) where path normalization and sanitization for output paths are incomplete.
Exploit preconditions
- Attack surface: Rollup build configuration and inputs (CLI arguments, config files, plugin APIs).
- Required access: Ability to:
- Provide or modify Rollup input file names, entry points, or output configuration; or
- Supply or control Rollup plugins that can set manual chunk aliases or output names.
- Trigger point: Executing a Rollup build that processes attacker-controlled names and writes bundle artifacts to disk.
- Why exploitation is possible: The core engine trusts output filename values and performs insufficient normalization and validation against traversal patterns (
../) and absolute paths. As a result, resolved output paths can escape the intended output directory and target arbitrary writable locations on the host filesystem.
Why this happens
The root cause is improper restriction of path construction when generating output files.
Rollup's core engine accepts user- or plugin-controlled names (such as entry point names and manual chunk aliases) and interpolates them directly into output paths. Without strict normalization, canonicalization, and whitelisting of allowed directories, path traversal sequences like ../ and similar constructs can cause the resolved path to point outside the intended build output directory. This aligns with CWE-22: Improper Limitation of a Pathname to a Restricted Directory, where application logic fails to enforce directory boundaries and relies on incomplete or ad-hoc string sanitization instead of robust path validation.
Potential impact
- Overwriting application source files or build artifacts that are later served to users or executed on servers
- Modifying user- or system-level configuration files to achieve persistent code execution
- Tampering with CI/CD pipeline scripts, hooks, or deployment manifests
- Corrupting security-related files (e.g., environment configuration, access control lists, or startup scripts) within the permissions of the build process
- Disrupting service availability by overwriting critical files, leading to application or system failures
General mitigation guidance
Effective mitigation focuses on enforcing strict output path boundaries and reducing trust in user-controlled names:
- Constrain output directories: Ensure that all generated file paths are resolved against a predefined, canonical output directory, rejecting or rewriting any paths that attempt to escape this root.
- Normalize and validate paths: Normalize paths to their canonical form and perform checks on the normalized result (not the raw string) to detect traversal (
../, absolute paths, or drive prefixes) before writing. - Apply allowlists for file locations: Restrict outputs to known safe subpaths (e.g., specific bundles, asset directories) and avoid deriving directory structures directly from user or plugin inputs.
- Sanitize attacker-controlled identifiers: When using CLI arguments, manual chunk aliases, or plugin-generated names, filter them to a safe character set and disallow path separators or dot-dot segments entirely.
- Isolate build permissions: Run build processes under least-privilege accounts with minimal filesystem write access, and, where feasible, in containerized or ephemeral environments to limit damage from arbitrary file writes.
- Review plugin behavior: Treat plugins as code with full impact on the build system; avoid loading untrusted plugins and ensure internal plugins do not pass raw user-supplied strings into output name fields.
How teams detect issues like this
Detection approaches can focus on both code and environment behavior:
- Static analysis and code review:
- Look for code paths in build tools or plugins that concatenate user input into file paths without canonicalization.
- Flag uses of output name or chunk alias APIs where the value may come from external configuration, HTTP parameters, or multi-tenant inputs.
- Review any custom Rollup plugins for direct use of user-controlled strings in
fileName,chunkFileNames,entryFileNames, or similar options. - Policy enforcement in CI/CD:
- Enforce policies that disallow unreviewed or third-party plugins in sensitive build pipelines.
- Use configuration linters to detect unsafe patterns such as path separators in names passed via environment variables or CLI.
- Runtime and filesystem monitoring:
- Monitor build environments for writes outside expected output directories by the Rollup build user.
- Use allowlist-based filesystem policies (e.g., sandboxing, mandatory access control) to log or block write attempts beyond designated build folders.
- Automated tooling:
- Integrate general-purpose SAST tools that can identify path traversal and arbitrary file-write patterns.
- Employ configuration scanning tools that highlight potentially dangerous use of dynamic filenames or uncontrolled paths.

