{"id":"CVE-2026-115897","aliases":["GHSA-m5mm-p8h7-m29v"],"title":"Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body","summary":"Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body","severity":"low","cvss":2.1,"cwe":["CWE-79"],"vendor":"serialize-javascript","product":"serialize-javascript","ecosystem":"npm","affected":["serialize-javascript < 7.1.3"],"patched":["serialize-javascript 7.1.3"],"published":"2026-10-23","updated":"2026-10-23","sourceUpdated":"2026-10-23T22:09:53Z","source":"GHSA","sourceUrl":"https://github.com/advisories/GHSA-m5mm-p8h7-m29v","references":[{"url":"https://github.com/yahoo/serialize-javascript/security/advisories/GHSA-m5mm-p8h7-m29v"},{"url":"https://github.com/yahoo/serialize-javascript/pull/235"},{"url":"https://github.com/yahoo/serialize-javascript/commit/2864b3c6260a3bfd52d2db3e70d1a079de108a61"},{"url":"https://github.com/yahoo/serialize-javascript/releases/tag/v7.1.3"},{"url":"https://github.com/advisories/GHSA-m5mm-p8h7-m29v"}],"tags":["ghsa","npm","cve.org"],"cvssVector":"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","cvssSource":"cna","ingestedAt":"2026-10-24T00:46:53.667Z","slug":"CVE-2026-115897","body":"## Overview\n\n### Impact\n\n`serialize-javascript` escapes its output so it is safe to embed inside a\n`<script>` element. Before 7.1.3 that guarantee did not hold for a **function\nvalue whose source ends in a bare `</script`**.\n\nEach function body is escaped on its own, and a bare `</script` was only\nneutralized when followed — within the same body — by a character the HTML\ntokenizer treats as ending the tag name (TAB, LF, FF, CR, SPACE, `/` or `>`).\nA body ending exactly at `</script` has no following character, so it was\nemitted unescaped. The delimiter is then supplied by the surrounding output\n(for example the newline the `space` option emits after the value), and a\nlater serialized value can supply the closing `>` followed by markup:\n\n```js\nconst serialize = require('serialize-javascript');\nfunction f() {} f.toString = () => 'function f(){ return 1 }//</script';\nfunction g() {} g.toString = () => 'function g(x){ return x } > <img src=x onerror=alert(1)>';\nserialize({ a: { f }, g }, { space: 2 });\n// {\n//   \"a\": {\n//     \"f\": function f(){ return 1 }//</script\n//   },\n//   \"g\": function g(x){ return x } > <img src=x onerror=alert(1)>\n// }\n```\n\nEmbedded in a `<script>` element, the script ends at the injected tag and the\n`<img>` becomes a live element in the page.\n\nExploitation requires an attacker to control the **source text** of a\nserialized function, in practice through a spoofed `toString()`. Real\nfunctions always end in `}`, so ordinary function values are not affected,\nand non-function values (including strings containing `</script`) are\nescaped correctly.\n\n### Patches\n\nFixed in **7.1.3** (#235). The bare `</script` form is now also matched at\nthe end of the function body, so it is escaped regardless of what follows it\nin the output.\n\n### Workarounds\n\nUpgrade to **7.1.3**. If you cannot upgrade, do not serialize function values\nwhose source text (or `toString()`) can be influenced by an attacker.\n\n### Credits\n\nReported by **ha_kr25** via the Yahoo bug bounty program.\n\n## Affected packages\n\n- `serialize-javascript < 7.1.3`\n\n## Remediation\n\nUpgrade to a patched release:\n\n- `serialize-javascript 7.1.3`","depth":"sunlit","depthScore":12,"depthScoreParts":{"impact":11.6,"likelihood":0,"exploitation":0,"ransomware":0},"changes":[]}