@bymax-one/nest-realtime 1.2.28 → 1.2.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,21 @@ Versioning is **not** strict [SemVer](https://semver.org/spec/v2.0.0.html) while
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.29] - 2026-11-21
11
+
12
+ ### Security
13
+
14
+ - **A `websocket.cors.origin` that is set to nothing no longer opens the server to every origin.** The module read `null` and `undefined` as an unset option and dropped them, so the block reached Socket.IO without an `origin` and the server answered `*`; Socket.IO itself answers no origin for either value. A host whose allowlist came from a missing environment variable (`origin: process.env.APP_ORIGIN`) therefore allowed every origin.
15
+
16
+ ### Changed
17
+
18
+ - **A present-but-nullish `websocket.cors.origin` is refused at boot.** `null`, `undefined` as a key of its own, and an environment variable that is missing are refused with `REALTIME_INVALID_OPTIONS`, naming `options.websocket.cors.origin`. A block with no `origin` key keeps the documented default, which answers `*`.
19
+ - **`websocket.cors.credentials` must be a boolean.** `'true'`, `'false'`, `1` and an object were ignored by Socket.IO, so credentials were silently off; they are refused with `REALTIME_INVALID_OPTIONS`.
20
+
21
+ #### Apply to a derived backend
22
+
23
+ A nullish `cors.origin` now refuses boot: set the allowlist, or remove the key to take the default. A `credentials` that is set to something other than `true` or `false` now refuses boot: write the boolean.
24
+
10
25
  ## [1.2.28] - 2026-11-21
11
26
 
12
27
  ### Documentation
@@ -1329,7 +1344,8 @@ First published release.
1329
1344
  rather than by the manual sweep that raised the NestJS floors — that sweep
1330
1345
  asked about NestJS and never put the same question to the other ten peers.
1331
1346
 
1332
- [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.28...HEAD
1347
+ [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.29...HEAD
1348
+ [1.2.29]: https://github.com/bymaxone/nest-realtime/compare/v1.2.28...v1.2.29
1333
1349
  [1.2.28]: https://github.com/bymaxone/nest-realtime/compare/v1.2.27...v1.2.28
1334
1350
  [1.2.27]: https://github.com/bymaxone/nest-realtime/compare/v1.2.26...v1.2.27
1335
1351
  [1.2.26]: https://github.com/bymaxone/nest-realtime/compare/v1.2.25...v1.2.26
package/README.md CHANGED
@@ -631,7 +631,7 @@ When integrating `@bymax-one/nest-realtime` in production, verify each of the fo
631
631
  - `tenantId` is derived from the authenticated result, never from a query parameter or request body
632
632
  - Tickets are single-use and short-lived; `consume()` must be atomic under concurrency
633
633
  - `websocket.cors.origin` is an explicit allowlist, not `true`, in any browser-facing deployment
634
- - `websocket.cors` with `credentials: true` also sets `origin`: a block with no `origin` key leaves Socket.IO's default, which answers `*`, and browsers refuse `*` together with credentials
634
+ - `websocket.cors` with `credentials: true` also sets `origin`: a block with no `origin` key leaves Socket.IO's default, which answers `*`, and browsers refuse `*` together with credentials. An `origin` that is set to `null` or `undefined`, as when its environment variable is missing, is refused at boot, and `credentials` must be a boolean
635
635
  - `maxConnectionsPerUser` is left at its default of `5` (or set) for WebSocket if clients are untrusted — `0` makes it unlimited
636
636
  - Reserved event names are not reused for application events (see the [catalog](#reserved-events))
637
637
 
@@ -113,11 +113,12 @@ var GROUPS = {
113
113
  websocket: WEBSOCKET_KEYS,
114
114
  reauthenticationPolicy: REAUTHENTICATION_KEYS
115
115
  };
116
- function readSet(source, known) {
116
+ function readSet(source, known, keepWhenSet) {
117
117
  const kept = {};
118
118
  for (const key of /* @__PURE__ */ new Set([...Object.keys(source), ...Object.keys(known)])) {
119
119
  const value = source[key];
120
120
  if (value !== void 0 && value !== null) kept[key] = value;
121
+ else if (key === keepWhenSet && (value === null || key in source)) kept[key] = value;
121
122
  }
122
123
  return kept;
123
124
  }
@@ -131,7 +132,7 @@ function dropUnset(options) {
131
132
  if (isPlainObject(websocket)) {
132
133
  const cors = websocket.cors;
133
134
  if (typeof cors === "object" && cors !== null && !Array.isArray(cors)) {
134
- websocket.cors = readSet(cors, CORS_KEYS);
135
+ websocket.cors = readSet(cors, CORS_KEYS, "origin");
135
136
  }
136
137
  }
137
138
  return kept;
@@ -310,6 +311,19 @@ function validateShapes(options) {
310
311
  assertBoolean("sse.emitConnectionEvent", options.sse?.emitConnectionEvent);
311
312
  assertBoolean("websocket.emitConnectionEvent", options.websocket?.emitConnectionEvent);
312
313
  assertSseEndpoint("sse.endpoint", options.sse?.endpoint);
314
+ assertCors(options.websocket?.cors);
315
+ }
316
+ function assertCors(cors) {
317
+ if (typeof cors !== "object" || cors === null) return;
318
+ const block = cors;
319
+ if ("origin" in block && (block.origin === null || block.origin === void 0)) {
320
+ refuse(
321
+ "websocket.cors.origin",
322
+ "a string, a RegExp, a function, an array or false",
323
+ block.origin
324
+ );
325
+ }
326
+ assertBoolean("websocket.cors.credentials", block.credentials);
313
327
  }
314
328
  function assertExtraProviders(value) {
315
329
  if (value === void 0 || value === null) return;
@@ -111,11 +111,12 @@ var GROUPS = {
111
111
  websocket: WEBSOCKET_KEYS,
112
112
  reauthenticationPolicy: REAUTHENTICATION_KEYS
113
113
  };
114
- function readSet(source, known) {
114
+ function readSet(source, known, keepWhenSet) {
115
115
  const kept = {};
116
116
  for (const key of /* @__PURE__ */ new Set([...Object.keys(source), ...Object.keys(known)])) {
117
117
  const value = source[key];
118
118
  if (value !== void 0 && value !== null) kept[key] = value;
119
+ else if (key === keepWhenSet && (value === null || key in source)) kept[key] = value;
119
120
  }
120
121
  return kept;
121
122
  }
@@ -129,7 +130,7 @@ function dropUnset(options) {
129
130
  if (isPlainObject(websocket)) {
130
131
  const cors = websocket.cors;
131
132
  if (typeof cors === "object" && cors !== null && !Array.isArray(cors)) {
132
- websocket.cors = readSet(cors, CORS_KEYS);
133
+ websocket.cors = readSet(cors, CORS_KEYS, "origin");
133
134
  }
134
135
  }
135
136
  return kept;
@@ -308,6 +309,19 @@ function validateShapes(options) {
308
309
  assertBoolean("sse.emitConnectionEvent", options.sse?.emitConnectionEvent);
309
310
  assertBoolean("websocket.emitConnectionEvent", options.websocket?.emitConnectionEvent);
310
311
  assertSseEndpoint("sse.endpoint", options.sse?.endpoint);
312
+ assertCors(options.websocket?.cors);
313
+ }
314
+ function assertCors(cors) {
315
+ if (typeof cors !== "object" || cors === null) return;
316
+ const block = cors;
317
+ if ("origin" in block && (block.origin === null || block.origin === void 0)) {
318
+ refuse(
319
+ "websocket.cors.origin",
320
+ "a string, a RegExp, a function, an array or false",
321
+ block.origin
322
+ );
323
+ }
324
+ assertBoolean("websocket.cors.credentials", block.credentials);
311
325
  }
312
326
  function assertExtraProviders(value) {
313
327
  if (value === void 0 || value === null) return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-realtime",
3
- "version": "1.2.28",
3
+ "version": "1.2.29",
4
4
  "description": "Realtime backend → frontend communication for NestJS — dual-transport SSE (default) and WebSocket (opt-in) with a unified server-side API.",
5
5
  "author": "Bymax One <support@bymax.one>",
6
6
  "license": "MIT",