CVE-2026-97711: Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script> in serialized function bodies

Published Sep 29, 2026
·
Updated

Impact

serialize-javascript escapes its output so it is safe to embed inside a <script> element. In 7.1.1 that guarantee does not hold for function values: a crafted function body can carry a literal, unescaped </script> into the output, terminating the script element early so the remainder is parsed as HTML.

SCRIPTCLOSEREGEXP used <\/script[^>]> as its first alternative. The character class excludes only >, so a single match could run from one </script all the way to the next > anywhere in the source — swallowing a second, complete </script> along the way. Only one replacement is emitted per match, and the plain-code branch neutralizes just the leading < ('< ' + match.slice(1)), so the swallowed tag was re-emitted verbatim.

Reaching that shape requires </script in code position, which is legal JavaScript: x</script=+/ parses as x < /script=+/, a comparison against a regex literal.

js const serialize = require('serialize-javascript'); const src = "function f(x){ return x</script=+/ + '</script><img src=x onerror=alert(1)>' }"; const out = serialize({ h: new Function('return ' + src)() }); // {"h":function f(x){ return x< /script=+/ + '</script><img src=x onerror=alert(1)>' }}

Embedded as the README documents (<script>window.S = <%= serialize(state) %></script>) and parsed by Chromium, the script element ends at the injected tag and the <img> becomes a live DOM node with its onerror handler executing in the page origin.

Only the function path is affected. The same payload passed as data is escaped correctly, and options.isJSON / non-function values are unaffected.

Patches

Fixed in 7.1.2. The wildcard now excludes < as well as > ([^<>]), so a match can never reach past a second <. Every </script in the source therefore either begins its own match or is followed by a character the HTML tokenizer does not accept as ending a tag name — it ends the tag name only on TAB, LF, FF, CR, SPACE, / or >, and emits anything else as text.

Workarounds

Upgrade to 7.1.2. If you cannot upgrade, 7.1.0 and earlier are unaffected, or avoid serializing functions whose source text is attacker-influenced.

Regression note

This is a regression specific to 7.1.1, not a long-standing issue. 7.1.0 and earlier applied the same wildcard but escaped the entire match, so no tag survived. Downstream scanners defaulting to a >= 7.1.0 range would be overly broad.

Other sources

Serialize JavaScript serializes JavaScript values to a superset of JSON that includes regular expressions and functions. From 7.1.1 until 7.1.2, function values serialized by serialize-javascript are not fully protected against script-closing tags in attacker-influenced function source because SCRIPTCLOSEREGEXP can consume a second closing tag inside one match. When the serialized function is embedded in a script element, the surviving closing tag terminates the element early and causes the remaining output to be parsed as HTML, enabling cross-site scripting in the page origin. Only function values are affected; ordinary data values and options.isJSON output are unaffected. This issue is fixed in version 7.1.2.

— MITRE

Affected Software

2 affected componentsFixes available
npm/serialize-javascript>=7.1.1<7.1.2
npm/serialize-javascript>=7.1.1<7.1.2
7.1.2

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.2
  2. Upgrade

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

    Fixed in 7.1.2
  3. Compensating control

    If upgrading is not possible, avoid serializing functions whose source text is attacker-influenced.

Event History

Sep 29, 2026
CVE Published
via MITRE·04:00 PM
Data Sourced
via MITRE·04:00 PM
DescriptionWeakness
Data Sourced
via NVD·04:17 PM
DescriptionSeverityWeakness
Sep 30, 2026
Advisory Published
via GitHub·03:40 PM
Data Sourced
via GitHub·03:40 PM
DescriptionWeaknessAffected Software

Frequently Asked Questions

1

Which uses are exposed to this issue?

Exposure requires serialize-javascript output containing a function value to be embedded in an HTML script element. Ordinary serialized data values and output generated with options.isJSON are unaffected.

2

What attacker control is needed for exploitation?

An attacker must be able to influence function source that is passed to serialize-javascript and have the resulting serialization embedded in a script element. A surviving </script> sequence can then close that element early and cause subsequent output to be interpreted as HTML in the page origin.

3

What should be done if the affected serializer behavior is in use?

Update serialize-javascript to version 7.1.2. Until updating is possible, avoid serializing attacker-influenced function values into script elements; use JSON-only output where compatible, since options.isJSON output is unaffected.

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