Skip to content

Commit a0d50f6

Browse files
committed
chore: disable ws validate connnection
1 parent a8aed29 commit a0d50f6

File tree

1 file changed

+29
-29
lines changed
  • packages/vite/src/node/server

1 file changed

+29
-29
lines changed

packages/vite/src/node/server/ws.ts

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import path from 'node:path'
1+
// import path from 'node:path'
22
import type { IncomingMessage, Server } from 'node:http'
33
import { STATUS_CODES, createServer as createHttpServer } from 'node:http'
44
import type { ServerOptions as HttpsServerOptions } from 'node:https'
55
import { createServer as createHttpsServer } from 'node:https'
66
import type { Socket } from 'node:net'
77
import type { Duplex } from 'node:stream'
8-
import crypto from 'node:crypto'
8+
// import crypto from 'node:crypto'
99
import colors from 'picocolors'
1010
import type { WebSocket as WebSocketRaw } from 'ws'
1111
import { WebSocketServer as WebSocketServerRaw_ } from 'ws'
@@ -102,19 +102,19 @@ function noop() {
102102
//
103103
// using the query params means the token might be logged out in server or middleware logs
104104
// but we assume that is not an issue since the token is regenerated for each process
105-
function hasValidToken(config: ResolvedConfig, url: URL) {
106-
const token = url.searchParams.get('token')
107-
if (!token) return false
105+
// function hasValidToken(config: ResolvedConfig, url: URL) {
106+
// const token = url.searchParams.get('token')
107+
// if (!token) return false
108108

109-
try {
110-
const isValidToken = crypto.timingSafeEqual(
111-
Buffer.from(token),
112-
Buffer.from(config.webSocketToken),
113-
)
114-
return isValidToken
115-
} catch {} // an error is thrown when the length is incorrect
116-
return false
117-
}
109+
// try {
110+
// const isValidToken = crypto.timingSafeEqual(
111+
// Buffer.from(token),
112+
// Buffer.from(config.webSocketToken),
113+
// )
114+
// return isValidToken
115+
// } catch {} // an error is thrown when the length is incorrect
116+
// return false
117+
// }
118118

119119
export function createWebSocketServer(
120120
server: HttpServer | null,
@@ -181,10 +181,10 @@ export function createWebSocketServer(
181181

182182
// If the Origin header is set, this request might be coming from a browser.
183183
// Browsers always sets the Origin header for WebSocket connections.
184-
if (req.headers.origin) {
185-
const parsedUrl = new URL(`http://example.com${req.url!}`)
186-
return hasValidToken(config, parsedUrl)
187-
}
184+
// if (req.headers.origin) {
185+
// const parsedUrl = new URL(`http://example.com${req.url!}`)
186+
// return hasValidToken(config, parsedUrl)
187+
// }
188188

189189
// We allow non-browser requests to connect without a token
190190
// for backward compat and convenience
@@ -213,20 +213,20 @@ export function createWebSocketServer(
213213
wss.shouldHandle = shouldHandle
214214

215215
if (wsServer) {
216-
let hmrBase = config.base
217-
const hmrPath = hmr ? hmr.path : undefined
218-
if (hmrPath) {
219-
hmrBase = path.posix.join(hmrBase, hmrPath)
220-
}
216+
// let hmrBase = config.base
217+
// const hmrPath = hmr ? hmr.path : undefined
218+
// if (hmrPath) {
219+
// hmrBase = path.posix.join(hmrBase, hmrPath)
220+
// }
221221
hmrServerWsListener = (req, socket, head) => {
222222
const protocol = req.headers['sec-websocket-protocol']!
223-
const parsedUrl = new URL(`http://example.com${req.url!}`)
224-
if (
225-
[HMR_HEADER, 'vite-ping'].includes(protocol) &&
226-
parsedUrl.pathname === hmrBase
227-
) {
223+
// const parsedUrl = new URL(`http://example.com${req.url!}`)
224+
// if (
225+
// [HMR_HEADER, 'vite-ping'].includes(protocol) &&
226+
// parsedUrl.pathname === hmrBase
227+
// ) {
228228
handleUpgrade(req, socket as Socket, head, protocol === 'vite-ping')
229-
}
229+
// }
230230
}
231231
wsServer.on('upgrade', hmrServerWsListener)
232232
} else {

0 commit comments

Comments
 (0)