@bymax-one/nest-realtime 1.2.26 → 1.2.28
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 +34 -1
- package/README.md +3 -0
- package/dist/internal/index.cjs +29 -3
- package/dist/internal/index.mjs +29 -3
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +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.28] - 2026-11-21
|
|
11
|
+
|
|
12
|
+
### Documentation
|
|
13
|
+
|
|
14
|
+
- **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.
|
|
15
|
+
|
|
16
|
+
#### Apply to a derived backend
|
|
17
|
+
|
|
18
|
+
None. No code changed.
|
|
19
|
+
|
|
20
|
+
## [1.2.27] - 2026-11-21
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **`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.
|
|
25
|
+
- **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).
|
|
26
|
+
|
|
27
|
+
### Documentation
|
|
28
|
+
|
|
29
|
+
- **What a `tenantResolver` that returns something other than a native promise gets.** A thenable that is not a promise is never asked for its `then`, because asking could run a lazy query, so its own rejection is not absorbed; a promise whose `constructor` cannot be read cannot be given a handler either. Both are refused as a blank tenant.
|
|
30
|
+
- **`roles` that is not an array is kept as it is.** A string, a `Set` or an array-like proxy is not copied, so it is read later by whoever uses it.
|
|
31
|
+
- **A `websocket.cors` key outside `CorsConfig`.** Only the keys the library names (`origin`, `credentials`, `methods`) and the block's own enumerable keys are carried; any other key defined as a getter on a prototype or as non-enumerable is not.
|
|
32
|
+
|
|
33
|
+
### Tests
|
|
34
|
+
|
|
35
|
+
- Rows for `websocket.cors` with `origin: false`, a `RegExp`, a function and a proxy over an empty target that answers by name, over a real Socket.IO server.
|
|
36
|
+
|
|
37
|
+
#### Apply to a derived backend
|
|
38
|
+
|
|
39
|
+
An authenticator that returns more than 1,024 roles is now refused; none is expected to.
|
|
40
|
+
|
|
10
41
|
## [1.2.26] - 2026-11-21
|
|
11
42
|
|
|
12
43
|
### Fixed
|
|
@@ -1298,7 +1329,9 @@ First published release.
|
|
|
1298
1329
|
rather than by the manual sweep that raised the NestJS floors — that sweep
|
|
1299
1330
|
asked about NestJS and never put the same question to the other ten peers.
|
|
1300
1331
|
|
|
1301
|
-
[Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.
|
|
1332
|
+
[Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.28...HEAD
|
|
1333
|
+
[1.2.28]: https://github.com/bymaxone/nest-realtime/compare/v1.2.27...v1.2.28
|
|
1334
|
+
[1.2.27]: https://github.com/bymaxone/nest-realtime/compare/v1.2.26...v1.2.27
|
|
1302
1335
|
[1.2.26]: https://github.com/bymaxone/nest-realtime/compare/v1.2.25...v1.2.26
|
|
1303
1336
|
[1.2.25]: https://github.com/bymaxone/nest-realtime/compare/v1.2.24...v1.2.25
|
|
1304
1337
|
[1.2.24]: https://github.com/bymaxone/nest-realtime/compare/v1.2.23...v1.2.24
|
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
|
|
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
|
package/dist/internal/index.cjs
CHANGED
|
@@ -860,6 +860,7 @@ function refuseReservedRoom(operation, roomId) {
|
|
|
860
860
|
}
|
|
861
861
|
|
|
862
862
|
// src/server/utils/admit-rooms.ts
|
|
863
|
+
var MAX_ROLES = 1024;
|
|
863
864
|
function refuse2(detail) {
|
|
864
865
|
throw realtimeError(
|
|
865
866
|
REALTIME_ERROR_CODES.AUTH_FAILED,
|
|
@@ -867,9 +868,17 @@ function refuse2(detail) {
|
|
|
867
868
|
);
|
|
868
869
|
}
|
|
869
870
|
function admitRoles(roles) {
|
|
870
|
-
|
|
871
|
+
const admitted = [];
|
|
872
|
+
let overflow = false;
|
|
871
873
|
try {
|
|
872
|
-
|
|
874
|
+
if (!Array.isArray(roles)) return roles;
|
|
875
|
+
for (const role of roles) {
|
|
876
|
+
if (admitted.length === MAX_ROLES) {
|
|
877
|
+
overflow = true;
|
|
878
|
+
break;
|
|
879
|
+
}
|
|
880
|
+
admitted.push(role);
|
|
881
|
+
}
|
|
873
882
|
} catch (error) {
|
|
874
883
|
throw realtimeError(
|
|
875
884
|
REALTIME_ERROR_CODES.AUTH_FAILED,
|
|
@@ -877,6 +886,13 @@ function admitRoles(roles) {
|
|
|
877
886
|
{ cause: error }
|
|
878
887
|
);
|
|
879
888
|
}
|
|
889
|
+
if (overflow) {
|
|
890
|
+
throw realtimeError(
|
|
891
|
+
REALTIME_ERROR_CODES.AUTH_FAILED,
|
|
892
|
+
`the authenticator returned more than ${MAX_ROLES} roles: the limit is ${MAX_ROLES}`
|
|
893
|
+
);
|
|
894
|
+
}
|
|
895
|
+
return Object.freeze(admitted);
|
|
880
896
|
}
|
|
881
897
|
function admitRooms(auth) {
|
|
882
898
|
const roles = admitRoles(auth.roles);
|
|
@@ -914,10 +930,20 @@ function resolveAuthTenant(options, auth) {
|
|
|
914
930
|
const own = auth.tenantId;
|
|
915
931
|
const kept = keepByName(auth);
|
|
916
932
|
const resolved = options.tenantResolver?.(auth) ?? own;
|
|
917
|
-
|
|
933
|
+
absorbRejection(resolved);
|
|
918
934
|
if (resolved === void 0 || resolved === null) return kept;
|
|
919
935
|
return { ...kept, tenantId: resolved };
|
|
920
936
|
}
|
|
937
|
+
function absorbRejection(value) {
|
|
938
|
+
try {
|
|
939
|
+
Promise.prototype.then.call(value, void 0, () => void 0);
|
|
940
|
+
} catch {
|
|
941
|
+
try {
|
|
942
|
+
if (value instanceof Promise) value.catch(() => void 0);
|
|
943
|
+
} catch {
|
|
944
|
+
}
|
|
945
|
+
}
|
|
946
|
+
}
|
|
921
947
|
function keepByName(auth) {
|
|
922
948
|
const kept = {};
|
|
923
949
|
for (const key of ["userId", "roles", "rooms", "metadata"]) {
|
package/dist/internal/index.mjs
CHANGED
|
@@ -858,6 +858,7 @@ function refuseReservedRoom(operation, roomId) {
|
|
|
858
858
|
}
|
|
859
859
|
|
|
860
860
|
// src/server/utils/admit-rooms.ts
|
|
861
|
+
var MAX_ROLES = 1024;
|
|
861
862
|
function refuse2(detail) {
|
|
862
863
|
throw realtimeError(
|
|
863
864
|
REALTIME_ERROR_CODES.AUTH_FAILED,
|
|
@@ -865,9 +866,17 @@ function refuse2(detail) {
|
|
|
865
866
|
);
|
|
866
867
|
}
|
|
867
868
|
function admitRoles(roles) {
|
|
868
|
-
|
|
869
|
+
const admitted = [];
|
|
870
|
+
let overflow = false;
|
|
869
871
|
try {
|
|
870
|
-
|
|
872
|
+
if (!Array.isArray(roles)) return roles;
|
|
873
|
+
for (const role of roles) {
|
|
874
|
+
if (admitted.length === MAX_ROLES) {
|
|
875
|
+
overflow = true;
|
|
876
|
+
break;
|
|
877
|
+
}
|
|
878
|
+
admitted.push(role);
|
|
879
|
+
}
|
|
871
880
|
} catch (error) {
|
|
872
881
|
throw realtimeError(
|
|
873
882
|
REALTIME_ERROR_CODES.AUTH_FAILED,
|
|
@@ -875,6 +884,13 @@ function admitRoles(roles) {
|
|
|
875
884
|
{ cause: error }
|
|
876
885
|
);
|
|
877
886
|
}
|
|
887
|
+
if (overflow) {
|
|
888
|
+
throw realtimeError(
|
|
889
|
+
REALTIME_ERROR_CODES.AUTH_FAILED,
|
|
890
|
+
`the authenticator returned more than ${MAX_ROLES} roles: the limit is ${MAX_ROLES}`
|
|
891
|
+
);
|
|
892
|
+
}
|
|
893
|
+
return Object.freeze(admitted);
|
|
878
894
|
}
|
|
879
895
|
function admitRooms(auth) {
|
|
880
896
|
const roles = admitRoles(auth.roles);
|
|
@@ -912,10 +928,20 @@ function resolveAuthTenant(options, auth) {
|
|
|
912
928
|
const own = auth.tenantId;
|
|
913
929
|
const kept = keepByName(auth);
|
|
914
930
|
const resolved = options.tenantResolver?.(auth) ?? own;
|
|
915
|
-
|
|
931
|
+
absorbRejection(resolved);
|
|
916
932
|
if (resolved === void 0 || resolved === null) return kept;
|
|
917
933
|
return { ...kept, tenantId: resolved };
|
|
918
934
|
}
|
|
935
|
+
function absorbRejection(value) {
|
|
936
|
+
try {
|
|
937
|
+
Promise.prototype.then.call(value, void 0, () => void 0);
|
|
938
|
+
} catch {
|
|
939
|
+
try {
|
|
940
|
+
if (value instanceof Promise) value.catch(() => void 0);
|
|
941
|
+
} catch {
|
|
942
|
+
}
|
|
943
|
+
}
|
|
944
|
+
}
|
|
919
945
|
function keepByName(auth) {
|
|
920
946
|
const kept = {};
|
|
921
947
|
for (const key of ["userId", "roles", "rooms", "metadata"]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-realtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.28",
|
|
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",
|