Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

eventsource

Latest version: v5.1.7

Overview

Last scanned
1 Dec 2026
Published
1 Dec 2026
npm package Publisher: aslakhellesoy, rexxars
1,163 Stars
271 Forks
8 Versions
440.3M Downloads
TypeScript Repo language

Scan summary

eventsource was last scanned on 1 Dec 2026 at version 5.1.7. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 8 versions; the latest 2 were published within 2 days (30 Nov and 1 Dec 2026).
  • Findings: No rules fired in version 5.1.7.
  • Downloads: 440,256,635 downloads.

Versions

8 versions published
Versions and the rules that fired in each
VersionPublishedStatus
5.1.7 LATEST 1 Dec 2026 No rules fired
5.1.6 30 Nov 2026 No rules fired
5.1.5 8 Nov 2026 No rules fired
5.1.4 28 Oct 2026 Not shown
5.1.3 14 Oct 2026 Not shown

No rules fired in 5.1.7

Findings

Findings for v5.1.7. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 5.1.7; other versions have their own rules, not their own score.

Known vulnerabilities

1 CVE · last 12 May 2022

1 CRITICAL 0 HIGH 0 MEDIUM 0 LOW

Versions

  • ≥ 2.0.2
  • ≥ 2.0.0, < 2.0.2 1 CRITICAL
  • ≥ 1.1.1, < 2.0.0
  • < 1.1.1 1 CRITICAL

Vulnerabilities

  • CVE-2022-1650 Critical 12 May 2022 eventsource: Exposure of Sensitive Information Fixed in 1.1.1, 2.0.2

README

The publisher’s own README, as collected from the registry.

eventsource

npm versionnpm bundle sizenpm weekly downloads

WhatWG/W3C-compatible server-sent events/eventsource client. The module attempts to implement an absolute minimal amount of features/changes beyond the specification.

If you're looking for a modern alternative with a less constrained API, check out the eventsource-client package.

Installation

npm install --save eventsource

Supported engines

  • Node.js >= 22.12
  • Chrome >= 84
  • Safari >= 15 (non-ASCII event ID limitation)
  • Firefox >= 105
  • Edge >= 84
  • Deno >= 2
  • Bun >= 1.1.23
  • Cloudflare Workers: partial

Basically, any environment that supports:

If you need to support runtimes without private class fields, methods and accessors, try the 4.x branch/version range.

If you need to support even older runtimes, try the 2.x branch/version range (note: 2.x branch is primarily targeted at Node.js, not browsers).

Usage

import {EventSource} from 'eventsource'

const es = new EventSource('https://my-server.com/sse')

/*
 * This will listen for events with the field `event: notice`.
 */
es.addEventListener('notice', (event) => {
  console.log(event.data)
})

/*
 * This will listen for events with the field `event: update`.
 */
es.addEventListener('update', (event) => {
  console.log(event.data)
})

/*
 * The event "message" is a special case, as it will capture events _without_ an
 * event field, as well as events that have the specific type `event: message`.
 * It will not trigger on any other event type.
 */
es.addEventListener('message', (event) => {
  console.log(event.data)
})

/**
 * To explicitly close the connection, call the `close` method.
 * This will prevent any reconnection from happening.
 */
setTimeout(() => {
  es.close()
}, 10_000)
TypeScript

Make sure you have configured your TSConfig so it matches the environment you are targetting. If you are targetting browsers, this would be dom:

{
  "compilerOptions": {
    "lib": ["dom"],
  },
}

If you're using Node.js, ensure you have @types/node installed (and it is version 22 or higher). Cloudflare workers have @cloudflare/workers-types etc.

The following errors are caused by targetting an environment that does not have the necessary types available:

error TS2304: Cannot find name 'Event'.
error TS2304: Cannot find name 'EventTarget'.
error TS2304: Cannot find name 'MessageEvent'.
Safari and WebKit

Safari/WebKit encodes non-ASCII Last-Event-ID header values as UTF-8 a second time, so the server receives a different ID on reconnect. This affects accented characters, currency symbols and emoji. Event data and MessageEvent.lastEventId retain their original Unicode values.

For the widest client compatibility, we recommend that servers use ASCII-only values in the event stream's id field. See WebKit's header encoding for the underlying behavior.

Cloudflare Workers

Cloudflare Workers require compatibilityDate: '2024-11-11' or later, and addEventListener() instead of the onmessage, onopen and onerror properties.

workerd's EventTarget dispatches on<type> handler properties itself, on top of the listener this module registers, so a handler assigned that way is called twice per event - and assigning null only removes one of the two registrations, so it does not unsubscribe (workerd#6022).

// Called twice per message on Cloudflare Workers
eventSource.onmessage = (event) => console.log(event.data)

// Use this instead
eventSource.addEventListener('message', (event) => console.log(event.data))

workerd also drops origin and lastEventId from the MessageEvent constructor. This module assigns them itself, so both are correct on Workers today; the workaround goes away once workerd#6995 lands.

Workers' native fetch encodes header values as UTF-8 itself. This module passes it the original event ID to avoid encoding twice. Custom fetch implementations receive a UTF-8 byte string; wrappers that forward to Workers' native fetch must decode Last-Event-ID back to Unicode first.

Migrating from v1 / v2

See MIGRATION.md for a detailed migration guide.

Extensions to the WhatWG/W3C API

Message and code properties on errors

The error event has a message and code property that can be used to get more information about the error. In the specification, the Event

es.addEventListener('error', (err) => {
  if (err.code === 401 || err.code === 403) {
    console.log('not authorized')
  }
})
Limit parser buffer size

The parser buffers up to 100 MB while waiting for a complete EventSource line. To change that limit, pass maxBufferSize in the constructor options:

const es = new EventSource('https://my-server.com/sse', {
  maxBufferSize: 10 * 1024 * 1024, // 10 MB
})

If the limit is exceeded, the connection fails and emits an error event, and will not reconnect. Prefer servers that emit smaller chunks or newlines more frequently over increasing this limit.

Specify fetch implementation

The EventSource constructor accepts an optional fetch property in the second argument that can be used to specify the fetch implementation to use.

This can be useful in environments where the global fetch function is not available - but it can also be used to alter the request/response behaviour.

Setting HTTP request headers
const es = new EventSource('https://my-server.com/sse', {
  fetch: (input, init) =>
    fetch(input, {
      ...init,
      headers: {
        ...init.headers,
        Authorization: 'Bearer myToken',
      },
    }),
})
HTTP/HTTPS proxy

Use a package like undici to add proxy support, either through environment variables or explicit configuration.

// npm install undici --save
import {fetch, EnvHttpProxyAgent} from 'undici'

const proxyAgent = new EnvHttpProxyAgent()

const es = new EventSource('https://my-server.com/sse', {
  fetch: (input, init) => fetch(input, {...init, dispatcher: proxyAgent}),
})
Using HTTP2

Use a package like undici that supports HTTP2.

// npm install undici --save
import {Agent, fetch} from 'undici'

const http2Dispatcher = new Agent({allowH2: true})

const es = new EventSource('https://my-server.com/sse', {
  fetch: (url, init) => fetch(url, {...init, dispatcher: http2Dispatcher}),
})
Allow unauthorized HTTPS requests

Use a package like undici for more control of fetch options through the use of an Agent.

// npm install undici --save
import {fetch, Agent} from 'undici'

const unsafeAgent = new Agent({
  connect: {
    rejectUnauthorized: false,
  },
})

await fetch('https://my-server.com/sse', {
  dispatcher: unsafeAgent,
})
Feature checking

For library authors, you may want to feature-check if an EventSource implementation supports passing a custom fetch implementation (such as this library does). We declare (from v4.1.0 and onwards) a non-enumerable symbol on the EventSource class to indicate this, named eventsource.supports-fetch-override. It can be used downstream such as:

function yourLibrary(options) {
  const OurEventSource = options.polyfills.EventSource || globalThis.EventSource

  if (OurEventSource && Symbol.for('eventsource.supports-fetch-override') in OurEventSource) {
    // We can safely assume this supports overriding/specifying `fetch`!
    const es = new OurEventSource('https://some.url', {
      fetch: (input, init) =>
        fetch(input, {
          ...init,
          headers: {
            ...(init.headers || {}),
            'x-some-header': 'foo',
          },
        }),
    })
    // …
  }
}

License

MIT-licensed. See LICENSE.

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm eventsource

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Plug and Pray: Your AI Agents Are Taking Orders From Strangers
Research

Plug and Pray: Your AI Agents Are Taking Orders From Strangers

Copy of Template Design OX Blog (1)
Research

Thousands Of GitHub Accounts Hijacked With wfx-loot CI Secret Stealing Malware Via GitHub Actions & npm

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Frame 2085668439 (1)
Group 1261154229