GHSA-M5MM-P8H7-M29V

Vulnerability from github – Published: 2026-10-23 22:09 – Updated: 2026-10-23 22:09
VLAI
Summary
Serialize JavaScript: Cross-site scripting (XSS) via unescaped </script at the end of a serialized function body
Details

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:

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.

Show details on source website

{
  "affected": [
    {
      "package": {
        "ecosystem": "npm",
        "name": "serialize-javascript"
      },
      "ranges": [
        {
          "events": [
            {
              "introduced": "0"
            },
            {
              "fixed": "7.1.3"
            }
          ],
          "type": "ECOSYSTEM"
        }
      ]
    }
  ],
  "aliases": [
    "CVE-2026-115897"
  ],
  "database_specific": {
    "cwe_ids": [
      "CWE-79"
    ],
    "github_reviewed": true,
    "github_reviewed_at": "2026-10-23T22:09:52Z",
    "nvd_published_at": null,
    "severity": "LOW"
  },
  "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 \u2014 within the same body \u2014 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(\u0027serialize-javascript\u0027);\nfunction f() {} f.toString = () =\u003e \u0027function f(){ return 1 }//\u003c/script\u0027;\nfunction g() {} g.toString = () =\u003e \u0027function g(x){ return x } \u003e \u003cimg src=x onerror=alert(1)\u003e\u0027;\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.",
  "id": "GHSA-m5mm-p8h7-m29v",
  "modified": "2026-10-23T22:09:52Z",
  "published": "2026-10-23T22:09:52Z",
  "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"
    }
  ],
  "schema_version": "1.4.0",
  "severity": [
    {
      "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",
      "type": "CVSS_V4"
    }
  ],
  "summary": "Serialize JavaScript: Cross-site scripting (XSS) via unescaped \u003c/script at the end of a serialized function body"
}



Log in or create an account to share your comment.




Tags
Taxonomy of the tags.


Loading…

Loading…

Loading…

Drag nodes to arrange them. Double-click a related vulnerability to open it, or a source to visit its link. The Physics button on the left tunes the layout and the simulation; the legend at the bottom left hides or shows nodes by kind and by sighting type.

Forecast uses a logistic model when the trend is rising, or an exponential decay model when the trend is falling. Fitted via linearized least squares.

Sightings

Author Source Type Date Other

Nomenclature

  • Seen: The vulnerability was mentioned, discussed, or observed by the user.
  • Confirmed: The vulnerability has been validated from an analyst's perspective.
  • Published Proof of Concept: A public proof of concept is available for this vulnerability.
  • Exploited: The vulnerability was observed as exploited by the user who reported the sighting.
  • Patched: The vulnerability was observed as successfully patched by the user who reported the sighting.
  • Not exploited: The vulnerability was not observed as exploited by the user who reported the sighting.
  • Not confirmed: The user expressed doubt about the validity of the vulnerability.
  • Not patched: The vulnerability was not observed as successfully patched by the user who reported the sighting.
Vulnerability timeline

Sightings and recorded dates, grouped by day · UTC

JSON
Events included in the timeline

Loading timeline…


    Loading…

    Loading…

    Loading…

    Related by attack behaviour

    Vulnerabilities whose description is nearest to this one in the vector space of the CIRCL/vulnerability-attack-technique-biencoder model. This is a similarity search over the bi-encoder space (plain cosine), not a classification, and it has no measured accuracy.