From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 8B14B1FF0AB for ; Wed, 07 Oct 2026 14:34:36 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 888652144E; Wed, 07 Oct 2026 14:34:33 +0200 (CEST) From: Christian Ebner To: pbs-devel@lists.proxmox.com Subject: [PATCH proxmox 1/3] s3-client: fix header and query parameter sorting during aws sign v4 Date: Wed, 7 Oct 2026 14:34:04 +0200 Message-ID: <20261007123406.429342-2-c.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261007123406.429342-1-c.ebner@proxmox.com> References: <20261007123406.429342-1-c.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1791376468359 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.575 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) KAM_SHORT 0.001 Use of a URL Shortener for very short URL RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: 4J4HNRZEBG6FYUF6DQ6EP7XXJMM6BV2D X-Message-ID-Hash: 4J4HNRZEBG6FYUF6DQ6EP7XXJMM6BV2D X-MailFrom: c.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox Backup Server development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Currently, canonical headers and query parameters are incorrectly sorted by combined `key:value` or `key=value` strings respectively, instead of by key only. This could result in signature mismatches with the S3 API. Fixes: 7c6ef846 ("s3 client: implement AWS signature v4 request authentication") Signed-off-by: Christian Ebner --- proxmox-s3-client/src/aws_sign_v4.rs | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/proxmox-s3-client/src/aws_sign_v4.rs b/proxmox-s3-client/src/aws_sign_v4.rs index f172b4b4..54f4e54e 100644 --- a/proxmox-s3-client/src/aws_sign_v4.rs +++ b/proxmox-s3-client/src/aws_sign_v4.rs @@ -31,11 +31,11 @@ pub(crate) fn aws_sign_v4_signature( // headers are required. however, in order to prevent data tampering, you should consider // including all the headers in the signature calculation." // See https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html - let mut canonical_headers = Vec::new(); - let mut signed_headers = Vec::new(); - for (key, value) in request.headers() { - canonical_headers.push(format!( - "{}:{}", + let req_headers = request.headers(); + let mut headers = Vec::with_capacity(req_headers.len()); + + for (key, value) in req_headers { + headers.push(( // Header name has to be lower case, key.as_str() does guarantee that, see // https://docs.rs/http/0.2.0/http/header/struct.HeaderName.html key.as_str(), @@ -43,14 +43,27 @@ pub(crate) fn aws_sign_v4_signature( // https://docs.rs/http/0.2.0/http/header/struct.HeaderValue.html value.to_str()?, )); - signed_headers.push(key.as_str()); } - canonical_headers.sort(); - signed_headers.sort(); + + headers.sort_unstable_by(|a, b| a.0.cmp(b.0)); + + let mut canonical_headers = Vec::with_capacity(headers.len()); + let mut signed_headers = Vec::with_capacity(headers.len()); + for (key, value) in headers { + canonical_headers.push(format!("{key}:{value}")); + signed_headers.push(key); + } let signed_headers_string = signed_headers.join(";"); let mut canonical_queries = Url::parse(&request.uri().to_string())? .query_pairs() + .map(|(key, value)| (key.to_string(), value.to_string())) + .collect::>(); + + canonical_queries.sort_unstable_by(|a, b| a.0.cmp(&b.0)); + + let canonical_queries = canonical_queries + .into_iter() .map(|(key, value)| { format!( "{}={}", @@ -59,7 +72,6 @@ pub(crate) fn aws_sign_v4_signature( ) }) .collect::>(); - canonical_queries.sort(); let canonical_request = format!( "{}\n{}\n{}\n{}\n\n{}\n{}", -- 2.47.3