Fix SigV4 signature for URIs with literal query parameters#674
Merged
Alan4506 merged 3 commits intosmithy-lang:developfrom Mar 31, 2026
Merged
Fix SigV4 signature for URIs with literal query parameters#674Alan4506 merged 3 commits intosmithy-lang:developfrom
Alan4506 merged 3 commits intosmithy-lang:developfrom
Conversation
jonathan343
requested changes
Mar 30, 2026
Contributor
jonathan343
left a comment
There was a problem hiding this comment.
Looks good, thanks @Alan4506!
Can you add some unit tests in tests/unit/test_signers.py for this case to prevent any regressions? It would look something like below:
Note: Both
TestSigV4SignerandTestAsyncSigV4Signeralready exist.
class TestSigV4Signer:
SIGV4_SYNC_SIGNER = SigV4Signer()
def test_format_canonical_query_keeps_blank_values(self) -> None:
canonical_query = self.SIGV4_SYNC_SIGNER._format_canonical_query(
query="foo=bar&baz="
)
assert canonical_query == "foo=bar&baz="
class TestAsyncSigV4Signer:
SIGV4_ASYNC_SIGNER = AsyncSigV4Signer()
async def test_format_canonical_query_keeps_blank_values(self) -> None:
canonical_query = await self.SIGV4_ASYNC_SIGNER._format_canonical_query(
query="foo=bar&baz="
)
assert canonical_query == "foo=bar&baz="
jonathan343
approved these changes
Mar 31, 2026
Contributor
jonathan343
left a comment
There was a problem hiding this comment.
LGTM. Thanks @Alan4506!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When generating a client for Amazon Q Business using smithy-python, the
ChatSyncoperation fails withInvalidSignatureException. The same request succeeds with boto3 using identical credentials and endpoint.The root cause is that
ChatSynchas a literal query parameter in its Smithy HTTP trait:Link to the model file: https://github.com/aws/api-models-aws/blob/9eafbc359b1c6a7187ac921009b9eef85de71d91/models/qbusiness/service/2023-11-27/qbusiness-2023-11-27.json#L2244-L2250
The
?syncquery parameter (no=sign, no value) is dropped during SigV4 canonical query string computation.parse_qsl("sync")returns[]because it ignores keys without values by default. The server includessync=in its canonical query string, so the signatures don't match.Fix
Add
keep_blank_values=Trueto both sync and async_format_canonical_querymethods. This makesparse_qsl("sync", keep_blank_values=True)return[('sync', '')], which correctly producessync=in the canonical query string.Testing
InvalidSignatureException200 OKwith valid responseBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.