mirror of
https://github.com/vuejs/vue-cli.git
synced 2026-04-27 15:30:02 -05:00
fix(ws): stricter check on web socket origins
To avoid CORS vulnerabilities
This commit is contained in:
@@ -6,10 +6,14 @@ const { setNotificationCallback } = require('@vue/cli-ui/apollo-server/util/noti
|
||||
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