Summary
Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body
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.
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 } > <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.
Untrusted input is rendered as active markup in a victim's browser, which can run script in their session. Typical impact: session or credential theft, and actions taken as the user.
Affected versions
Security releases
Kodem intelligence
Severity tells you how bad this could be in the worst case. It does not tell you whether you are exposed. Exploitability and impact are functions of runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A vulnerable package can sit in your dependency tree and never run.
Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter. Kodem's runtime-powered SCA identifies whether this CVE is reachable in your applications.
Already deployed Kodem?
See it in your environmentNew to Kodem? Get a demo →Remediation advice
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.
Frequently Asked Questions
- What is CVE-2026-115897? CVE-2026-115897 is a low-severity cross-site scripting (XSS) vulnerability in serialize-javascript (npm), affecting versions < 7.1.3. It is fixed in 7.1.3. Untrusted input is rendered as active markup in a victim's browser, which can run script in their session.
- Which versions of serialize-javascript are affected by CVE-2026-115897? serialize-javascript (npm) versions < 7.1.3 is affected.
- Is there a fix for CVE-2026-115897? Yes. CVE-2026-115897 is fixed in 7.1.3. Upgrade to this version or later.
- Is CVE-2026-115897 exploitable, and should I be worried? Whether CVE-2026-115897 is exploitable in your environment depends on whether the vulnerable code is present and reachable. A CVSS score is a worst-case rating; it does not account for your specific deployment, configuration, or usage patterns. Kodem, an Intelligent Application Security platform, uses runtime intelligence to show which vulnerabilities actually execute in production, so you can focus on the ones that represent real risk. Get a demo
- What actually determines whether CVE-2026-115897 is exploitable, and how bad it is? Exploitability and impact are not fixed properties of a CVE. They depend on runtime truth: whether the vulnerable code is present, reachable, and actually executes in your application. A high CVSS score on a dependency that never runs is not the same as real risk. Kodem, an Intelligent Application Security platform, uses runtime intelligence to reveal which vulnerabilities actually execute in production, so teams prioritize the ones that genuinely matter.
- How do I fix CVE-2026-115897? Upgrade
serialize-javascriptto 7.1.3 or later.