diff --git a/CHANGELOG.md b/CHANGELOG.md index dda648651..2f72b2083 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ ### Fixed - relay: fix timing attack on password authentication ([GHSA-vhv8-g2r9-cwcc](https://github.com/weechat/weechat/security/advisories/GHSA-vhv8-g2r9-cwcc)) +- api, relay: fix timing attack on TOTP validation ([GHSA-vhv8-g2r9-cwcc](https://github.com/weechat/weechat/security/advisories/GHSA-vhv8-g2r9-cwcc)) - relay: limit size of decompressed websocket frame with permessage-deflate to prevent memory exhaustion ([GHSA-v2v4-45wm-5cr3](https://github.com/weechat/weechat/security/advisories/GHSA-v2v4-45wm-5cr3)) - relay/weechat: fix empty buffers in client when WeeChat is running on Solaris/illumos - build: fix build on Solaris/illumos (issue #2251) diff --git a/src/core/core-crypto.c b/src/core/core-crypto.c index 8c34d1fb7..a81664014 100644 --- a/src/core/core-crypto.c +++ b/src/core/core-crypto.c @@ -662,15 +662,18 @@ weecrypto_totp_validate (const char *secret_base32, time_t totp_time, otp_ok = 0; + /* + * Compare in constant time and never break early: a non-constant + * compare and an early exit on match would let an observer measure + * how many digits of the expected OTP they got right and which + * time-window offset matched. + */ for (i = moving_factor - window; i <= moving_factor + window; i++) { rc = weecrypto_totp_generate_internal (secret, length_secret, i, digits, str_otp); - if (rc && (strcmp (str_otp, otp) == 0)) - { + if (rc && (string_memcmp_constant_time (str_otp, otp, digits) == 0)) otp_ok = 1; - break; - } } free (secret);