From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id E5AE5B8295 for ; Thu, 7 Mar 2024 11:17:25 +0100 (CET) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id C7431346C8 for ; Thu, 7 Mar 2024 11:17:25 +0100 (CET) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Thu, 7 Mar 2024 11:17:24 +0100 (CET) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 880FD42901 for ; Thu, 7 Mar 2024 11:17:24 +0100 (CET) Message-ID: Date: Thu, 7 Mar 2024 11:17:23 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: pbs-devel@lists.proxmox.com References: <20240306123609.164021-1-s.sterz@proxmox.com> <20240306123609.164021-5-s.sterz@proxmox.com> From: Max Carrara In-Reply-To: <20240306123609.164021-5-s.sterz@proxmox.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.002 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [access.rs] Subject: Re: [pbs-devel] [PATCH proxmox v2 04/12] auth-api: use constant time comparison for csrf tokens X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Mar 2024 10:17:25 -0000 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 > --- > 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."); > } >