From 8609fb58efe1ee1e435c5114840be0da446b2382 Mon Sep 17 00:00:00 2001 From: Stefan Sterz Date: Wed, 6 Mar 2024 13:36:01 +0100 Subject: [PATCH] auth-api: use constant time comparison for csrf tokens by using openssl's `memcmp::eq()` we can avoid potential side-channel attack on the csrf token comparison. this comparison's runtime only depends on the length of the two byte vectors, not their contents. Signed-off-by: Stefan Sterz --- proxmox-auth-api/src/api/access.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/proxmox-auth-api/src/api/access.rs b/proxmox-auth-api/src/api/access.rs index 428d22a8..e22eea24 100644 --- a/proxmox-auth-api/src/api/access.rs +++ b/proxmox-auth-api/src/api/access.rs @@ -286,14 +286,15 @@ fn verify_csrf_prevention_token_do( } let timestamp = parts.pop_front().unwrap(); - let sig = parts.pop_front().unwrap(); + let sig = parts.pop_front().unwrap().as_bytes(); let ttime = i64::from_str_radix(timestamp, 16) .map_err(|err| format_err!("timestamp format error - {}", err))?; let digest = compute_csrf_secret_digest(ttime, secret, userid); + let digest = digest.as_bytes(); - if digest != sig { + if digest.len() != sig.len() || !openssl::memcmp::eq(digest, sig) { bail!("invalid signature."); }