Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependency socket.io to v4 #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mend-for-github-com[bot]
Copy link

@mend-for-github-com mend-for-github-com bot commented May 22, 2024

This PR contains the following updates:

Package Type Update Change
socket.io (source) dependencies major ^3.1.0 -> ^4.6.2

By merging this PR, the below vulnerabilities will be automatically resolved:

Severity CVSS Score CVE
High High 7.5 CVE-2024-37890
High High 7.3 CVE-2023-32695
High High 7.3 CVE-2024-38355
High High 7.1 CVE-2022-41940

Release Notes

socketio/socket.io (socket.io)

v4.6.2

Compare Source

Bug Fixes
Links

v4.6.1

Compare Source

Bug Fixes
  • properly handle manually created dynamic namespaces (0d0a7a2)
  • types: fix nodenext module resolution compatibility (#​4625) (d0b22c6)
Links

v4.6.0

Compare Source

Bug Fixes
  • add timeout method to remote socket (#​4558) (0c0eb00)
  • typings: properly type emits with timeout (f3ada7d)
Features
Promise-based acknowledgements

This commit adds some syntactic sugar around acknowledgements:

  • emitWithAck()
try {
  const responses = await io.timeout(1000).emitWithAck("some-event");
  console.log(responses); // one response per client
} catch (e) {
  // some clients did not acknowledge the event in the given delay
}

io.on("connection", async (socket) => {
    // without timeout
  const response = await socket.emitWithAck("hello", "world");

  // with a specific timeout
  try {
    const response = await socket.timeout(1000).emitWithAck("hello", "world");
  } catch (err) {
    // the client did not acknowledge the event in the given delay
  }
});
  • serverSideEmitWithAck()
try {
  const responses = await io.timeout(1000).serverSideEmitWithAck("some-event");
  console.log(responses); // one response per server (except itself)
} catch (e) {
  // some servers did not acknowledge the event in the given delay
}

Added in 184f3cf.

Connection state recovery

This feature allows a client to reconnect after a temporary disconnection and restore its state:

  • id
  • rooms
  • data
  • missed packets

Usage:

import { Server } from "socket.io";

const io = new Server({
  connectionStateRecovery: {
    // default values
    maxDisconnectionDuration: 2 * 60 * 1000,
    skipMiddlewares: true,
  },
});

io.on("connection", (socket) => {
  console.log(socket.recovered); // whether the state was recovered or not
});

Here's how it works:

  • the server sends a session ID during the handshake (which is different from the current id attribute, which is public and can be freely shared)
  • the server also includes an offset in each packet (added at the end of the data array, for backward compatibility)
  • upon temporary disconnection, the server stores the client state for a given delay (implemented at the adapter level)
  • upon reconnection, the client sends both the session ID and the last offset it has processed, and the server tries to restore the state

The in-memory adapter already supports this feature, and we will soon update the Postgres and MongoDB adapters. We will also create a new adapter based on Redis Streams, which will support this feature.

Added in 54d5ee0.

Compatibility (for real) with Express middlewares

This feature implements middlewares at the Engine.IO level, because Socket.IO middlewares are meant for namespace authorization and are not executed during a classic HTTP request/response cycle.

Syntax:

io.engine.use((req, res, next) => {
  // do something

  next();
});

// with express-session
import session from "express-session";

io.engine.use(session({
  secret: "keyboard cat",
  resave: false,
  saveUninitialized: true,
  cookie: { secure: true }
}));

// with helmet
import helmet from "helmet";

io.engine.use(helmet());

A workaround was possible by using the allowRequest option and the "headers" event, but this feels way cleaner and works with upgrade requests too.

Added in 24786e7.

Error details in the disconnecting and disconnect events

The disconnect event will now contain additional details about the disconnection reason.

io.on("connection", (socket) => {
  socket.on("disconnect", (reason, description) => {
    console.log(description);
  });
});

Added in 8aa9499.

Automatic removal of empty child namespaces

This commit adds a new option, "cleanupEmptyChildNamespaces". With this option enabled (disabled by default), when a socket disconnects from a dynamic namespace and if there are no other sockets connected to it then the namespace will be cleaned up and its adapter will be closed.

import { createServer } from "node:http";
import { Server } from "socket.io";

const httpServer = createServer();
const io = new Server(httpServer, {
  cleanupEmptyChildNamespaces: true
});

Added in 5d9220b.

A new "addTrailingSlash" option

The trailing slash which was added by default can now be disabled:

import { createServer } from "node:http";
import { Server } from "socket.io";

const httpServer = createServer();
const io = new Server(httpServer, {
  addTrailingSlash: false
});

In the example above, the clients can omit the trailing slash and use /socket.io instead of /socket.io/.

Added in d0fd474.

Performance Improvements
  • precompute the WebSocket frames when broadcasting (da2b542)
Links:

v4.5.4

Compare Source

This release contains a bump of:

Links:

v4.5.3

Compare Source

Bug Fixes
  • typings: accept an HTTP2 server in the constructor (d3d0a2d)
  • typings: apply types to "io.timeout(...).emit()" calls (e357daf)
Links:

v4.5.2

Compare Source

Bug Fixes
  • prevent the socket from joining a room after disconnection (18f3fda)
  • uws: prevent the server from crashing after upgrade (ba497ee)
Links:

v4.5.1

Compare Source

Bug Fixes
  • forward the local flag to the adapter when using fetchSockets() (30430f0)
  • typings: add HTTPS server to accepted types (#​4351) (9b43c91)
Links:

v4.5.0

Compare Source

Bug Fixes
Features
  • add support for catch-all listeners for outgoing packets (531104d)

This is similar to onAny(), but for outgoing packets.

Syntax:

socket.onAnyOutgoing((event, ...args) => {
  console.log(event);
});
  • broadcast and expect multiple acks (8b20457)

Syntax:

io.timeout(1000).emit("some-event", (err, responses) => {
  // ...
});
  • add the "maxPayload" field in the handshake details (088dcb4)

So that clients in HTTP long-polling can decide how many packets they have to send to stay under the maxHttpBufferSize
value.

This is a backward compatible change which should not mandate a new major revision of the protocol (we stay in v4), as
we only add a field in the JSON-encoded handshake data:

0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000}
Links:

v4.4.1

Compare Source

Bug Fixes
Links:

v4.4.0

Compare Source

Bug Fixes
  • only set 'connected' to true after middleware execution (02b0f73)
Features
  • add an implementation based on uWebSockets.js (c0d8c5a)
const { App } = require("uWebSockets.js");
const { Server } = require("socket.io");

const app = new App();
const io = new Server();

io.attachApp(app);

io.on("connection", (socket) => {
  // ...
});

app.listen(3000, (token) => {
  if (!token) {
    console.warn("port already in use");
  }
});
socket.timeout(5000).emit("my-event", (err) => {
  if (err) {
    // the client did not acknowledge the event in the given delay
  }
});
interface SocketData {
  name: string;
  age: number;
}

const io = new Server<ClientToServerEvents, ServerToClientEvents, InterServerEvents, SocketData>();

io.on("connection", (socket) => {
  socket.data.name = "john";
  socket.data.age = 42;
});
Links:

v4.3.2

Compare Source

Bug Fixes
Links:

v4.3.1

Compare Source

Bug Fixes
Links:

v4.3.0

Compare Source

For this release, most of the work was done on the client side, see here.

Bug Fixes
  • typings: add name field to cookie option (#​4099) (033c5d3)
  • send volatile packets with binary attachments (dc81fcf)
Features
Links:

v4.2.0

Compare Source

Bug Fixes
  • typings: allow async listener in typed events (ccfd8ca)
Features
  • ignore the query string when serving client JavaScript (#​4024) (24fee27)
Links:

v4.1.3

Compare Source

Bug Fixes
  • fix io.except() method (94e27cd)
  • remove x-sourcemap header (a4dffc6)
Links:

v4.1.2

Compare Source

Bug Fixes
  • typings: ensure compatibility with TypeScript 3.x (0cb6ac9)
  • ensure compatibility with previous versions of the adapter (a2cf248)
Links:

v4.1.1

Compare Source

Bug Fixes
  • typings: properly type server-side events (b84ed1e)
  • typings: properly type the adapter attribute (891b187)
Links:

v4.1.0

Compare Source

Blog post: https://socket.io/blog/socket-io-4-1-0/

Features
  • add support for inter-server communication (93cce05)
  • notify upon namespace creation (499c892)
  • add a "connection_error" event (7096e98, from engine.io)
  • add the "initial_headers" and "headers" events (2527543, from engine.io)
Links:

v4.0.2

Compare Source

Bug Fixes
  • typings: make "engine" attribute public (b81ce4c)
  • properly export the Socket class (d65b6ee)
Links:

v4.0.1

Compare Source

Bug Fixes
Links:

v4.0.0

Compare Source

Blog post: https://socket.io/blog/socket-io-4-release/
Migration guide: https://socket.io/docs/v3/migrating-from-3-x-to-4-0/

Bug Fixes
  • make io.to(...) immutable (ac9e8ca)
Features
BREAKING CHANGES
  • io.to(...) now returns an immutable operator

Previously, broadcasting to a given room (by calling io.to()) would mutate the io instance, which could lead to surprising behaviors, like:

io.to("room1");
io.to("room2").emit(/* ... */); // also sent to room1

// or with async/await
io.to("room3").emit("details", await fetchDetails()); // random behavior: maybe in room3, maybe to all clients

Calling io.to() (or any other broadcast modifier) will now return an immutable instance.

Links:

v3.1.2

Compare Source

Bug Fixes
  • ignore packets received after disconnection (494c64e)
Links:

v3.1.1

Compare Source

Bug Fixes
  • properly parse the CONNECT packet in v2 compatibility mode (6f4bd7f)
  • typings: add return types and general-case overload signatures (#​3776) (9e8f288)
  • typings: update the types of "query", "auth" and "headers" (4f2e9a7)
Links:

  • If you want to rebase/retry this PR, check this box

@mend-for-github-com mend-for-github-com bot added the security fix Security fix generated by Mend label May 22, 2024
@rafikmojr
Copy link

rafikmojr commented May 22, 2024

Logo
Checkmarx One – Scan Summary & Detailsb344e643-2258-47a5-85c3-64d290159ce1

Fixed Issues

Severity Issue Source File / Package
HIGH CVE-2024-38355 Npm-socket.io-3.1.2
MEDIUM CVE-2022-41940 Npm-engine.io-4.1.2

@mend-for-github-com mend-for-github-com bot force-pushed the whitesource-remediate/socket.io-4.x branch from 8646b78 to dff4190 Compare June 20, 2024 12:05
Copy link

socket-security bot commented Jun 20, 2024

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/jasmine-core@3.9.0 filesystem 0 394 kB sgravrock
npm/jasmine-reporters@2.5.2 environment, filesystem, network +1 160 kB bloveridge
npm/jasmine@3.99.0 None 0 48.5 kB sgravrock
npm/jest@26.6.3 None 0 4.34 kB simenb
npm/js-yaml@3.14.1 eval Transitive: environment, filesystem +2 777 kB vitaly
npm/jsonwebtoken@0.4.0 None +1 39.4 kB woloski
npm/jssha@3.3.1 None 0 624 kB caligatio
npm/juicy-chat-bot@0.8.0 filesystem, unsafe 0 61.3 kB bkimminich
npm/libxmljs2@0.33.0 None +1 7.65 MB marudor
npm/marsdb@0.6.11 eval 0 1.03 MB a.artemev
npm/median@0.0.2 None 0 3.41 kB lafikl
npm/mocha@8.4.0 environment, eval, filesystem +31 4.06 MB juergba
npm/morgan@1.10.0 eval Transitive: environment +3 70.6 kB dougwilson
npm/multer@1.4.5-lts.1 filesystem Transitive: environment +7 312 kB linusu
npm/node-fetch@2.7.0 network 0 162 kB node-fetch-bot
npm/node-pre-gyp@0.15.0 environment, filesystem Transitive: shell +6 267 kB nicolasnoble
npm/notevil@1.3.3 None +1 348 kB mmckegg
npm/nyc@15.1.0 environment, filesystem, unsafe +23 574 kB coreyfarrell
npm/on-finished@2.4.1 unsafe +1 19.9 kB dougwilson
npm/otplib@12.0.1 None 0 25.6 kB geraldyeo
npm/pdfkit@0.11.0 filesystem 0 4.78 MB devongovett
npm/portscanner@2.2.0 network +1 1.44 MB laggingreflex
npm/prom-client@14.2.0 filesystem, network, unsafe 0 110 kB simenb
npm/pug@3.0.3 environment, eval, filesystem 0 59.7 kB pug-bot
npm/replace@1.2.2 eval, filesystem Transitive: environment +24 914 kB almaclaine
npm/request@2.88.2 environment, filesystem, network +25 1.73 MB mikeal
npm/sanitize-filename@1.6.3 None 0 16.8 kB parshap
npm/sanitize-html@1.4.2 Transitive: network +3 1.55 MB boutell
npm/semver@7.6.3 None 0 95.8 kB npm-cli-ops
npm/sequelize@6.37.3 filesystem Transitive: environment +4 4.52 MB sdepold
npm/serve-index@1.9.1 filesystem, network Transitive: environment, eval +13 452 kB dougwilson
npm/shelljs@0.8.5 environment, filesystem 0 212 kB nfischer
npm/sinon-chai@3.7.0 None 0 16.8 kB simondel
npm/sinon@11.1.2 environment, eval +2 4.9 MB mrgnrdrck
npm/smallest@1.0.1 None 0 2.39 kB bendrucker
npm/socket.io-client@3.1.3 Transitive: environment +3 1.04 MB darrachequesne
npm/socket.io@4.8.0 filesystem, network Transitive: environment +6 1.78 MB darrachequesne
npm/source-map-support@0.5.21 filesystem +2 895 kB linusu
npm/sqlite3@5.1.7 None 0 3.35 MB daniellockyer
npm/svg-captcha@1.4.0 None 0 102 kB lichaozhy
npm/swagger-ui-express@5.0.1 None 0 24 kB scottie1984
npm/ts-jest@26.5.6 environment, filesystem +7 2.03 MB kul
npm/ts-node-dev@1.1.8 environment, filesystem, shell +10 386 kB whitecolor
npm/ts-node@10.9.2 environment, filesystem, unsafe +5 1.66 MB blakeembrey
npm/typescript@4.6.4 None 0 64.7 MB typescript-bot
npm/unzipper@0.9.15 filesystem Transitive: environment, eval, unsafe +3 859 kB zjonsson
npm/web3@4.13.0 None 0 3.4 MB luu-alex
npm/winston@3.14.2 filesystem, network Transitive: environment +5 1.16 MB dabh
npm/yaml-schema-validator@1.2.3 filesystem Transitive: environment +7 108 kB ketan-saxena
npm/z85@0.0.2 None 0 9.72 kB msealand

View full report↗︎

@mend-for-github-com mend-for-github-com bot force-pushed the whitesource-remediate/socket.io-4.x branch from dff4190 to b375fe0 Compare September 23, 2024 12:57
Copy link

🚨 Potential security issues detected. Learn more about Socket for GitHub ↗︎

To accept the risk, merge this PR and you will not be notified again.

Alert Package NoteSourceCI
Critical CVE npm/marsdb@0.6.11 ⚠︎

View full report↗︎

Next steps

What is a critical CVE?

Contains a Critical Common Vulnerability and Exposure (CVE).

Remove or replace dependencies that include known critical CVEs. Consumers can use dependency overrides or npm audit fix --force to remove vulnerable dependencies.

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

  • @SocketSecurity ignore npm/marsdb@0.6.11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security fix Security fix generated by Mend
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant