From f1ae2ae23b2499890770fa966ee72da78b367774 Mon Sep 17 00:00:00 2001 From: Simon Kendler Date: Sun, 15 Mar 2026 18:53:17 +0100 Subject: [PATCH] Use SORT_STRING for canonicalized query generation, add test new behavior --- .../chore-error-description-support.json | 7 ------- .changes/nextrelease/fix-canonicalized-query.json | 7 +++++++ src/Signature/SignatureV4.php | 2 +- tests/Signature/SignatureV4Test.php | 14 ++++++++++++++ 4 files changed, 22 insertions(+), 8 deletions(-) delete mode 100644 .changes/nextrelease/chore-error-description-support.json create mode 100644 .changes/nextrelease/fix-canonicalized-query.json diff --git a/.changes/nextrelease/chore-error-description-support.json b/.changes/nextrelease/chore-error-description-support.json deleted file mode 100644 index 92044833a3..0000000000 --- a/.changes/nextrelease/chore-error-description-support.json +++ /dev/null @@ -1,7 +0,0 @@ -[ - { - "type": "enhancement", - "category": "", - "description": "Handles errors that comes in the `error_description` field, specifically how SSO-OIDC service has it modeled." - } -] diff --git a/.changes/nextrelease/fix-canonicalized-query.json b/.changes/nextrelease/fix-canonicalized-query.json new file mode 100644 index 0000000000..d79a6b2acc --- /dev/null +++ b/.changes/nextrelease/fix-canonicalized-query.json @@ -0,0 +1,7 @@ +[ + { + "type": "bugfix", + "category": "Signature", + "description": "Fixes bug in canonicalized query generation when dealing with numeric values" + } +] diff --git a/src/Signature/SignatureV4.php b/src/Signature/SignatureV4.php index 48eb6b9f02..bb95b0556a 100644 --- a/src/Signature/SignatureV4.php +++ b/src/Signature/SignatureV4.php @@ -356,7 +356,7 @@ private function getCanonicalizedQuery(array $query) if (!is_array($v)) { $qs .= rawurlencode($k) . '=' . rawurlencode($v !== null ? $v : '') . '&'; } else { - sort($v); + sort($v, SORT_STRING); foreach ($v as $value) { $qs .= rawurlencode($k) . '=' . rawurlencode($value !== null ? $value : '') . '&'; } diff --git a/tests/Signature/SignatureV4Test.php b/tests/Signature/SignatureV4Test.php index f4bc36eb16..d2196fb84d 100644 --- a/tests/Signature/SignatureV4Test.php +++ b/tests/Signature/SignatureV4Test.php @@ -367,6 +367,20 @@ public function testCanonicalQuerySortingOccursAfterEncoding() $this->assertSame($expectedSigned, Psr7\Message::toString($signed)); } + public function testCanonicalizedQuerySortingParameterMultiOccurrenceNumericValues(): void + { + $signature = new SignatureV4('service', 'region'); + + $canonicalizedQuery = new \ReflectionMethod($signature, 'getCanonicalizedQuery'); + $parameters = [ + 'parameter1' => ['100', '50'], + 'parameter2' => 'value', + ]; + + $query = $canonicalizedQuery->invoke($signature, $parameters); + $this->assertSame('parameter1=100¶meter1=50¶meter2=value', $query); + } + public function testEnsuresContentSha256CanBeCalculated() { $this->expectException(\Aws\Exception\CouldNotCreateChecksumException::class);