Commit cc87a86
committed
fix(viz): reject cross-origin WebSocket handshakes
The `/ws` handler enforced "localhost bind only" but otherwise
accepted every incoming handshake without checking the Origin
header. Browsers deliberately allow cross-origin WebSocket
handshakes — the Same-Origin Policy does not apply there — so a
malicious page open in the same browser could connect to
ws://localhost:<port>/ws and immediately send a `cancel_session`
message, killing an active RLCR loop with zero auth prompt.
Reuse the existing `_origin_matches_request()` matcher (the same
logic that gates mutating HTTP routes via CSRF) before adding the
socket to `_ws_clients`. Connections without an Origin header are
treated as same-origin (curl, server-to-server callers): the
localhost bind already refuses non-loopback clients and the
Origin header is effectively mandatory from browsers on the
WebSocket handshake.
Fixes Codex review P1 on PR PolyArch#63 (cross-origin WebSocket
`cancel_session` vector).
Signed-off-by: Chao Liu <chao.liu.zevorn@gmail.com>1 parent 8de3545 commit cc87a86
1 file changed
Lines changed: 17 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1376 | 1376 | | |
1377 | 1377 | | |
1378 | 1378 | | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
| 1385 | + | |
| 1386 | + | |
| 1387 | + | |
| 1388 | + | |
| 1389 | + | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
| 1394 | + | |
| 1395 | + | |
1379 | 1396 | | |
1380 | 1397 | | |
1381 | 1398 | | |
| |||
0 commit comments