@steve31415/baselib 4.0.0 → 5.0.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/README.md +8 -0
- package/dist/app-update/shell.d.ts +11 -1
- package/dist/app-update/shell.js +29 -3
- package/dist/auth.d.ts +22 -0
- package/dist/auth.js +105 -28
- package/dist/http.d.ts +8 -4
- package/dist/http.js +12 -7
- package/dist/hub/server.d.ts +3 -7
- package/dist/hub/server.js +16 -3
- package/dist/log-browser.js +10 -5
- package/dist/ops/logs.d.ts +6 -1
- package/dist/ops/logs.js +32 -19
- package/dist/origin-check.d.ts +62 -0
- package/dist/origin-check.js +136 -0
- package/dist/s2s.d.ts +6 -0
- package/dist/s2s.js +10 -4
- package/dist/security-headers.d.ts +59 -0
- package/dist/security-headers.js +193 -0
- package/dist/socket-age.d.ts +34 -1
- package/dist/socket-age.js +30 -1
- package/dist/sync-browser/client.js +7 -0
- package/package.json +1 -1
package/dist/socket-age.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
// A cap on WebSocket age, applied by wrapping a Hono `upgradeWebSocket
|
|
1
|
+
// A cap on WebSocket age, applied by wrapping a Hono `upgradeWebSocket`, and
|
|
2
|
+
// (since 5.0.0) a cap on the size of one incoming message, applied to the
|
|
3
|
+
// app's ws server.
|
|
2
4
|
//
|
|
3
5
|
// An open socket is an open request, and Cloud Run keeps a retired instance
|
|
4
6
|
// alive (and counted against --max-instances) until its last request ends.
|
|
@@ -8,6 +10,7 @@
|
|
|
8
10
|
// laptop, an old client) at 300 s of age, in code rather than through the
|
|
9
11
|
// service's --timeout, which must stay long enough for long background
|
|
10
12
|
// routes (PW docs/OPERATIONS.md, "Socket lifetime").
|
|
13
|
+
import { truncate } from './log-core.js';
|
|
11
14
|
/** Sockets older than this are closed by the server. */
|
|
12
15
|
export const SOCKET_MAX_AGE_MS = 300_000;
|
|
13
16
|
/** After the close frame, how long the client gets to answer it before the
|
|
@@ -100,3 +103,29 @@ function withAgeCap(events, path, maxAgeMs, graceMs, logger) {
|
|
|
100
103
|
},
|
|
101
104
|
};
|
|
102
105
|
}
|
|
106
|
+
// ---- message size ----
|
|
107
|
+
/** The default cap on one incoming WebSocket message: 1 MiB. ws's own
|
|
108
|
+
* default is 100 MiB, which lets one client make the server buffer that
|
|
109
|
+
* much per frame. */
|
|
110
|
+
export const SOCKET_MAX_PAYLOAD = 1024 * 1024;
|
|
111
|
+
/** Caps the size of one incoming message on every socket of the app's ws
|
|
112
|
+
* server, the way the hub caps its own: a client that sends more has its
|
|
113
|
+
* socket closed with 1009 (message too big). Takes effect for sockets
|
|
114
|
+
* opened after the call (ws reads the option at each upgrade). */
|
|
115
|
+
export function capSocketMessageSize(wss, options = {}) {
|
|
116
|
+
const maxBytes = options.maxBytes ?? SOCKET_MAX_PAYLOAD;
|
|
117
|
+
// ws reads 0 as "no limit": a computed 0 must not remove the cap.
|
|
118
|
+
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1)
|
|
119
|
+
throw new Error(`capSocketMessageSize: maxBytes must be a positive whole number, got ${maxBytes}`);
|
|
120
|
+
wss.options.maxPayload = maxBytes;
|
|
121
|
+
const logger = options.logger;
|
|
122
|
+
if (!logger || !wss.on)
|
|
123
|
+
return;
|
|
124
|
+
wss.on('connection', (ws, request) => {
|
|
125
|
+
ws.on('error', (error) => {
|
|
126
|
+
if (error.code !== 'WS_ERR_UNSUPPORTED_MESSAGE_LENGTH')
|
|
127
|
+
return;
|
|
128
|
+
logger.warn('socket message too large', { path: truncate(new URL(request.url ?? '/', 'http://x').pathname, 200), maxBytes });
|
|
129
|
+
});
|
|
130
|
+
});
|
|
131
|
+
}
|
|
@@ -686,6 +686,13 @@ export class SyncClient {
|
|
|
686
686
|
}
|
|
687
687
|
this.hubLastHeardAt = this.now();
|
|
688
688
|
this.hubAwaitingPong = false;
|
|
689
|
+
// Hidden with a hub socket, the 5-minute tick runs beside it (hints can
|
|
690
|
+
// be lost). A page hidden later started it at the hide; one loaded
|
|
691
|
+
// hidden starts it here, current since its bootstrap.
|
|
692
|
+
if (this.isHidden() && this.backgroundTickTimer === null) {
|
|
693
|
+
this.lastTickAt ??= this.now();
|
|
694
|
+
this.armBackgroundTick();
|
|
695
|
+
}
|
|
689
696
|
this.sendRaw(this.connectMessage());
|
|
690
697
|
this.startLiveTimers();
|
|
691
698
|
};
|
package/package.json
CHANGED