@bymax-one/nest-realtime 1.2.25 → 1.2.26

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,18 @@ Versioning is **not** strict [SemVer](https://semver.org/spec/v2.0.0.html) while
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.2.26] - 2026-11-21
11
+
12
+ ### Fixed
13
+
14
+ - **An origin allowlist in `websocket.cors` is no longer dropped when it is defined as a class getter, a non-enumerable property or a prototype property.** The block was copied by its own enumerable keys, so `origin` went missing, Socket.IO fell back to its default and answered every origin with `Access-Control-Allow-Origin: *`. The block is now read by the names of `CorsConfig` whenever it is a non-array object, however it reports its type: a block with a `Symbol.toStringTag`, or a strict proxy, is read the same way. A block whose names cannot be read is refused with `REALTIME_INVALID_OPTIONS` and the host's error as the cause, never answered with a wildcard.
15
+ - **`roles` whose read throws is refused at admission.** A proxy or getter on `roles` was first read when the connection event or a hook needed it, so the host's error reached the framework raw. The array is now read once at admission into a frozen copy, and a read that throws is refused with `REALTIME_AUTH_FAILED` and the host's error as the cause. A `roles` value that is not an array is left as it is.
16
+ - **An `async` `tenantResolver` no longer leaves an unhandled rejection.** The resolver is synchronous; a promise is refused as a tenant that is not a string, and its rejection is now absorbed.
17
+
18
+ #### Apply to a derived backend
19
+
20
+ Nothing to change. A host that defined `websocket.cors.origin` as a getter, non-enumerable or on a prototype now gets the allowlist it wrote; check that it is the list you intend, since until now such a server answered every origin.
21
+
10
22
  ## [1.2.25] - 2026-11-21
11
23
 
12
24
  ### Fixed
@@ -1286,7 +1298,8 @@ First published release.
1286
1298
  rather than by the manual sweep that raised the NestJS floors — that sweep
1287
1299
  asked about NestJS and never put the same question to the other ten peers.
1288
1300
 
1289
- [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.25...HEAD
1301
+ [Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.26...HEAD
1302
+ [1.2.26]: https://github.com/bymaxone/nest-realtime/compare/v1.2.25...v1.2.26
1290
1303
  [1.2.25]: https://github.com/bymaxone/nest-realtime/compare/v1.2.24...v1.2.25
1291
1304
  [1.2.24]: https://github.com/bymaxone/nest-realtime/compare/v1.2.23...v1.2.24
1292
1305
  [1.2.23]: https://github.com/bymaxone/nest-realtime/compare/v1.2.22...v1.2.23
package/README.md CHANGED
@@ -638,16 +638,16 @@ When integrating `@bymax-one/nest-realtime` in production, verify each of the fo
638
638
 
639
639
  ## 🛡️ Security Table
640
640
 
641
- | Layer | Implementation |
642
- | --------------------- | -------------------------------------------------------------------------------------------------- |
643
- | Credential validation | Delegated entirely to your `IConnectionAuthenticator` |
644
- | Auth library imports | None: an ESLint rule fails lint on a string literal naming an auth package in `src` |
645
- | Tenant isolation | Room-scoped (`tenant:{id}`), resolved from the authenticated result |
646
- | Connection revocation | `disconnect(connectionId)`, cross-instance; rejects if it cannot reach it |
647
- | Credential expiry | Interval re-authentication; a failure drops the connection, after an event if `onFailure: 'event'` |
648
- | Connection flooding | FIFO eviction per user: oldest closed, new admitted, never a 429 |
649
- | SSE transport headers | `X-Accel-Buffering: no` and `Cache-Control: no-cache, no-transform` |
650
- | WebSocket origin | Explicit `cors` config passed straight to Socket.IO |
641
+ | Layer | Implementation |
642
+ | --------------------- | ----------------------------------------------------------------------------------------------------- |
643
+ | Credential validation | Delegated entirely to your `IConnectionAuthenticator` |
644
+ | Auth library imports | None: an ESLint rule fails lint on a string literal naming an auth package in `src` |
645
+ | Tenant isolation | Room-scoped (`tenant:{id}`), resolved from the authenticated result |
646
+ | Connection revocation | `disconnect(connectionId)`, cross-instance; rejects if it cannot reach it |
647
+ | Credential expiry | Interval re-authentication; a failure drops the connection, after an event if `onFailure: 'event'` |
648
+ | Connection flooding | FIFO eviction per user: oldest closed, new admitted, never a 429 |
649
+ | SSE transport headers | `X-Accel-Buffering: no` and `Cache-Control: no-cache, no-transform` |
650
+ | WebSocket origin | Explicit `cors` config: `origin`, `credentials` and `methods` are read by name and given to Socket.IO |
651
651
 
652
652
  ---
653
653
 
@@ -79,6 +79,11 @@ var WEBSOCKET_KEYS = {
79
79
  emitConnectionEvent: true,
80
80
  redisAdapter: true
81
81
  };
82
+ var CORS_KEYS = {
83
+ origin: true,
84
+ credentials: true,
85
+ methods: true
86
+ };
82
87
  var REAUTHENTICATION_KEYS = {
83
88
  intervalSeconds: true,
84
89
  onFailure: true,
@@ -122,6 +127,13 @@ function dropUnset(options) {
122
127
  const value = kept[group];
123
128
  if (isPlainObject(value)) kept[group] = readSet(value, keys);
124
129
  }
130
+ const websocket = kept.websocket;
131
+ if (isPlainObject(websocket)) {
132
+ const cors = websocket.cors;
133
+ if (typeof cors === "object" && cors !== null && !Array.isArray(cors)) {
134
+ websocket.cors = readSet(cors, CORS_KEYS);
135
+ }
136
+ }
125
137
  return kept;
126
138
  }
127
139
 
@@ -854,9 +866,23 @@ function refuse2(detail) {
854
866
  `the authenticator returned rooms that are not valid: ${detail}. Fix the authenticator; the limits are bounds against abuse and apply to this field only.`
855
867
  );
856
868
  }
869
+ function admitRoles(roles) {
870
+ if (!Array.isArray(roles)) return roles;
871
+ try {
872
+ return Object.freeze([...roles]);
873
+ } catch (error) {
874
+ throw realtimeError(
875
+ REALTIME_ERROR_CODES.AUTH_FAILED,
876
+ "the authenticator returned roles that could not be read: a getter or a proxy on them throws",
877
+ { cause: error }
878
+ );
879
+ }
880
+ }
857
881
  function admitRooms(auth) {
882
+ const roles = admitRoles(auth.roles);
858
883
  const { rooms } = auth;
859
- if (rooms === void 0) return auth;
884
+ const kept = roles === auth.roles ? auth : { ...auth, roles };
885
+ if (rooms === void 0) return kept;
860
886
  if (!Array.isArray(rooms)) refuse2("`rooms` is not an array");
861
887
  const admitted = [];
862
888
  for (const room of rooms) {
@@ -877,7 +903,7 @@ function admitRooms(auth) {
877
903
  const reserved = reservedRoomPrefix(room);
878
904
  if (reserved !== void 0) refuse2(`a room name starts with the reserved prefix "${reserved}"`);
879
905
  }
880
- return { ...auth, rooms: Object.freeze(admitted) };
906
+ return { ...kept, rooms: Object.freeze(admitted) };
881
907
  }
882
908
 
883
909
  // src/server/utils/assert-identity.ts
@@ -888,6 +914,7 @@ function resolveAuthTenant(options, auth) {
888
914
  const own = auth.tenantId;
889
915
  const kept = keepByName(auth);
890
916
  const resolved = options.tenantResolver?.(auth) ?? own;
917
+ if (resolved instanceof Promise) resolved.catch(() => void 0);
891
918
  if (resolved === void 0 || resolved === null) return kept;
892
919
  return { ...kept, tenantId: resolved };
893
920
  }
@@ -2187,7 +2187,7 @@ declare class RedisOfflineQueue implements IOfflineQueueStorage {
2187
2187
  *
2188
2188
  * @param options - The module options, read for an optional `tenantResolver`.
2189
2189
  * @param auth - The authentication result the consumer's authenticator returned.
2190
- * @returns The same result with `tenantId` resolved, or absent when there is none.
2190
+ * @returns A copy of the result with `tenantId` resolved, or absent when there is none.
2191
2191
  */
2192
2192
  declare function resolveAuthTenant(options: Pick<BymaxRealtimeModuleOptions, 'tenantResolver'>, auth: AuthenticationResult): AuthenticationResult;
2193
2193
  /**
@@ -2227,9 +2227,9 @@ declare function assertIdentityIsNotBlank(auth: AuthenticationResult): void;
2227
2227
  * await, so reading the original there would join whatever it holds by then.
2228
2228
  *
2229
2229
  * @param auth - The resolved authentication result.
2230
- * @returns `auth` itself when it has no `rooms`; otherwise a result with the same fields and a
2231
- * frozen copy of its `rooms`.
2232
- * @throws Error carrying `REALTIME_AUTH_FAILED` when `rooms` is present and invalid.
2230
+ * @returns `auth` itself when it has no `rooms` and no array `roles`; otherwise a result with the
2231
+ * same fields and a frozen copy of each of those it has.
2232
+ * @throws Error carrying `REALTIME_AUTH_FAILED` when `rooms` is present and invalid, or `roles` cannot be read.
2233
2233
  */
2234
2234
  declare function admitRooms(auth: AuthenticationResult): AuthenticationResult;
2235
2235
 
@@ -2187,7 +2187,7 @@ declare class RedisOfflineQueue implements IOfflineQueueStorage {
2187
2187
  *
2188
2188
  * @param options - The module options, read for an optional `tenantResolver`.
2189
2189
  * @param auth - The authentication result the consumer's authenticator returned.
2190
- * @returns The same result with `tenantId` resolved, or absent when there is none.
2190
+ * @returns A copy of the result with `tenantId` resolved, or absent when there is none.
2191
2191
  */
2192
2192
  declare function resolveAuthTenant(options: Pick<BymaxRealtimeModuleOptions, 'tenantResolver'>, auth: AuthenticationResult): AuthenticationResult;
2193
2193
  /**
@@ -2227,9 +2227,9 @@ declare function assertIdentityIsNotBlank(auth: AuthenticationResult): void;
2227
2227
  * await, so reading the original there would join whatever it holds by then.
2228
2228
  *
2229
2229
  * @param auth - The resolved authentication result.
2230
- * @returns `auth` itself when it has no `rooms`; otherwise a result with the same fields and a
2231
- * frozen copy of its `rooms`.
2232
- * @throws Error carrying `REALTIME_AUTH_FAILED` when `rooms` is present and invalid.
2230
+ * @returns `auth` itself when it has no `rooms` and no array `roles`; otherwise a result with the
2231
+ * same fields and a frozen copy of each of those it has.
2232
+ * @throws Error carrying `REALTIME_AUTH_FAILED` when `rooms` is present and invalid, or `roles` cannot be read.
2233
2233
  */
2234
2234
  declare function admitRooms(auth: AuthenticationResult): AuthenticationResult;
2235
2235
 
@@ -77,6 +77,11 @@ var WEBSOCKET_KEYS = {
77
77
  emitConnectionEvent: true,
78
78
  redisAdapter: true
79
79
  };
80
+ var CORS_KEYS = {
81
+ origin: true,
82
+ credentials: true,
83
+ methods: true
84
+ };
80
85
  var REAUTHENTICATION_KEYS = {
81
86
  intervalSeconds: true,
82
87
  onFailure: true,
@@ -120,6 +125,13 @@ function dropUnset(options) {
120
125
  const value = kept[group];
121
126
  if (isPlainObject(value)) kept[group] = readSet(value, keys);
122
127
  }
128
+ const websocket = kept.websocket;
129
+ if (isPlainObject(websocket)) {
130
+ const cors = websocket.cors;
131
+ if (typeof cors === "object" && cors !== null && !Array.isArray(cors)) {
132
+ websocket.cors = readSet(cors, CORS_KEYS);
133
+ }
134
+ }
123
135
  return kept;
124
136
  }
125
137
 
@@ -852,9 +864,23 @@ function refuse2(detail) {
852
864
  `the authenticator returned rooms that are not valid: ${detail}. Fix the authenticator; the limits are bounds against abuse and apply to this field only.`
853
865
  );
854
866
  }
867
+ function admitRoles(roles) {
868
+ if (!Array.isArray(roles)) return roles;
869
+ try {
870
+ return Object.freeze([...roles]);
871
+ } catch (error) {
872
+ throw realtimeError(
873
+ REALTIME_ERROR_CODES.AUTH_FAILED,
874
+ "the authenticator returned roles that could not be read: a getter or a proxy on them throws",
875
+ { cause: error }
876
+ );
877
+ }
878
+ }
855
879
  function admitRooms(auth) {
880
+ const roles = admitRoles(auth.roles);
856
881
  const { rooms } = auth;
857
- if (rooms === void 0) return auth;
882
+ const kept = roles === auth.roles ? auth : { ...auth, roles };
883
+ if (rooms === void 0) return kept;
858
884
  if (!Array.isArray(rooms)) refuse2("`rooms` is not an array");
859
885
  const admitted = [];
860
886
  for (const room of rooms) {
@@ -875,7 +901,7 @@ function admitRooms(auth) {
875
901
  const reserved = reservedRoomPrefix(room);
876
902
  if (reserved !== void 0) refuse2(`a room name starts with the reserved prefix "${reserved}"`);
877
903
  }
878
- return { ...auth, rooms: Object.freeze(admitted) };
904
+ return { ...kept, rooms: Object.freeze(admitted) };
879
905
  }
880
906
 
881
907
  // src/server/utils/assert-identity.ts
@@ -886,6 +912,7 @@ function resolveAuthTenant(options, auth) {
886
912
  const own = auth.tenantId;
887
913
  const kept = keepByName(auth);
888
914
  const resolved = options.tenantResolver?.(auth) ?? own;
915
+ if (resolved instanceof Promise) resolved.catch(() => void 0);
889
916
  if (resolved === void 0 || resolved === null) return kept;
890
917
  return { ...kept, tenantId: resolved };
891
918
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bymax-one/nest-realtime",
3
- "version": "1.2.25",
3
+ "version": "1.2.26",
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",