CVE-2026-115897: Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body
Impact serialize-javascript escapes its output so it is safe to embed inside a element. Before 7.1.3 that guarantee did not hold for a function value whose source ends in a bare ). A body ending exactly at followed by markup: Embedded in a element, the script ends at the injected tag and the becomes a live element in the page.
Published Oct 23, 2026
Affected packages
serialize-javascript
- Ecosystem
- npm
- Affected
- < 7.1.3
- Fixed in
- 7.1.3
- Check
npm ls serialize-javascript
Advisory details
From the GitHub Advisory Database (CC BY 4.0).
Impact
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 } > ';
serialize({ a: { f }, g }, { space: 2 });
// {
// "a": {
// "f": function f(){ return 1 }//</script
// },
// "g": function g(x){ return x } >
// }Embedded in a <script> element, the script ends at the injected tag and the `` 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.
Patches
Fixed in 7.1.3 (#235). The bare </script form is now also matched at the end of the function body, so it is escaped regardless of what follows it in the output.
Workarounds
Upgrade to 7.1.3. If you cannot upgrade, do not serialize function values whose source text (or toString()) can be influenced by an attacker.
Credits
Reported by ha_kr25 via the Yahoo bug bounty program.
References
- https://github.com/yahoo/serialize-javascript/security/advisories/GHSA-m5mm-p8h7-m29v
- https://github.com/yahoo/serialize-javascript/pull/235
- https://github.com/yahoo/serialize-javascript/commit/2864b3c6260a3bfd52d2db3e70d1a079de108a61
- https://github.com/yahoo/serialize-javascript/releases/tag/v7.1.3
- https://github.com/advisories/GHSA-m5mm-p8h7-m29v
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. No analysis has been written for this entry yet. Methodology
More npm vulnerabilities
All npm entriesCVE-2026-97711
Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script> in serialized function bodies
low2.3Sep 30, 2026CVE-2026-34043
Serialize JavaScript has CPU Exhaustion Denial of Service via crafted array-like objects
medium5.9Mar 27, 2026GHSA-5c6j-r48x-rmvq
Serialize JavaScript is Vulnerable to RCE via RegExp.flags and Date.prototype.toISOString()
high8.1Feb 28, 2026CVE-2024-11831
Cross-site Scripting (XSS) in serialize-javascript
medium5.4Feb 10, 2025
