Skip to content

Commit 0266bbb

Browse files
committed
fix(ws): stricter check on web socket origins
To avoid CORS vulnerabilities
1 parent 6e0d846 commit 0266bbb

File tree

1 file changed

+7
-3
lines changed
  • packages/@vue/cli/lib

1 file changed

+7
-3
lines changed

packages/@vue/cli/lib/ui.js

+7-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@ const shortid = require('shortid')
55
function simpleCorsValidation (allowedHost) {
66
return function (req, socket) {
77
const { host, origin } = req.headers
8-
// maybe we should just use strict string equal?
9-
const hostRegExp = new RegExp(`^https?://(${host}|${allowedHost}|localhost)(:\\d+)?$`)
108

11-
if (!origin || !hostRegExp.test(origin)) {
9+
const safeOrigins = [
10+
host,
11+
allowedHost,
12+
'localhost'
13+
]
14+
15+
if (!origin || !safeOrigins.includes(new URL(origin).hostname)) {
1216
socket.destroy()
1317
}
1418
}

0 commit comments

Comments
 (0)