{"schema":"threatline.record/2","record":{"id":"CVE-2026-97711","aliases":["GHSA-gfhx-hw2g-v5hg"],"summary":"Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script> in serialized function bodies","details":"### 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.","categories":["Libraries & packages"],"product":"serialize-javascript","vendor":"yahoo","ecosystem":"npm","affected_ranges":[{"source":"GitHub Advisory Database","source_url":"https://github.com/advisories/GHSA-gfhx-hw2g-v5hg","source_modified_at":"2026-09-30T15:40:06Z","fetched_at":"2026-10-23T18:42:43.628194Z","package":{"ecosystem":"npm","name":"serialize-javascript"},"range":">= 7.1.1, < 7.1.2"},{"source":"CVE List","source_url":"https://www.cve.org/CVERecord?id=CVE-2026-97711","source_modified_at":"2026-09-29T16:53:35.013Z","fetched_at":"2026-10-23T18:45:31.882637Z","product":"serialize-javascript","vendor":"yahoo","versions":[{"version":">= 7.1.1, < 7.1.2","status":"affected"}],"defaultStatus":null},{"source":"OSV","source_url":"https://osv.dev/vulnerability/GHSA-gfhx-hw2g-v5hg","source_modified_at":"2026-09-30T16:00:18.940888700Z","fetched_at":"2026-10-23T18:42:43.628194Z","package":{"ecosystem":"npm","name":"serialize-javascript","purl":"pkg:npm/serialize-javascript"},"ranges":[{"events":[{"introduced":"7.1.1"},{"fixed":"7.1.2"}],"type":"SEMVER"}],"versions":[]}],"fixed_versions":[{"source":"GitHub Advisory Database","source_url":"https://github.com/advisories/GHSA-gfhx-hw2g-v5hg","source_modified_at":"2026-09-30T15:40:06Z","fetched_at":"2026-10-23T18:42:43.628194Z","package":{"ecosystem":"npm","name":"serialize-javascript"},"version":"7.1.2"},{"source":"OSV","source_url":"https://osv.dev/vulnerability/GHSA-gfhx-hw2g-v5hg","source_modified_at":"2026-09-30T16:00:18.940888700Z","fetched_at":"2026-10-23T18:42:43.628194Z","package":{"ecosystem":"npm","name":"serialize-javascript","purl":"pkg:npm/serialize-javascript"},"version":"7.1.2"}],"cvss":2.3,"severity":"Low","kev":{"listed":false},"epss":{"probability":0.003,"percentile":0.2162,"score_date":"2026-10-23"},"published_at":"2026-09-29T16:00:33.534Z","modified_at":"2026-09-30T16:00:18.940888700Z","provenance":[{"source":"GitHub Advisory Database","url":"https://github.com/advisories/GHSA-gfhx-hw2g-v5hg","fetched_at":"2026-10-23T18:42:43.628194Z","source_modified_at":"2026-09-30T15:40:06Z"},{"source":"CVE List","url":"https://www.cve.org/CVERecord?id=CVE-2026-97711","fetched_at":"2026-10-23T18:45:31.882637Z","source_modified_at":"2026-09-29T16:53:35.013Z"},{"source":"OSV","url":"https://osv.dev/vulnerability/GHSA-gfhx-hw2g-v5hg","fetched_at":"2026-10-23T18:42:43.628194Z","source_modified_at":"2026-09-30T16:00:18.940888700Z"},{"source":"EPSS","url":"https://api.first.org/data/v1/epss?cve=CVE-2026-97711","fetched_at":"2026-10-23T18:42:43.628194Z","source_modified_at":"2026-10-23"}],"sources":["GitHub Advisory Database","CVE List","OSV","EPSS"],"references":[{"source":"CVE List","url":"https://github.com/yahoo/serialize-javascript/security/advisories/GHSA-gfhx-hw2g-v5hg","tags":["x_refsource_CONFIRM"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-97711","source":"GitHub Advisory Database"},{"source":"CVE List","url":"https://github.com/yahoo/serialize-javascript/commit/2bdbaaff9cb8a4639135eb24cfcd383d3fefb534","tags":["x_refsource_MISC"]},{"source":"CVE List","url":"https://github.com/yahoo/serialize-javascript/releases/tag/v7.1.2","tags":["x_refsource_MISC"]},{"url":"https://github.com/advisories/GHSA-gfhx-hw2g-v5hg","source":"GitHub Advisory Database"}],"locations":[],"motoko_assessment":{"status":"requires_architecture_review","automatic_remediation":false},"cve_state":"PUBLISHED","ssvc":{"exploitation":"none","automatable":"no","technical_impact":"partial","assessed_at":"2026-09-29T16:53:22.214214Z"},"classification":{"method":"product-first software-layer rules","rules_version":"2.1","matched_on":"product","confidence":"heuristic","reviewed":false},"change_timestamp":"2026-09-30T16:00:18.940888700Z","content_hash":"903d50ab3ad25531094ea2ea8eb2bbbb4e2968605379ae89cb342267d238182d"}}
