fix(realtime): reject WebSocket handshakes from unlisted Origins (CSWSH)

HandshakeValidator::validate never read the Origin header, so any
cross-site page could open a WebSocket to the app and ride a victim's
cookies (CWE-1385, the CVE-2024-23898 class). Add HandshakeConfig's
allowed_origins exact-match list and reject the handshake when an
Origin header is present but not allow-listed. Empty/unset
allowed_origins is closed by default (any Origin present is
rejected), matching CorsPolicy's closed-by-default convention.
Requests with no Origin header (non-browser clients) are unaffected.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 20:06:04 +01:00
co-authored by Claude Sonnet 5
parent 16a0bb0de4
commit 9733d63e6c
2 changed files with 21 additions and 0 deletions
@@ -20,6 +20,13 @@ struct HandshakeConfig {
// no protocol echoed.
std::vector<std::string> subprotocols;
bool require_subprotocol = false;
// Exact-match allow-list for the browser-sent Origin header (CSWSH
// defense, CWE-1385). Empty means closed: any request that carries an
// Origin header is rejected, matching CorsPolicy's closed-by-default
// convention (src/security/guard/CorsPolicy.h). A request with no
// Origin header at all (non-browser clients) is not checked here.
std::vector<std::string> allowed_origins;
};
struct HandshakeResult {