fix(signer): send SigV4 X-Amz-Date in trailer requests (#9886)

streaming_unsigned_v4 overwrote the X-Amz-Date set by sign_v4_inner with an extended RFC 3339 timestamp, so requests signed with a trailer were sent with a date that differs from the signed one. Use the SigV4 basic format so the sent header matches the signature.
This commit is contained in:
Metin Binbir
2026-12-03 20:46:32 +08:00
committed by GitHub
parent 33bd349bee
commit 88fcc7499a
2 changed files with 41 additions and 1 deletions
@@ -31,7 +31,7 @@ pub fn streaming_unsigned_v4<B>(
headers.insert("X-Amz-Security-Token", token_value);
}
let format = format_description!("[year]-[month]-[day]T[hour]:[minute]:[second].[subsecond]Z");
let format = format_description!("[year][month][day]T[hour][minute][second]Z");
if let Ok(date) = req_time.format(&format)
&& let Ok(date_value) = HeaderValue::from_str(&date)
{
@@ -48,6 +48,20 @@ mod tests {
use http::request;
use rustfs_s3_types::Body;
use time::OffsetDateTime;
use time::macros::datetime;
#[test]
fn streaming_unsigned_v4_uses_sigv4_amz_date_format() {
let req = request::Request::builder()
.method(http::Method::PUT)
.uri("https://bucket.example.com/object")
.body(Body::empty())
.expect("request should build");
let req = streaming_unsigned_v4(req, "", 0, datetime!(2013-05-24 01:02:03.456 UTC));
assert_eq!(req.headers().get("X-Amz-Date"), Some(&http::HeaderValue::from_static("20130524T010203Z")));
}
#[test]
fn streaming_unsigned_v4_skips_invalid_session_token_header() {
+26
View File
@@ -1176,6 +1176,32 @@ mod tests {
);
}
#[test]
fn sign_v4_trailer_sends_the_signed_amz_date() {
let mut req = request::Request::builder()
.method(http::Method::PUT)
.uri("http://examplebucket.s3.amazonaws.com/object")
.body(Body::empty())
.unwrap();
let headers = req.headers_mut();
headers.insert("host", HeaderValue::from_static("examplebucket.s3.amazonaws.com"));
headers.insert(
"x-amz-content-sha256",
HeaderValue::from_static(crate::constants::UNSIGNED_PAYLOAD_TRAILER),
);
let mut trailer = HeaderMap::new();
trailer.insert("x-amz-checksum-crc32", HeaderValue::from_static("AAAAAA=="));
let signed = try_sign_v4_trailer(req, "rustfsadmin", "rustfsadmin", "", "us-east-1", trailer).unwrap();
let amz_date = signed.headers().get("X-Amz-Date").unwrap().to_str().unwrap();
time::PrimitiveDateTime::parse(amz_date, format_description!("[year][month][day]T[hour][minute][second]Z"))
.expect("X-Amz-Date must use the SigV4 basic format");
let authorization = signed.headers().get(http::header::AUTHORIZATION).unwrap().to_str().unwrap();
let scope_date = format!("/{}/us-east-1/s3/aws4_request", &amz_date[..8]);
assert!(authorization.contains(&scope_date), "{authorization} must be scoped to {amz_date}");
}
fn build_request_with_invalid_header_value(uri: &str) -> request::Request<Body> {
let mut req = request::Request::builder()
.method(http::Method::GET)