@bymax-one/nest-realtime 1.2.26 → 1.2.27
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 +23 -1
- 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,27 @@ Versioning is **not** strict [SemVer](https://semver.org/spec/v2.0.0.html) while
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.27] - 2026-11-21
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- **`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.
|
|
16
|
+
|
|
17
|
+
### Documentation
|
|
18
|
+
|
|
19
|
+
- **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.
|
|
20
|
+
- **`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.
|
|
21
|
+
- **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.
|
|
22
|
+
|
|
23
|
+
### Tests
|
|
24
|
+
|
|
25
|
+
- 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.
|
|
26
|
+
|
|
27
|
+
#### Apply to a derived backend
|
|
28
|
+
|
|
29
|
+
An authenticator that returns more than 1,024 roles is now refused; none is expected to.
|
|
30
|
+
|
|
10
31
|
## [1.2.26] - 2026-11-21
|
|
11
32
|
|
|
12
33
|
### Fixed
|
|
@@ -1298,7 +1319,8 @@ First published release.
|
|
|
1298
1319
|
rather than by the manual sweep that raised the NestJS floors — that sweep
|
|
1299
1320
|
asked about NestJS and never put the same question to the other ten peers.
|
|
1300
1321
|
|
|
1301
|
-
[Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.
|
|
1322
|
+
[Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.27...HEAD
|
|
1323
|
+
[1.2.27]: https://github.com/bymaxone/nest-realtime/compare/v1.2.26...v1.2.27
|
|
1302
1324
|
[1.2.26]: https://github.com/bymaxone/nest-realtime/compare/v1.2.25...v1.2.26
|
|
1303
1325
|
[1.2.25]: https://github.com/bymaxone/nest-realtime/compare/v1.2.24...v1.2.25
|
|
1304
1326
|
[1.2.24]: https://github.com/bymaxone/nest-realtime/compare/v1.2.23...v1.2.24
|
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.27",
|
|
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",
|