CVE-2026-44214 - eventsource-encoder vulnerable to SSE event injection via unsanitized `event` an
CVE-2026-44214 - eventsource-encoder vulnerable to SSE event injection via unsanitized `event` an
GHSA-m9g3-3g99-mhpx MEDIUM npm/eventsource-encoder
CVE: CVE-2026-44214
Summary
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 (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.
Details
In src/encode.ts, encodeMessage interpolates event and id into the output without inspecting them for line terminators:
if (message.event) {
output += `event: ${message.event}\n`
}
// ...
if (typeof message.id === 'string' || typeof message.id === 'number') {
output += `id: ${message.id}\n`
}The 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.
By contrast, data and comment already normalize all three line-terminator forms via NEWLINES_RE = /(\r\n|\r|\n)/g, so they are not affected.
Proof of concept
import {encode} from 'eventsource-encoder'
// Attacker-controlled value flows into `event`
const userSuppliedTopic = 'message\nevent: admin\ndata: {"role":"admin"}'
console.log(encode({event: userSuppliedTopic, data: 'hello'}))Output:
event: message
event: admin
data: {"role":"admin"}
data: helloThe 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.
Impact
If untrusted input is passed into the event or id field of a message, an attacker can:
- Spoof events of arbitrary type (rerouting payloads to handl
📌 来源: GitHub-Advisory | 🆔 CVE-2026-44214 | 📅 2026-05-08