Skip to content

Commit a903d65

Browse files
committed
fix: followup of #4985, allow same-site ws requests of any domain
1 parent 773f8a4 commit a903d65

File tree

1 file changed

+12
-6
lines changed
  • packages/@vue/cli/lib

1 file changed

+12
-6
lines changed

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ const { log, error, openBrowser } = require('@vue/cli-shared-utils')
22
const { portfinder, server } = require('@vue/cli-ui/server')
33
const shortid = require('shortid')
44

5+
function simpleCorsValidation (allowedHost) {
6+
return function (req, socket) {
7+
const { host, origin } = req.headers
8+
const hostRegExp = new RegExp(`${host}|${allowedHost}|localhost`)
9+
10+
if (!origin || !hostRegExp.test(origin)) {
11+
socket.destroy()
12+
}
13+
}
14+
}
15+
516
async function ui (options = {}, context = process.cwd()) {
617
const host = options.host || 'localhost'
718

@@ -69,12 +80,7 @@ async function ui (options = {}, context = process.cwd()) {
6980
}
7081
})
7182

72-
httpServer.on('upgrade', (req, socket) => {
73-
const { origin } = req.headers
74-
if (!origin || !(new RegExp(host)).test(origin)) {
75-
socket.destroy()
76-
}
77-
})
83+
httpServer.on('upgrade', simpleCorsValidation(host))
7884
}
7985

8086
module.exports = (...args) => {

0 commit comments

Comments
 (0)