Skip to content

Commit

Permalink
fix: followup of #4985, allow same-site ws requests of any domain
Browse files Browse the repository at this point in the history
  • Loading branch information
sodatea committed Feb 4, 2020
1 parent 773f8a4 commit a903d65
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions packages/@vue/cli/lib/ui.js
Expand Up @@ -2,6 +2,17 @@ const { log, error, openBrowser } = require('@vue/cli-shared-utils')
const { portfinder, server } = require('@vue/cli-ui/server')
const shortid = require('shortid')

function simpleCorsValidation (allowedHost) {
return function (req, socket) {
const { host, origin } = req.headers
const hostRegExp = new RegExp(`${host}|${allowedHost}|localhost`)

if (!origin || !hostRegExp.test(origin)) {
socket.destroy()
}
}
}

async function ui (options = {}, context = process.cwd()) {
const host = options.host || 'localhost'

Expand Down Expand Up @@ -69,12 +80,7 @@ async function ui (options = {}, context = process.cwd()) {
}
})

httpServer.on('upgrade', (req, socket) => {
const { origin } = req.headers
if (!origin || !(new RegExp(host)).test(origin)) {
socket.destroy()
}
})
httpServer.on('upgrade', simpleCorsValidation(host))
}

module.exports = (...args) => {
Expand Down

0 comments on commit a903d65

Please sign in to comment.