{"id":"GHSA-m5mm-p8h7-m29v","summary":"Serialize JavaScript: Cross-site scripting (XSS) via unescaped \u003c/script at the end of a serialized function body","details":"### Impact\n\n`serialize-javascript` escapes its output so it is safe to embed inside a\n`\u003cscript\u003e` element. Before 7.1.3 that guarantee did not hold for a **function\nvalue whose source ends in a bare `\u003c/script`**.\n\nEach function body is escaped on its own, and a bare `\u003c/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 `\u003e`).\nA body ending exactly at `\u003c/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 `\u003e` followed by markup:\n\n```js\nconst serialize = require('serialize-javascript');\nfunction f() {} f.toString = () =\u003e 'function f(){ return 1 }//\u003c/script';\nfunction g() {} g.toString = () =\u003e 'function g(x){ return x } \u003e \u003cimg src=x onerror=alert(1)\u003e';\nserialize({ a: { f }, g }, { space: 2 });\n// {\n//   \"a\": {\n//     \"f\": function f(){ return 1 }//\u003c/script\n//   },\n//   \"g\": function g(x){ return x } \u003e \u003cimg src=x onerror=alert(1)\u003e\n// }\n```\n\nEmbedded in a `\u003cscript\u003e` element, the script ends at the injected tag and the\n`\u003cimg\u003e` 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 `\u003c/script`) are\nescaped correctly.\n\n### Patches\n\nFixed in **7.1.3** (#235). The bare `\u003c/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.","aliases":["CVE-2026-115754","CVE-2026-115897"],"modified":"2026-10-24T02:55:55.507718062Z","published":"2026-10-23T22:09:52Z","database_specific":{"github_reviewed":true,"github_reviewed_at":"2026-10-23T22:09:52Z","nvd_published_at":null,"cwe_ids":["CWE-79"],"severity":"LOW"},"references":[{"type":"WEB","url":"https://github.com/yahoo/serialize-javascript/security/advisories/GHSA-m5mm-p8h7-m29v"},{"type":"WEB","url":"https://github.com/yahoo/serialize-javascript/pull/235"},{"type":"WEB","url":"https://github.com/yahoo/serialize-javascript/commit/2864b3c6260a3bfd52d2db3e70d1a079de108a61"},{"type":"PACKAGE","url":"https://github.com/yahoo/serialize-javascript"},{"type":"WEB","url":"https://github.com/yahoo/serialize-javascript/releases/tag/v7.1.3"}],"affected":[{"package":{"name":"serialize-javascript","ecosystem":"npm","purl":"pkg:npm/serialize-javascript"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"7.1.3"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/10/GHSA-m5mm-p8h7-m29v/GHSA-m5mm-p8h7-m29v.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V4","score":"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"}]}