P0安全修复: WS token改subprotocol + nginx日志关闭 + 类型修复 + 降级验证 + 依赖

This commit is contained in:
Simon
2026-06-14 21:21:48 +08:00
parent edbb86835e
commit ddebbe61a5
12 changed files with 628 additions and 27 deletions
@@ -103,12 +103,10 @@ export function useWebSocket() {
console.log(`[WebSocket] 正在连接: ${wsUrl}`)
ws = new WebSocket(wsUrl, [], {
// P0-#4: 将 token 放入 Authorization header(避免 URL 泄露)
headers: {
Authorization: `Bearer ${agentStore.token}`,
},
})
// P0-#4 修复: 用 Sec-WebSocket-Protocol (subprotocols) 传递 token
// 浏览器原生 WebSocket API 第2参数是 protocols (字符串数组),不是 headers
// 服务端从 sec-websocket-protocol 头读取 bearer.{token}
ws = new WebSocket(wsUrl, [`bearer.${agentStore.token}`])
// ----------------------------------------------------------------------
// 连接成功