Merge branch 'worktree-agent-a12c20b7597e0869e'

This commit is contained in:
2026-10-25 20:28:07 +01:00
2 changed files with 21 additions and 0 deletions
@@ -58,6 +58,20 @@ HandshakeResult HandshakeValidator::validate(
shared::set_header(r.response, "Sec-WebSocket-Version", "13");
return r;
}
std::string origin = shared::header_first(req, "Origin");
if (!origin.empty()) {
bool allowed = false;
for (const std::string& o : config_.allowed_origins) {
if (o == origin) {
allowed = true;
break;
}
}
if (!allowed) {
return fail("Origin not allowed-listed");
}
}
std::string picked;
std::string asked = shared::header_first(req, "Sec-WebSocket-Protocol");
if (!asked.empty()) {
@@ -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 {