mirror of
https://github.com/streamwall/streamwall.git
synced 2026-01-24 22:22:50 -05:00
Validate Origin header for WebSocket requests
This commit is contained in:
@@ -15,6 +15,7 @@ import websocket from 'koa-easy-ws'
|
|||||||
const webDistPath = path.join(app.getAppPath(), 'web')
|
const webDistPath = path.join(app.getAppPath(), 'web')
|
||||||
|
|
||||||
function initApp({ username, password, baseURL, getInitialState, onMessage }) {
|
function initApp({ username, password, baseURL, getInitialState, onMessage }) {
|
||||||
|
const expectedOrigin = new URL(baseURL).origin
|
||||||
const sockets = new Set()
|
const sockets = new Set()
|
||||||
|
|
||||||
const app = new Koa()
|
const app = new Koa()
|
||||||
@@ -38,6 +39,11 @@ function initApp({ username, password, baseURL, getInitialState, onMessage }) {
|
|||||||
app.use(
|
app.use(
|
||||||
route.get('/ws', async (ctx) => {
|
route.get('/ws', async (ctx) => {
|
||||||
if (ctx.ws) {
|
if (ctx.ws) {
|
||||||
|
if (ctx.headers.origin !== expectedOrigin) {
|
||||||
|
ctx.status = 403
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
const ws = await ctx.ws()
|
const ws = await ctx.ws()
|
||||||
sockets.add(ws)
|
sockets.add(ws)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user