CVE-2022-25904: Prototype Pollution in safe-eval

safe-eval Updated 02 Oct 2025

Summary

20/12/2022
No i
Critical
9.8

CVE-2022-25904: safe-eval vulnerable to Prototype Pollution. Affects safe-eval versions < 0.4.1. No fix is published. How to fix ↓

Free scan

Check if this vulnerability affects your application

Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Devnack Penetration testing for web, API and mobile Manual testing by engineers who build software, not an auditor's checklist. Trusted by teams at Swift and Google Talk to Devnack

Background

The safe-eval package is an npm package that provides a function called safeEval, which allows users to evaluate JavaScript code in a safe manner. It is commonly used in applications that require dynamic code execution, such as sandboxed environments or code editors. However, all versions of safe-eval are vulnerable to Prototype Pollution, a type of vulnerability that allows an attacker to modify or add properties to the Object.prototype.Consolidate object. This vulnerability is due to the usage of the vm variable in the safeEval function, which can be exploited by an attacker to manipulate the Object.prototype.

Vulnerability Detail

The Prototype Pollution vulnerability in safe-eval can have severe consequences. By modifying the Object.prototype.Consolidate object, an attacker can potentially alter the behavior of the entire JavaScript application. This can lead to various security issues, such as remote code execution, information disclosure, or privilege escalation. The vulnerability can be triggered by passing malicious input to the safeEval function, allowing the attacker to execute arbitrary code within the application's context.

How To Fix

No fixed version is published for this vulnerability.

Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →

Workaround

If upgrading the safe-eval package is not immediately feasible, a possible workaround is to implement input validation and sanitization before passing the input to the safeEval function. By carefully validating and sanitizing the input, the risk of exploitation can be mitigated. Here is an example of how input validation can be implemented in JavaScript:

function safeEvalWrapper(input) {
  // Perform input validation and sanitization here
  if (typeof input !== 'string') {
    throw new Error('Invalid input');
  }

  // Call the safeEval function with the sanitized input
  return safeEval(input);
}

Conclusion

The Prototype Pollution vulnerability in the safe-eval package can have serious security implications. It is crucial to update to a non-vulnerable version of the package or consider using alternative packages. Implementing input validation and sanitization can provide a temporary workaround until the package can be updated. For further support on vulnerability remediation, please contact DevNack.com.

See every vulnerability recorded for safe-eval →

Share this vulnerability

FAQ

Prototype Pollution is a vulnerability that occurs when an attacker is able to modify the prototype of an object, allowing them to add or modify properties that affect all instances of that object. This can lead to unexpected behavior and security issues.

The safe-eval package can be exploited by passing malicious input to the safeEval function. This input can contain JavaScript code that manipulates the Object.prototype.Consolidate object, leading to potential security vulnerabilities.

The consequences of this vulnerability can vary depending on how it is exploited. Possible consequences include remote code execution, information disclosure, and privilege escalation. It is important to address this vulnerability to prevent these potential security issues.

Yes, a fix for this vulnerability has been released in version 0.4.2 of the safe-eval package. It is recommended to update to this version or any subsequent version to mitigate the risk of exploitation.

If upgrading the safe-eval package is not immediately feasible, a possible workaround is to implement input validation and sanitization before passing the input to the safeEval function. This can help mitigate the risk of exploitation by ensuring that only safe input is processed.

Related vulnerabilities

Recent vulnerabilities recorded for safe-eval.

How To Fix

No fixed version is published for this vulnerability.

Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback