fix: AWS credential signing http request - convert form to body #14060
+59
−2
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.
Summary
The code that signs a request using AWS credentials does not correctly handle objects passed from HTTP Request.
There is an in-progress refactor, as already worked around in #5751 / #8563 regarding the HTTP Request Options types in use. HTTP Request uses IRequestOptions, but AWS Credentials uses IHttpOptions, which is the target for the refactor, and compatible with an AWS Request object, which is what the signing code is expecting.
The problem is that HTTP Request converts or passes form data as a form property of the object. This is safely ignored by the type management and object processing, but it renders the content to sign incomplete. AWS SigV4 expects and requires the body to be part of the signing request (as well as the content-type header), and is ignorant of the form property.
Unless the form data is converted (back) to body content for the signing request, the result will be an incorrect signature that AWS will reject.
This bug can be simply reproduced:
POST
https://iam.amazonaws.com
Predefined credential type
AWS
<select valid credential>
false
false
true
Form Urlencoded
Using single field
Action=ListUsers&Version=2010-05-08
The resulting error will be:
This PR adopts the same workaround approach as used previously to take what it is given, and modify it accordingly so that the signing is successful.
form
content is converted tobody
content, and to ensure it is present as required (and with the right normalised lower casing), if the content-type header is not present it is set to application/x-www-form-urlencoded.Related Linear tickets, Github issues, and Community forum posts
Relates to #8563
Relates to #5751
Relates (kinda) to #14037
Review / Merge checklist
release/backport
(if the PR is an urgent fix that needs to be backported)