[pbs-devel] [PATCH proxmox v2 04/12] auth-api: use constant time comparison for csrf tokens
Max Carrara
m.carrara at proxmox.com
Thu Mar 7 11:17:23 CET 2024
On 3/6/24 13:36, Stefan Sterz wrote:
> 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();
Thought these `unwrap()`s here seemed a bit spicy at first, but we do
check for the length of `parts` beforehand, so this is fine.
>
> 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.");
> }
>
More information about the pbs-devel
mailing list