Skip to content

Commit

Permalink
fix(ws): stricter check on web socket origins
Browse files Browse the repository at this point in the history
To avoid CORS vulnerabilities
  • Loading branch information
sodatea committed Oct 11, 2021
1 parent a8b74b4 commit c3be5ee
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions packages/@vue/cli/lib/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
Expand Down

0 comments on commit c3be5ee

Please sign in to comment.