mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-01-24 16:18:57 -06:00
fix(ws): stricter check on web socket origins
To avoid CORS vulnerabilities
This commit is contained in:
@@ -5,10 +5,14 @@ const shortid = require('shortid')
|
||||
function simpleCorsValidation (allowedHost) {
|
||||
return function (req, socket) {
|
||||
const { host, origin } = req.headers
|
||||
// maybe we should just use strict string equal?
|
||||
const hostRegExp = new RegExp(`^https?://(${host}|${allowedHost}|localhost)(:\\d+)?$`)
|
||||
|
||||
if (!origin || !hostRegExp.test(origin)) {
|
||||
const safeOrigins = [
|
||||
host,
|
||||
allowedHost,
|
||||
'localhost'
|
||||
]
|
||||
|
||||
if (!origin || !safeOrigins.includes(new URL(origin).hostname)) {
|
||||
socket.destroy()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user