Summary
Piscina's worker pool constructor and run() logic can inherit a polluted filename property from Object.prototype when the caller does not provide its own filename field.
If an attacker can influence prototype pollution in the hosting application, they may cause Piscina to spawn worker threads that load and execute an attacker-controlled .mjs module.
Affected context
This vulnerability appears in Node.js applications that use Piscina worker pools and accept options objects that may be influenced by untrusted data.
It manifests when:
- The code relies on plain property access (options.filename) without guarding against prototype inheritance.
- Object.prototype has been polluted so that filename is defined upstream.
- Piscina instantiates worker_threads.Worker using the inherited filename value.
The risk is greatest in complex codebases where shared objects, JSON parsing, or third-party libraries can lead to prototype pollution.
Exploit preconditions
- Attack surface: Node.js application using Piscina to manage worker threads.
- Required access: Ability to trigger or control prototype pollution on Object.prototype.filename (often via another input-handling flaw).
- Trigger point: Invocations of new Piscina(options) or piscina.run(...) when options.filename is not set as an own property.
- Why exploitation is possible: The implementation reads options.filename through simple member access, allowing the read to traverse the prototype chain, which in turn feeds an attacker-controlled path into worker_threads.Worker.
Why this happens
The root cause is unsafe reliance on inherited object properties for security-sensitive configuration, combined with the broader risk of JavaScript prototype pollution.
Instead of restricting configuration reads to own properties or validating the source of filename, the code accesses options.filename directly.
Under prototype pollution (CWE-1321), Object.prototype is modified so that filename resolves to an attacker-controlled string, which is then used as the module path for worker instantiation.
This aligns with CWE-94 (Improper Control of Generation of Code) because user-influenced input determines which code module is loaded and executed inside a worker thread.
Potential impact
- Attacker-controlled JavaScript or TypeScript module may run inside Piscina worker threads.
- Compromise of application integrity, including manipulation of data processed in workers.
- Unauthorized access to in-process secrets that workers can reach (API keys, tokens, configuration).
- Potential lateral movement within the application environment and escalation of impact if workers share resources or credentials.
General mitigation guidance
Effective mitigation centers on isolating configuration from prototype pollution and hardening how options are read:
- Treat all options objects as potentially polluted and only read own properties, for example by using safe object creation patterns or explicit property checks.
- Normalize and validate configuration objects before passing them into Piscina, ensuring filename is defined, sanitized, and not inherited.
- Reduce the attack surface for prototype pollution by avoiding mixing untrusted data into global objects and by freezing or sealing core prototypes where operationally viable.
- Restrict what module paths workers may load by enforcing allowlists, controlled resolution logic, or fixed entry points rather than arbitrary filenames drawn from configuration.
- Apply least-privilege design to worker threads, including limiting accessible environment variables, filesystem paths, and network permissions.
How teams detect issues like this
Detection strategies typically combine code-level review and automated analysis:
- Use static analysis or linters to flag direct use of user-controllable configuration in security-sensitive APIs, especially where property access can traverse Object.prototype.
- During code review, look for patterns where options objects are created from or merged with untrusted input and then passed into Piscina, worker_threads, or dynamic import logic.
- Add runtime assertions or logging around worker instantiation to record resolved module paths and detect unexpected or anomalous values.
- Employ security-focused test cases and fuzzing that attempt prototype pollution (e.g., injecting __proto__ or constructor properties) and observe whether worker creation behavior changes.

