]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: h1: use ha_random64_pair_hashed() for the WebSocket key
authorWilly Tarreau <w@1wt.eu>
Mon, 25 May 2026 16:23:30 +0000 (18:23 +0200)
committerWilly Tarreau <w@1wt.eu>
Tue, 26 May 2026 11:13:24 +0000 (13:13 +0200)
Instead of using two consecutive calls to ha_random64(), let's use the
cleaner and safer ha_random64_pair_hashed(). This way the internal
PRNG state will not leak into the emitted headers.

src/h1.c

index 8edc816f5786a41159f108261f882fc2714d38ae..98bb492b25dc7fd6c06a8aa30db91e9f07f09ce2 100644 (file)
--- a/src/h1.c
+++ b/src/h1.c
@@ -1272,9 +1272,10 @@ int h1_headers_to_hdr_list(char *start, const char *stop,
 void h1_generate_random_ws_input_key(char key_out[25])
 {
        /* generate a random websocket key */
-       const uint64_t rand1 = ha_random64(), rand2 = ha_random64();
+       uint64_t rand1, rand2;
        char key[16];
 
+       ha_random64_pair_hashed(&rand1, &rand2);
        memcpy(key, &rand1, 8);
        memcpy(&key[8], &rand2, 8);
        a2base64(key, 16, key_out, 25);