{"id":"CVE-2026-44214","aliases":["CVE-2026-44214","GHSA-m9g3-3g99-mhpx"],"related":[],"kind":"vulnerability","state":"published","title":"eventsource-encoder: SSE event injection via unsanitized event and id fields","summary":"eventsource-encoder encodes events as well-formed EventSource/Server Sent Event (SSE) messages. Prior to 1.0.2, eventsource-encoder does not sanitize the event or id fields of an EventSourceMessage before serializing them. An attacker who controls either field can inject arbitrary Server-Sent Events line terminators (\\n, \\r, or \\r\\n) and thereby forge additional SSE fields or entire messages on the stream. This vulnerability is fixed in 1.0.2.","summarySource":"cvelist","descriptions":[{"lang":"en","text":"eventsource-encoder encodes events as well-formed EventSource/Server Sent Event (SSE) messages. Prior to 1.0.2, eventsource-encoder does not sanitize the event or id fields of an EventSourceMessage before serializing them. An attacker who controls either field can inject arbitrary Server-Sent Events line terminators (\\n, \\r, or \\r\\n) and thereby forge additional SSE fields or entire messages on the stream. This vulnerability is fixed in 1.0.2.","source":"cvelist"},{"lang":"en","text":"### Summary\n\n`eventsource-encoder` does not sanitize the `event` or `id` fields of an `EventSourceMessage` before serializing them. An attacker who controls either field can inject arbitrary Server-Sent Events line terminators (`\\n`, `\\r`, or `\\r\\n`) and thereby forge additional SSE fields or entire messages on the stream. This is similar in spirit to [GHSA-4hxc-9384-m385](https://github.com/advisories/GHSA-4hxc-9384-m385) (h3), but the vulnerable fields are `event`/`id` rather than `data`/`comment`. These are less likely to be user-controllable, but should still be sanitized.\n\n### Details\n\nIn `src/encode.ts`, `encodeMessage` interpolates `event` and `id` into the output without inspecting them for line terminators:\n\n```ts\nif (message.event) {\n  output += `event: ${message.event}\\n`\n}\n// ...\nif (typeof message.id === 'string' || typeof message.id === 'number') {\n  output += `id: ${message.id}\\n`\n}\n```\n\nThe SSE specification treats `\\r`, `\\n`, and `\\r\\n` as line terminators. A `\\n` (or `\\r`) embedded in either field is rendered as the end of that field, allowing the rest of the input to be interpreted by the client as new SSE fields.\n\nBy contrast, `data` and `comment` already normalize all three line-terminator forms via `NEWLINES_RE = /(\\r\\n|\\r|\\n)/g`, so they are not affected.\n\n### Proof of concept\n\n```js\nimport {encode} from 'eventsource-encoder'\n\n// Attacker-controlled value flows into `event`\nconst userSuppliedTopic = 'message\\nevent: admin\\ndata: {\"role\":\"admin\"}'\n\nconsole.log(encode({event: userSuppliedTopic, data: 'hello'}))\n```\n\nOutput:\n\n```\nevent: message\nevent: admin\ndata: {\"role\":\"admin\"}\ndata: hello\n\n```\n\nThe browser sees two events: a forged `admin` event with attacker-chosen payload, followed by the legitimate `message` event. The same primitive works through `id` for any string id value.\n\n### Impact\n\nIf untrusted input is passed into the `event` or `id` field of a message, an attacker can:\n\n- Spoof events of arbitrary type (rerouting payloads to handlers the attacker chooses)\n- Inject additional SSE fields (`data:`, `id:`, `retry:`) into the stream\n- Split a single `encode()` call into multiple distinct browser events\n- Override the client's `Last-Event-ID` via injected `id:` lines\n\nThe vulnerability requires that an application places attacker-controlled data into `event` or `id`. Applications that only put trusted, statically-defined values into these fields are not affected.\n\n### Patches\n\nFixed in `eventsource-encoder@1.0.2`. The `event` and string `id` fields are now validated; any value containing `\\r` or `\\n` causes the encoder to throw a `TypeError` rather than emit a malformed stream.\n\n### Workarounds\n\nIf users cannot upgrade, validate or strip line terminators from any untrusted value before passing it to `encode` / `encodeMessage`:\n\n```js\nfunction safeSingleLine(value) {\n  if (/[\\r\\n]/.test(value)) throw new Error('SSE field must be single-line')\n  return value\n}\n\nencode({event: safeSingleLine(topic), id: safeSingleLine(id), data})\n```\n\n### Resources\n\n- Related advisory (different package, same class): https://github.com/advisories/GHSA-4hxc-9384-m385\n- SSE spec, line terminators: https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream\n\n### Credit\n\nDiscovered while reviewing in light of GHSA-4hxc-9384-m385.","format":"markdown","source":"ghsa"},{"lang":"es","text":"eventsource-encoder codifica eventos como mensajes EventSource/Server Sent Event (SSE) bien formados. Antes de la versión 1.0.2, eventsource-encoder no sanitiza los campos 'event' o 'id' de un EventSourceMessage antes de serializarlos. Un atacante que controla cualquiera de los dos campos puede inyectar terminadores de línea arbitrarios de Server-Sent Events (\\n, \\r, o \\r\\n) y de este modo forjar campos SSE adicionales o mensajes completos en el flujo. Esta vulnerabilidad está corregida en la versión 1.0.2.","source":"nvd"}],"published":"2026-05-08T20:49:40.000Z","modified":"2026-07-24T11:10:00.170Z","severity":{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:L/A:N","score":5.8,"rating":"MEDIUM"},"severities":[{"scorer":"GitHub_M","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:L/A:N","score":5.8,"rating":"MEDIUM"},{"scorer":"GitHub","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:N/I:L/A:N","score":5.8,"rating":"MEDIUM"},{"scorer":"NVD","scheme":"CVSS:3.1","vector":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:L/A:N","score":5.3,"rating":"MEDIUM"}],"cwes":["CWE-93","CWE-113"],"affected":[{"ranges":[{"version":"< 1.0.2","status":"affected"}],"vendor":"rexxars","product":"eventsource-encoder","source":"cvelist"},{"ranges":[{"type":"semver","introduced":"0","status":"affected","fixed":"1.0.2"}],"ecosystem":"npm","package":"eventsource-encoder","purl":"pkg:npm/eventsource-encoder","source":"ghsa"},{"ranges":[{"status":"affected","fixed":"1.0.2"}],"vendor":"rexxars","product":"eventsource-encoder","cpe":"cpe:2.3:a:rexxars:eventsource-encoder:*:*:*:*:*:node.js:*:*","source":"nvd"}],"references":[{"url":"https://github.com/rexxars/eventsource-encoder/security/advisories/GHSA-m9g3-3g99-mhpx","tags":["exploit","mitigation","vendor-advisory","web","x-refsource-confirm"],"sources":["cvelist","ghsa","nvd"]},{"url":"https://nvd.nist.gov/vuln/detail/CVE-2026-44214","tags":["advisory"],"sources":["ghsa"]},{"url":"https://github.com/rexxars/eventsource-encoder","tags":["package"],"sources":["ghsa"]},{"url":"https://html.spec.whatwg.org/multipage/server-sent-events.html#parsing-an-event-stream","tags":["web"],"sources":["ghsa"]}],"credits":[],"assigner":"GitHub_M","ssvc":{"scorer":"CISA-ADP","exploitation":"poc","automatable":"yes","technicalImpact":"partial","date":"2026-05-27T13:19:24.561Z"},"sources":[{"source":"cvelist","name":"CVE List","id":"CVE-2026-44214","url":"https://www.cve.org/CVERecord?id=CVE-2026-44214","licence":"CVE Terms of Use","modified":"2026-05-27T13:19:45.558Z"},{"source":"ghsa","name":"GitHub Advisory Database","id":"GHSA-m9g3-3g99-mhpx","url":"https://github.com/advisories/GHSA-m9g3-3g99-mhpx","licence":"CC-BY-4.0","modified":"2026-06-08T23:45:16.047Z"},{"source":"nvd","name":"NVD","id":"CVE-2026-44214","url":"https://nvd.nist.gov/vuln/detail/CVE-2026-44214","licence":"Public domain","modified":"2026-07-24T11:10:00.170Z"}],"updatedAt":"2026-11-25T22:59:22.374Z","epss":{"score":0.00277,"percentile":0.2155,"date":"2026-12-01T12:00:22.000Z"}}