Skip to content

Commit c3be5ee

Browse files
committed
fix(ws): stricter check on web socket origins
To avoid CORS vulnerabilities
1 parent a8b74b4 commit c3be5ee

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@ const { setNotificationCallback } = require('@vue/cli-ui/apollo-server/util/noti
66
function simpleCorsValidation (allowedHost) {
77
return function (req, socket) {
88
const { host, origin } = req.headers
9-
// maybe we should just use strict string equal?
10-
const hostRegExp = new RegExp(`^https?://(${host}|${allowedHost}|localhost)(:\\d+)?$`)
119

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

0 commit comments

Comments
 (0)