{"id":"CVE-2026-97711","aliases":["CVE-2026-97711","GHSA-gfhx-hw2g-v5hg"],"related":[],"kind":"vulnerability","state":"published","title":"Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script> in serialized function bodies","summary":"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 SCRIPT_CLOSE_REGEXP 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.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"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 SCRIPT_CLOSE_REGEXP 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.","source":"cvelist"},{"lang":"en","text":"### Impact\n\n`serialize-javascript` escapes its output so it is safe to embed inside a\n`<script>` element. In 7.1.1 that guarantee does not hold for **function\nvalues**: a crafted function body can carry a literal, unescaped `</script>`\ninto the output, terminating the script element early so the remainder is\nparsed as HTML.\n\n`SCRIPT_CLOSE_REGEXP` used `<\\/script[^>]*>` as its first alternative. The\ncharacter class excludes only `>`, so a single match could run from one\n`</script` all the way to the next `>` anywhere in the source — swallowing a\nsecond, complete `</script>` along the way. Only one replacement is emitted\nper match, and the plain-code branch neutralizes just the leading `<`\n(`'< ' + match.slice(1)`), so the swallowed tag was re-emitted verbatim.\n\nReaching that shape requires `</script` in code position, which is legal\nJavaScript: `x</script=+/` parses as `x < /script=+/`, a comparison against a\nregex literal.\n\n```js\nconst serialize = require('serialize-javascript');\nconst src = \"function f(x){ return x</script=+/ + '</script><img src=x onerror=alert(1)>' }\";\nconst out = serialize({ h: new Function('return ' + src)() });\n// {\"h\":function f(x){ return x< /script=+/ + '</script><img src=x onerror=alert(1)>' }}\n```\n\nEmbedded as the README documents (`<script>window.S = <%= serialize(state) %></script>`)\nand parsed by Chromium, the script element ends at the injected tag and the\n`<img>` becomes a live DOM node with its `onerror` handler executing in the\npage origin.\n\nOnly the function path is affected. The same payload passed as **data** is\nescaped correctly, and `options.isJSON` / non-function values are unaffected.\n\n### Patches\n\nFixed in **7.1.2**. The wildcard now excludes `<` as well as `>`\n(`[^<>]*`), so a match can never reach past a second `<`. Every `</script`\nin the source therefore either begins its own match or is followed by a\ncharacter the HTML tokenizer does not accept as ending a tag name — it ends\nthe tag name only on TAB, LF, FF, CR, SPACE, `/` or `>`, and emits anything\nelse as text.\n\n### Workarounds\n\nUpgrade to **7.1.2**. If you cannot upgrade, 7.1.0 and earlier are\nunaffected, or avoid serializing functions whose source text is\nattacker-influenced.\n\n### Regression note\n\nThis is a regression specific to 7.1.1, not a long-standing issue. 7.1.0 and\nearlier applied the same wildcard but escaped the **entire** match, so no tag\nsurvived. Downstream scanners defaulting to a `>= 7.1.0` range would be\noverly broad.","format":"markdown","source":"ghsa"}],"published":"2026-09-29T16:00:33.534Z","modified":"2026-09-30T19:38:27.293Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","score":2.3,"rating":"LOW"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","score":2.3,"rating":"LOW"},{"scorer":"GitHub","scheme":"CVSS:4.0","vector":"CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:N/VI:N/VA:N/SC:L/SI:L/SA:N","rating":"LOW"}],"cwes":["CWE-79","CWE-80"],"affected":[{"ranges":[{"version":">= 7.1.1, < 7.1.2","status":"affected"}],"vendor":"yahoo","product":"serialize-javascript","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"7.1.1","status":"affected","fixed":"7.1.2"}],"ecosystem":"npm","package":"serialize-javascript","purl":"pkg:npm/serialize-javascript","source":"ghsa"}],"references":[{"url":"https://github.com/yahoo/serialize-javascript/security/advisories/GHSA-gfhx-hw2g-v5hg","tags":["web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/yahoo/serialize-javascript/commit/2bdbaaff9cb8a4639135eb24cfcd383d3fefb534","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://github.com/yahoo/serialize-javascript/releases/tag/v7.1.2","tags":["web","x-refsource-misc"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-97711","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/yahoo/serialize-javascript","tags":["package"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"none","automatable":"no","technicalImpact":"partial","date":"2026-09-29T16:53:22.214Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-97711","url":"https://www.cve.org/CVERecord?id=CVE-2026-97711","licence":"CVE Terms of Use","modified":"2026-09-29T16:53:35.013Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-gfhx-hw2g-v5hg","url":"https://github.com/advisories/GHSA-gfhx-hw2g-v5hg","licence":"CC-BY-4.0","modified":"2026-09-30T16:00:18.940Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-97711","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-97711","licence":"Public domain","modified":"2026-09-30T19:38:27.293Z"}],"updatedAt":"2026-11-25T22:59:41.488Z","epss":{"score":0.00318,"percentile":0.26675,"date":"2026-12-01T12:00:22.000Z"}}