server: a wrong api key closes the connection it guessed on

A failed authentication answered 401 and kept the connection alive, so a
client guessing credentials over one keep-alive paid for the socket once
and then streamed a thousand tries down it. The gate can refuse the
request; it was not refusing the session.

The 401 now carries Connection: close. A guessing client pays a fresh
connect -- and on TLS, a fresh handshake -- per guess, while every
correctly-keyed request keeps its warm connection untouched.
This commit is contained in:
fl0l0u committed 2026-11-15 20:38:10 +00:00
1 parent e30ada33e8
commit 9bfdd95cb6
1 file changed
+3
+3
View File
@@ -763,6 +763,9 @@ int HttpTransport::serve(const Router& router, const TransportOptions& o) {
hres.status = 401;
hres.set_content(error_body(p, 401, "authentication_error", "invalid api key"),
"application/json");
/* Close over it: a credential-guessing client should pay a fresh TLS/TCP setup
* per try, not one keep-alive for a thousand. */
hres.set_header("Connection", "close");
return false;
}
}