Skip to content

fix(sigv4): Convert empty query parameters to null #6082

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion packages/aws_signature_v4/lib/src/signer/aws_signer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
final queryParameters = Map.of(canonicalRequest.queryParameters);
Map<String, String>? 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
Expand Down Expand Up @@ -284,6 +285,13 @@ 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
// 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.
Expand Down
Loading