[pbs-devel] [PATCH proxmox v2 04/12] auth-api: use constant time comparison for csrf tokens

Stefan Sterz s.sterz at proxmox.com
Wed Mar 6 13:36:01 CET 2024


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 <s.sterz at proxmox.com>
---
 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 428d22a..e22eea2 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.");
     }
 
-- 
2.39.2





More information about the pbs-devel mailing list