Advisory Database
  • Advisories
  • Dependency Scanning
  1. npm
  2. ›
  3. serialize-javascript
  4. ›
  5. CVE-2026-115897

CVE-2026-115897: Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body

October 23, 2026

serialize-javascript escapes its output so it is safe to embed inside a <script> element. Before 7.1.3 that guarantee did not hold for a function value whose source ends in a bare </script.

Each function body is escaped on its own, and a bare </script was only neutralized when followed — within the same body — by a character the HTML tokenizer treats as ending the tag name (TAB, LF, FF, CR, SPACE, / or >). A body ending exactly at </script has no following character, so it was emitted unescaped. The delimiter is then supplied by the surrounding output (for example the newline the space option emits after the value), and a later serialized value can supply the closing > followed by markup:

const serialize = require('serialize-javascript');
function f() {} f.toString = () => 'function f(){ return 1 }//</script';
function g() {} g.toString = () => 'function g(x){ return x } > <img src=x onerror=alert(1)>';
serialize({ a: { f }, g }, { space: 2 });
// {
//   "a": {
//     "f": function f(){ return 1 }//</script
//   },
//   "g": function g(x){ return x } > <img src=x onerror=alert(1)>
// }

Embedded in a <script> element, the script ends at the injected tag and the <img> becomes a live element in the page.

Exploitation requires an attacker to control the source text of a serialized function, in practice through a spoofed toString(). Real functions always end in }, so ordinary function values are not affected, and non-function values (including strings containing </script) are escaped correctly.

References

  • github.com/advisories/GHSA-m5mm-p8h7-m29v
  • github.com/yahoo/serialize-javascript/commit/2864b3c6260a3bfd52d2db3e70d1a079de108a61
  • github.com/yahoo/serialize-javascript/pull/235
  • github.com/yahoo/serialize-javascript/releases/tag/v7.1.3
  • github.com/yahoo/serialize-javascript/security/advisories/GHSA-m5mm-p8h7-m29v
  • nvd.nist.gov/vuln/detail/CVE-2026-115897

Code Behaviors & Features

Detect and mitigate CVE-2026-115897 with GitLab Dependency Scanning

Secure your software supply chain by verifying that all open source dependencies used in your projects contain no disclosed vulnerabilities. Dependency Scanning using SBOM also detects vulnerabilities from proprietary advisories that this site does not include. Learn more about Dependency Scanning using SBOM →

Affected versions

All versions before 7.1.3

Fixed versions

  • 7.1.3

Solution

Upgrade to version 7.1.3 or above.

Impact 4.4 MEDIUM

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

Learn more about CVSS

Weakness

  • CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

Source file

npm/serialize-javascript/CVE-2026-115897.yml

Spotted a mistake? Edit the file on GitLab.

  • Site Repo
  • About GitLab
  • Terms
  • Privacy Statement
  • Contact

Page generated Sun, 25 Oct 2026 00:15:21 +0000.