fix(onebot): enforce WebSocket access policy

Apply the configured access policy before server-side WebSocket sessions are established across both listener modes.

Preserve established client compatibility and runtime configuration changes, with regression coverage for accepted and rejected connections.
This commit is contained in:
DrSmoothl committed 2026-08-01 17:09:04 +08:00
1 parent 8940f8864b
commit 3c772df818
5 files changed
+64 -3

No files matched your search

@@ -160,7 +160,11 @@ export class HttpServerAdapter extends IOneBotNetworkAdapter<HttpServerNetwork>
let webSocketServer: WebSocketServer | null = null;
try {
if (this.config.enableWebSocket === true) {
webSocketServer = new WebSocketServer({ server });
webSocketServer = new WebSocketServer({
server,
verifyClient: ({ req }: { req: IncomingMessage }) =>
this.webSocketConnections.authorizeUpgrade(req),
});
webSocketServer.on('connection', (socket, request) => {
this.webSocketConnections.accept(socket, request);
});