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

Published Oct 23, 2026
·
Updated

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:

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

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 hakr25 via the Yahoo bug bounty program.

Other sources

Serialize JavaScript serializes JavaScript values to a superset of JSON that includes regular expressions and functions. Prior to 7.1.3, the function-source escaping logic does not neutralize a bare closing-script prefix when attacker-influenced function source text ends exactly at that prefix. Because each function body is escaped independently, a delimiter supplied by surrounding serialized output can terminate an HTML script element, and a later serialized value supplies injected markup that becomes a live element in the page. Exploitation requires control of a serialized function's source text, such as through a spoofed toString(). This issue is fixed in version 7.1.3.

— MITRE

Affected Software

2 affected componentsFixes available
npm/serialize-javascript<7.1.3
npm/serialize-javascript<7.1.3
7.1.3

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade npm/serialize-javascript to a version that resolves this vulnerability.

    Fixed in 7.1.3
  2. Upgrade

    Upgrade serialize-javascript to a version that resolves this vulnerability.

    Fixed in 7.1.3Patch #235
  3. Compensating control

    If you cannot upgrade, do not serialize function values.

Event History

Oct 23, 2026
CVE Published
via MITRE·09:37 PM
Data Sourced
via MITRE·09:37 PM
DescriptionWeakness
Advisory Published
via GitHub·10:09 PM
Data Sourced
via GitHub·10:09 PM
DescriptionWeaknessAffected Software

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203