@mulmobridge/chat-service 1.0.3 → 1.1.0
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/dist/socket.js +15 -5
- package/package.json +1 -1
package/dist/socket.js
CHANGED
|
@@ -45,6 +45,15 @@ export const CHAT_SOCKET_EVENTS = {
|
|
|
45
45
|
/** server → bridge streaming text chunk (Phase C of #268). */
|
|
46
46
|
textChunk: "textChunk",
|
|
47
47
|
};
|
|
48
|
+
// Hard limits to prevent oversized payloads from bridges (DoS /
|
|
49
|
+
// accidental misconfiguration). Express's JSON body limit (50 MB)
|
|
50
|
+
// is the outer gate; these are tighter, attachment-specific caps.
|
|
51
|
+
const MAX_ATTACHMENT_COUNT = 10;
|
|
52
|
+
const MAX_ATTACHMENT_TOTAL_BYTES = 20 * 1024 * 1024; // 20 MB base64
|
|
53
|
+
/** Transport ceiling for one socket frame. Headroom over the attachment
|
|
54
|
+
* budget for the rest of the payload (text, ids, options) so the
|
|
55
|
+
* application-level cap is what a bridge actually hits. */
|
|
56
|
+
const MAX_SOCKET_PAYLOAD_BYTES = MAX_ATTACHMENT_TOTAL_BYTES + 4 * 1024 * 1024;
|
|
48
57
|
export function bridgeRoom(transportId) {
|
|
49
58
|
return `bridge:${transportId}`;
|
|
50
59
|
}
|
|
@@ -55,6 +64,12 @@ export function attachChatSocket(server, deps) {
|
|
|
55
64
|
// Loopback-only deployment; skip long-polling negotiation for
|
|
56
65
|
// the same reason `/ws/pubsub` does (#311).
|
|
57
66
|
transports: ["websocket"],
|
|
67
|
+
// Socket.IO's default is 1 MB — below the attachment budget
|
|
68
|
+
// `parseAttachments` enforces, so a bridge shipping a 900 KB image
|
|
69
|
+
// had its connection closed before the ack instead of a reply.
|
|
70
|
+
// `parseAttachments` stays the real gate; this only has to be
|
|
71
|
+
// wide enough not to pre-empt it.
|
|
72
|
+
maxHttpBufferSize: MAX_SOCKET_PAYLOAD_BYTES,
|
|
58
73
|
});
|
|
59
74
|
io.use((socket, next) => {
|
|
60
75
|
const result = validateHandshake(socket.handshake.auth, tokenProvider);
|
|
@@ -232,11 +247,6 @@ function parseMessagePayload(payload) {
|
|
|
232
247
|
const attachments = parseAttachments(payload.attachments);
|
|
233
248
|
return { ok: true, externalChatId, text, attachments };
|
|
234
249
|
}
|
|
235
|
-
// Hard limits to prevent oversized payloads from bridges (DoS /
|
|
236
|
-
// accidental misconfiguration). Express's JSON body limit (50 MB)
|
|
237
|
-
// is the outer gate; these are tighter, attachment-specific caps.
|
|
238
|
-
const MAX_ATTACHMENT_COUNT = 10;
|
|
239
|
-
const MAX_ATTACHMENT_TOTAL_BYTES = 20 * 1024 * 1024; // 20 MB base64
|
|
240
250
|
export function parseAttachments(raw) {
|
|
241
251
|
if (!Array.isArray(raw) || raw.length === 0)
|
|
242
252
|
return undefined;
|
package/package.json
CHANGED