Low

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

  • Disclosed: 23.10.2026
  • Updated: 24.10.2026 05:17

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

Affected software

Click a technology to see all vulnerabilities affecting it.

PlatformPackageVulnerable versionsFixed in
npm package serialize-javascript < 7.1.3 7.1.3

References

CVSS score -
CVSS vector
CVSS:4.0/AV:N/AC:H/AT:P/PR:L/UI:P/VC:L/VI:L/VA:N/SC:L/SI:L/SA:N
Weakness (CWE)
CWE-79
Platform
npm
Package
serialize-javascript
Disclosed
23.10.2026
Updated
24.10.2026 05:17

Sources and licenses

OSV / GitHub Advisory Database - GHSA-m5mm-p8h7-m29v - CC BY 4.0

Vulnerability history: serialize-javascript

All published vulnerabilities of this package (npm package), newest first. Shows whether this is a one-off slip or a package that needs watching.

Total entries
7
First → latest
12.2019 10.2026
Without a fix
0
Exploited in attacks
0

Severity breakdown

  • High 2
  • Medium 3
  • Low 2

Disclosures per year

  1. 2019: 1
  2. 2020: 1
  3. 2021: 0
  4. 2022: 0
  5. 2023: 0
  6. 2024: 0
  7. 2025: 1
  8. 2026: 4
  1. Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body this entry
    Low CVE-2026-115897 < 7.1.3 7.1.3
  2. Medium · 5.4 CVE-2024-11831 >= 6.0.0, < 6.0.2 6.0.2
  3. High · 8.1 CVE-2020-7660 < 3.1.0 3.1.0
  4. Medium · 4.2 CVE-2019-16769 < 2.1.1 2.1.1

Know which vulnerabilities affect your application

With the DockRay integration and software inventory enabled, DockRay checks reported component versions against known vulnerabilities and notifies you about confirmed matches. Coverage depends on the supported technology and available advisory data.

Connect your application
DockRay newsletter

Application security in your inbox

Important vulnerabilities, actionable guidance and practical advice for your applications. Choose your technologies and follow what matters to your project.

  • A daily digest of new vulnerabilities, critical ones included.
  • Notifications about important updates.
  • Practical advice on application security and monitoring.

Leave empty to receive updates for every technology.

Free to subscribe. Unsubscribe with one click in any email.