From 6576382cedeed41b82055e14002b3071dd15188f Mon Sep 17 00:00:00 2001 From: Tyler-Larkin Date: Wed, 19 Mar 2025 13:27:42 -0700 Subject: [PATCH 1/3] fix(sigv4): Convert empty query parameters to null --- packages/aws_signature_v4/lib/src/signer/aws_signer.dart | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/aws_signature_v4/lib/src/signer/aws_signer.dart b/packages/aws_signature_v4/lib/src/signer/aws_signer.dart index b9c11023eb8..3efb6964254 100644 --- a/packages/aws_signature_v4/lib/src/signer/aws_signer.dart +++ b/packages/aws_signature_v4/lib/src/signer/aws_signer.dart @@ -256,7 +256,7 @@ class AWSSigV4Signer { }) { // The signing process requires component keys be encoded. However, the // actual HTTP request should have the pre-encoded keys. - final queryParameters = Map.of(canonicalRequest.queryParameters); + Map? queryParameters = Map.of(canonicalRequest.queryParameters); // Similar to query parameters, some header values are canonicalized for // signing. However their original values should be included in the @@ -284,6 +284,13 @@ class AWSSigV4Signer { } } + // Web sends an OPTIONS request to verify CORS compatability with the URL. + // A 404 can be returned if the URL contains unexpected query Parameters + // and URI.toString() appends a "?" to the URL for an empty query parameter + // map. Set the query parameter to null if it empty to avoid this. + // https://github.com/dart-lang/sdk/issues/51656 + queryParameters = queryParameters.isEmpty ? null : queryParameters; + // On Web, sign the `Host` and `Content-Length` headers, but do not send // them as part of the request, since these will be included automatically // by the browser and most now restrict the ability to set them via code. From d03266675ec095f75a7e438315de0c37fb8e3efb Mon Sep 17 00:00:00 2001 From: Tyler-Larkin Date: Wed, 19 Mar 2025 13:34:06 -0700 Subject: [PATCH 2/3] chore(): fixed Typo --- packages/aws_signature_v4/lib/src/signer/aws_signer.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/aws_signature_v4/lib/src/signer/aws_signer.dart b/packages/aws_signature_v4/lib/src/signer/aws_signer.dart index 3efb6964254..682aea2b601 100644 --- a/packages/aws_signature_v4/lib/src/signer/aws_signer.dart +++ b/packages/aws_signature_v4/lib/src/signer/aws_signer.dart @@ -284,7 +284,7 @@ class AWSSigV4Signer { } } - // Web sends an OPTIONS request to verify CORS compatability with the URL. + // Web sends an OPTIONS request to verify CORS compatibility with the URL. // A 404 can be returned if the URL contains unexpected query Parameters // and URI.toString() appends a "?" to the URL for an empty query parameter // map. Set the query parameter to null if it empty to avoid this. From f766e74e3ef4434124a19749996582fdabb6abb0 Mon Sep 17 00:00:00 2001 From: Tyler-Larkin Date: Wed, 19 Mar 2025 13:39:43 -0700 Subject: [PATCH 3/3] chore(): formatted file --- packages/aws_signature_v4/lib/src/signer/aws_signer.dart | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/aws_signature_v4/lib/src/signer/aws_signer.dart b/packages/aws_signature_v4/lib/src/signer/aws_signer.dart index 682aea2b601..7c49705f7a3 100644 --- a/packages/aws_signature_v4/lib/src/signer/aws_signer.dart +++ b/packages/aws_signature_v4/lib/src/signer/aws_signer.dart @@ -256,7 +256,8 @@ class AWSSigV4Signer { }) { // The signing process requires component keys be encoded. However, the // actual HTTP request should have the pre-encoded keys. - Map? queryParameters = Map.of(canonicalRequest.queryParameters); + Map? queryParameters = + Map.of(canonicalRequest.queryParameters); // Similar to query parameters, some header values are canonicalized for // signing. However their original values should be included in the @@ -285,8 +286,8 @@ class AWSSigV4Signer { } // Web sends an OPTIONS request to verify CORS compatibility with the URL. - // A 404 can be returned if the URL contains unexpected query Parameters - // and URI.toString() appends a "?" to the URL for an empty query parameter + // A 404 can be returned if the URL contains unexpected query Parameters + // and URI.toString() appends a "?" to the URL for an empty query parameter // map. Set the query parameter to null if it empty to avoid this. // https://github.com/dart-lang/sdk/issues/51656 queryParameters = queryParameters.isEmpty ? null : queryParameters;