fix: avoid websocket token leakage in logs

This commit is contained in:
2026-06-22 11:34:35 +08:00
parent 0793eb82d6
commit c5d9bac0ed
2 changed files with 57 additions and 30 deletions
+10 -9
View File
@@ -169,21 +169,22 @@ export class WebSocketManager {
return;
}
// 构建带token的URL
const separator = this.config.url.includes('?') ? '&' : '?';
const wsUrl = `${this.config.url}${separator}token=${encodeURIComponent(token)}`;
const wsUrl = this.config.url;
const protocols = Array.isArray(this.config.protocols)
? [...this.config.protocols]
: this.config.protocols
? [this.config.protocols]
: [];
protocols.unshift('access_token', token);
console.log(
'Connecting to WebSocket:',
wsUrl.replace(/token=[^&]+/, 'token=***'),
);
console.log('Connecting to WebSocket:', wsUrl);
console.log('WebSocket URL详情:', {
originalUrl: this.config.url,
finalUrl: wsUrl.replace(/token=[^&]+/, 'token=***'),
finalUrl: wsUrl,
isDev: import.meta.env.DEV,
});
this.ws = new WebSocket(wsUrl, this.config.protocols);
this.ws = new WebSocket(wsUrl, protocols);
this.ws.addEventListener('open', (event) => {
console.log('WebSocket连接已建立');