@bymax-one/nest-realtime 1.2.27 → 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,12 +7,37 @@ 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
+
25
+ ## [1.2.28] - 2026-11-21
26
+
27
+ ### Documentation
28
+
29
+ - **The README states what a `tenantResolver`'s promise cannot have handled, and what `websocket.cors` does without an `origin`.** A promise the resolver returns has its rejection absorbed except in the cases the 1.2.27 entry lists. A `cors` block with no `origin` key leaves Socket.IO's own default, which answers `*`; browsers refuse `*` together with `credentials: true`, so the origin is the host's to set.
30
+
31
+ #### Apply to a derived backend
32
+
33
+ None. No code changed.
34
+
10
35
  ## [1.2.27] - 2026-11-21
11
36
 
12
37
  ### Fixed
13
38
 
14
39
  - **`roles` is read with a bound, and a `roles` that cannot be read is refused in every shape.** A revoked proxy over an array made `Array.isArray` throw a raw `TypeError` before the guard; the check now sits inside it, so the refusal is `REALTIME_AUTH_FAILED` with the host's error as the cause. The copy stops at 1,024 roles: an authentication result with more is refused with `REALTIME_AUTH_FAILED`, and an iterator that never ends is no longer read to exhaustion. The bound is there to cap the cost of the copy, not to say how many roles a user may hold; exactly 1,024 is admitted.
15
- - **The rejection of a promise a `tenantResolver` returns is absorbed whatever kind of promise it is.** The check was `instanceof Promise`, which a promise from another realm fails, and the handler was the promise's own `catch`, which a subclass can override; either left an unhandled rejection that ended the process. The handler is now attached with the intrinsic `then`, which accepts a real promise of any realm and refuses every other value without reading a property of it. A proxy over a promise, whose own methods the intrinsic cannot reach, is given its own `catch` when the intrinsic refuses it, so its rejection is absorbed too; a thenable that is not a promise is still never asked for its `then`. A promise whose `constructor` or species cannot be read cannot be given a handler by either path.
40
+ - **The rejection of a promise a `tenantResolver` returns is absorbed whatever kind of promise it is.** The check was `instanceof Promise`, which a promise from another realm fails, and the handler was the promise's own `catch`, which a subclass can override; either left an unhandled rejection that ended the process. The handler is now attached with the intrinsic `then`, which accepts a real promise of any realm and refuses every other value without reading a property of it. A proxy over a promise whose `get` trap binds the promise's methods to it is given its own `catch` when the intrinsic refuses it, so its rejection is absorbed too; a thenable that is not a promise is still never asked for its `then`. These cannot be given a handler by either path, and their rejection is left to the process: a proxy with no traps, a proxy whose `catch` trap throws, and a promise whose species lookup throws (see the README for which values do that).
16
41
 
17
42
  ### Documentation
18
43
 
@@ -1319,7 +1344,9 @@ First published release.
1319
1344
  rather than by the manual sweep that raised the NestJS floors — that sweep
1320
1345
  asked about NestJS and never put the same question to the other ten peers.
1321
1346
 
1322
- [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.27...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
1349
+ [1.2.28]: https://github.com/bymaxone/nest-realtime/compare/v1.2.27...v1.2.28
1323
1350
  [1.2.27]: https://github.com/bymaxone/nest-realtime/compare/v1.2.26...v1.2.27
1324
1351
  [1.2.26]: https://github.com/bymaxone/nest-realtime/compare/v1.2.25...v1.2.26
1325
1352
  [1.2.25]: https://github.com/bymaxone/nest-realtime/compare/v1.2.24...v1.2.25
package/README.md CHANGED
@@ -631,6 +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. 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
634
635
  - `maxConnectionsPerUser` is left at its default of `5` (or set) for WebSocket if clients are untrusted — `0` makes it unlimited
635
636
  - Reserved event names are not reused for application events (see the [catalog](#reserved-events))
636
637
 
@@ -779,6 +780,8 @@ To place a connection in no tenant, **omit `tenantId`**. The runtime also accept
779
780
 
780
781
  `tenantResolver` cannot clear a tenant. It receives the authenticator's own result, the object it returned and not a copy, so everything on it works as it does for the authenticator's code. The library keeps its own record of `userId`, `tenantId`, `roles`, `rooms` and `metadata`, built by name before the resolver runs and read the way JavaScript reads a property, so a field that a class default, `Object.create` or an accessor on the prototype supplies counts. What a resolver writes to the result does not change that record, which is another object; `roles`, `rooms` and `metadata` are shared, so a write inside them changes what the library keeps. Resolution is `tenantResolver?.(auth) ?? tenantId`, where `tenantId` is what the result held before the resolver ran, so a resolver returning `undefined` or `null` means "no opinion" and the authenticator's tenant stays. Decide the absent case in the authenticator.
781
782
 
783
+ A resolver that returns a promise is refused as a blank tenant, and the promise's rejection is handled so it cannot end the process. That handling reaches a native promise from any realm, a subclass, a promise with a `then` of its own, and a proxy whose `get` trap binds the promise's methods. It cannot reach a proxy with no traps, a proxy whose `catch` trap throws, or a promise whose species lookup throws, which is a `constructor` that is neither an object nor `undefined`, a `Symbol.species` that is neither a constructor nor `null` or `undefined`, or a getter for either that throws: `then` and `catch` run that lookup before attaching a handler, so such a promise's rejection is left to the process. A thenable that is not a promise is never asked for its `then`. Return a value from a resolver, not a promise.
784
+
782
785
  #### Carrying handshake context into the hooks
783
786
 
784
787
  `AuthenticationResult.metadata` is a free-form bag the library carries verbatim: it reaches
@@ -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.27",
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",