Skip to content

Security

Rollup bundles code that you chose to build. This page describes which part of that we treat as a security boundary, and what you need to take care of yourself when Rollup processes code from someone else, such as pull requests from forks, uploaded packages, scanner input or code submitted to a bundling service. To report a vulnerability, follow SECURITY.md.

Generated code is the security boundary ​

We treat it as a security issue if Rollup's own transformations introduce a security problem into the generated code that was not present in the sources. That is the class of problem we want reported to us, and it is what the bundler is responsible for.

The following sections are about the process that runs Rollup. There we do a best effort, but we cannot offer the same guarantees.

Writing outside the output directory ​

Rollup writes generated files to output.file or output.dir and checks that generated file names stay inside that directory, but this check is a safety net rather than a sandbox:

  • Symlinks are followed when writing. If the output directory, one of its parents or an existing file or subdirectory inside it is a symlink, files are written to the symlink target. Such symlinks can come from the source tree, for example when a pull request commits dist/assets as a symlink.
  • The configuration file and plugins run arbitrary Node.js code with the permissions of the Rollup process and can write anywhere.

With output.file, emitted assets are written relative to that file's directory. Do not treat the output directory as a boundary when the input is untrusted.

Crashes and resource exhaustion ​

Parsing runs in native code, or in WebAssembly for @rollup/wasm-node and @rollup/browser. Certain inputs — deeply nested arrays, objects, parentheses or operator chains, for example — can exhaust the stack. With the native build, the operating system then terminates the process: there is no exception to catch, no uncaughtException handler runs, and no plugin hook such as buildEnd or renderError is called. With the WebAssembly builds the failure surfaces as an error, but the shared parser can stay unusable, see below.

Less extreme nesting instead surfaces as a regular RangeError, large inputs can exhaust memory, and some inputs or plugins can make a build run for arbitrarily long. The same applies when the parser is used directly through parseAst, parseAstAsync or this.parse, and to rollup.watch or a long-running server that embeds Rollup.

We cannot guarantee that Rollup will never crash or run out of memory on arbitrary input. We accept reports about these failures and assess them case by case; depending on the impact and the scope, we usually do not treat them as security vulnerabilities. See SECURITY.md for the policy.

Running Rollup on untrusted code ​

Rollup is a local build tool. Running it in a server is supported, but the server has to assume that Rollup can fail in ways the server cannot observe or catch. If the code is not trusted, assume that Rollup can be made to crash, exhaust memory or CPU, read files it should not see, or write outside the intended directory. The protections have to come from the surrounding system:

  • Run such builds in a disposable process, container or VM, never in the long-lived process that serves your users. A worker thread is not enough: a native crash takes down the whole process.
  • Supervise the build from outside. Restart on abnormal exit and treat a vanished build process as a failed build; in-process error handling does not see the failures described above.
  • Bound memory, CPU time and wall-clock time, and kill the build when it exceeds them.
  • Expose only the files the build needs, read-only except where the build has to write, and deny network access.
  • Write to an empty directory created by the build job, then copy the results out without following symlinks.
  • Do not return raw error messages, code frames or source maps to whoever submitted the code unless that is acceptable to you; they can contain file contents.
  • With @rollup/wasm-node and @rollup/browser, the parser is shared by everything in the same process, page or worker. After a failure, discard that process, page or worker, because the parser may keep throwing on valid input.
  • If the configuration file or plugins come from the untrusted source, as in pull requests from forks, the build runs arbitrary code, because Rollup executes the configuration file and plugins as they are; only the isolation described here protects you then.
  • Keep Rollup and its plugins up to date.

Released under the MIT License.