1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-29 14:26:39 +02:00

relay: fix timing attack on password authentication (GHSA-vhv8-g2r9-cwcc)

The relay authentication used non-constant-time comparisons (strcasecmp,
strcmp) to verify password hashes and plaintext passwords, allowing an
attacker to derive the expected hash byte-by-byte from response timing
and then authenticate without knowing the password.

- SHA/PBKDF2 hex hash comparisons: normalize the client-supplied hash to
  uppercase and compare in constant time over the fixed expected length.
- Plaintext password comparison: HMAC-SHA256 both passwords with a fresh
  per-call random key and compare the fixed-size MACs in constant time,
  hiding both per-byte timing and the password length.

Add string_memcmp_constant_time helper in core, exposed via the plugin
API. Bump WEECHAT_PLUGIN_API_VERSION accordingly.
This commit is contained in:
Sébastien Helleu
2026-05-30 19:00:59 +02:00
parent 35699ea802
commit 30230498b2
7 changed files with 158 additions and 11 deletions
+32
View File
@@ -800,6 +800,38 @@ TEST(CoreString, StringComparison)
LONGS_EQUAL(-2, string_strcmp_ignore_chars ("è", "ê", "", 1));
}
/*
* Test functions:
* string_memcmp_constant_time
*/
TEST(CoreString, MemcmpConstantTime)
{
/* NULL handling */
LONGS_EQUAL(0, string_memcmp_constant_time (NULL, NULL, 0));
LONGS_EQUAL(0, string_memcmp_constant_time (NULL, NULL, 4));
LONGS_EQUAL(1, string_memcmp_constant_time (NULL, "abcd", 4));
LONGS_EQUAL(1, string_memcmp_constant_time ("abcd", NULL, 4));
/* zero-size compare always equal */
LONGS_EQUAL(0, string_memcmp_constant_time ("", "", 0));
LONGS_EQUAL(0, string_memcmp_constant_time ("abc", "xyz", 0));
/* equal areas */
LONGS_EQUAL(0, string_memcmp_constant_time ("abcd", "abcd", 4));
LONGS_EQUAL(0, string_memcmp_constant_time ("\x00\x01\x02\xff",
"\x00\x01\x02\xff", 4));
/* differing areas (first / middle / last byte) */
LONGS_EQUAL(1, string_memcmp_constant_time ("Xbcd", "abcd", 4));
LONGS_EQUAL(1, string_memcmp_constant_time ("aXcd", "abcd", 4));
LONGS_EQUAL(1, string_memcmp_constant_time ("abcX", "abcd", 4));
LONGS_EQUAL(1, string_memcmp_constant_time ("abcd", "abce", 4));
/* only compares "size" bytes, ignores trailing content */
LONGS_EQUAL(0, string_memcmp_constant_time ("abcd", "abcz", 3));
}
/*
* Test functions:
* string_strcasestr