http: server-side Digest Auth with htdigest file support - #3638
Conversation
|
Gemini says: PR 3638 Security & Robustness Analysis Critical Security Vulnerabilities
c Because wsi->http.digest_auth_nonce is NULL for any new connection (and is also set to NULL after the first request on a keep-alive connection), the strcmp is entirely skipped. The server then uses the client-provided nonce_in to verify the MD5 hash. An attacker can intercept any valid Authorization: Digest ... header and replay it on a newly established connection to bypass authentication entirely.
c An attacker who intercepts a valid authentication header for a low-privilege endpoint (e.g., /public) can send a request to a high-privilege endpoint (e.g., /secret) while keeping uri="/public" in the header. The server will compute a matching hash and grant access to /secret as the authenticated user. Robustness & Protocol Issues c In Digest Auth, a client is supposed to reuse the nonce for subsequent requests on the same connection by incrementing the nonce count (nc). By deleting the nonce, if the NULL-bypass vulnerability (Issue 1) is fixed, the server will force a new 401 challenge on every single request over a keep-alive connection, destroying performance.
c If the read() system call is interrupted by a signal (errno == EINTR), it will return -1. The code treats this as a failure and spuriously denies authentication instead of retrying the read. Recommendations Use Signed Nonces: Instead of random strings, generate nonces as base64(timestamp + ":" + HMAC(secret, timestamp)). This allows the server to verify the nonce was issued by itself and check expiration, without needing to store nonces per-wsi. |
99aac47 to
d56159a
Compare
|
I have addressed the Gemini comments except 5 which is an architectural change. |
|
It's definitely improved thanks. Gemini finds two problems
A good trick to know about LLMs is that if you simply open a new context and ask it to assess the output from the previous context, it won't feel any need to be consistent with the previous context's work, get defensive or freak out. It will just do what Gemini is doing for me when I ask it to assess it, directly to you. If there are gaping holes it will just shamelessly tell you [that patch it just made] has the following gaping holes... |
558a432 to
4e59faf
Compare
Add server-side HTTP Digest Auth support using the standard htdigest file format (username:realm:HA1_hex per line). - New mount auth mode LWSAUTHM_DIGEST_AUTH - New mount field basic_auth_realm for the auth realm - lws_check_digest_auth() parses Authorization: Digest headers and validates against the htdigest file - lws_unauthorised_digest_auth() sends 401 with a fresh random nonce - Nonce is stored per-wsi and verified on keep-alive retries - Constant-time response comparison via lws_timingsafe_bcmp - Wired into HTTP/1.1, HTTP/2 and WS upgrade paths - Added minimal example minimal-http-server-digestauth - LWS_WITH_HTTP_DIGEST_AUTH now implies LWS_WITH_HTTP_BASIC_AUTH so the shared lws_authorization_rewrite helper is available Signed-off-by: Bastian Germann <bage@debian.org> Co-developed-by: Claude Sonnet 4.6
|
feb2be6 to
b1c687c
Compare



Add server-side HTTP Digest Auth support using the standard htdigest file format (username:realm:HA1_hex per line).