@nestjs/platform-ws 11.2.5 → 11.2.7
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/adapters/ws-adapter.js +21 -2
- package/package.json +2 -2
package/adapters/ws-adapter.js
CHANGED
|
@@ -78,12 +78,31 @@ class WsAdapter extends websockets_1.AbstractWsAdapter {
|
|
|
78
78
|
const handlersMap = new Map();
|
|
79
79
|
handlers.forEach(handler => handlersMap.set(handler.message, handler));
|
|
80
80
|
const close$ = (0, rxjs_1.fromEvent)(client, constants_1.CLOSE_EVENT).pipe((0, operators_1.share)(), (0, operators_1.first)());
|
|
81
|
-
const source$ = (0, rxjs_1.fromEvent)(client, 'message').pipe((0, operators_1.mergeMap)(data => this.bindMessageHandler(data, handlersMap, transform).pipe((0, operators_1.filter)(result => !(0, shared_utils_1.isNil)(result))
|
|
81
|
+
const source$ = (0, rxjs_1.fromEvent)(client, 'message').pipe((0, operators_1.mergeMap)(data => this.bindMessageHandler(data, handlersMap, transform).pipe((0, operators_1.filter)(result => !(0, shared_utils_1.isNil)(result)),
|
|
82
|
+
// a handler that rejects through an error filter that rethrows
|
|
83
|
+
// would error the client's stream and silence every later message;
|
|
84
|
+
// that rethrow is an app bug, so it gets logged, not dropped silently
|
|
85
|
+
(0, operators_1.catchError)(err => {
|
|
86
|
+
this.logger.error(err);
|
|
87
|
+
return rxjs_1.EMPTY;
|
|
88
|
+
}))), (0, operators_1.takeUntil)(close$));
|
|
82
89
|
const onMessage = (response) => {
|
|
83
90
|
if (client.readyState !== READY_STATE.OPEN_STATE) {
|
|
84
91
|
return;
|
|
85
92
|
}
|
|
86
|
-
|
|
93
|
+
// JSON.stringify throws on circular structures and BigInts, and on
|
|
94
|
+
// client-controlled payloads nested deep enough to overflow its native
|
|
95
|
+
// recursion (JSON.parse accepts any depth). A throw here escapes the
|
|
96
|
+
// subscriber, which RxJS rethrows asynchronously, killing the process.
|
|
97
|
+
let payload;
|
|
98
|
+
try {
|
|
99
|
+
payload = JSON.stringify(response);
|
|
100
|
+
}
|
|
101
|
+
catch (err) {
|
|
102
|
+
this.logger.error(err);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
client.send(payload);
|
|
87
106
|
};
|
|
88
107
|
source$.subscribe(onMessage);
|
|
89
108
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nestjs/platform-ws",
|
|
3
|
-
"version": "11.2.
|
|
3
|
+
"version": "11.2.7",
|
|
4
4
|
"description": "Nest - modern, fast, powerful node.js web framework (@platform-ws)",
|
|
5
5
|
"author": "Kamil Mysliwiec",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,5 +26,5 @@
|
|
|
26
26
|
"@nestjs/websockets": "^11.0.0",
|
|
27
27
|
"rxjs": "^7.1.0"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "c666d7f72201f02cd241030d815abf72dbf49b15"
|
|
30
30
|
}
|