From 85b4f65ecef5a327083f5019faa994763efedb30 Mon Sep 17 00:00:00 2001 From: Bala FA Date: Sat, 17 Aug 2024 16:46:17 +0530 Subject: [PATCH] SignV4: trim leading/trailing spaces in header value (#1578) Signed-off-by: Bala.FA --- api/src/main/java/io/minio/Signer.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/api/src/main/java/io/minio/Signer.java b/api/src/main/java/io/minio/Signer.java index 4752a76d6..c45f11f1a 100644 --- a/api/src/main/java/io/minio/Signer.java +++ b/api/src/main/java/io/minio/Signer.java @@ -134,12 +134,14 @@ private void setCanonicalHeaders(Set ignored_headers) { // https://docs.aws.amazon.com/general/latest/gr/sigv4-create-canonical-request.html // * Header having multiple values should be converted to comma separated values. // * Multi-spaced value of header should be trimmed to single spaced value. + // * Trim leading/trailing spaces in header value (As OkHttp trims leading/trailing spaces + // automatically, this is added for completion). this.canonicalHeaders.put( signedHeader, headers.values(name).stream() .map( value -> { - return value.replaceAll("( +)", " "); + return value.replaceAll("( +)", " ").trim(); }) .collect(Collectors.joining(","))); }