Skip to content
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

Disable signing the payload when UnsignedPayload is set to true #3596

Conversation

muhammad-othman
Copy link
Member

@muhammad-othman muhammad-othman commented Jan 3, 2025

Description

As part of SigV4a as a trait SEP, this PR disables signing the payload when UnsignedPayload is set to true based on the following paragraph from the SEP

If the `unsignedPayload` trait is present and has a value of true, then the HTTP payload must not be signed. 
For sigv4 and sigv4a, the static string `UNSIGNED-PAYLOAD` must be used in place of the payload hash.

Motivation and Context

DOTNET-7858

Testing

  • Tested the affected actions with body included and validated that the behavior didn't change after disable signing the payload.
  • DRY_RUN-58765492-6dda-400f-bad6-dc4ae269bff4

generator/ServiceClientGeneratorLib/Operation.cs Outdated Show resolved Hide resolved
@@ -499,7 +499,7 @@ public static string SetRequestBodyHash(IRequest request, string chunkedBodyHash
public static string SetRequestBodyHash(IRequest request, bool signPayload, string chunkedBodyHash, int signatureLength)
{
// If unsigned payload, set the appropriate magic string in the header and return it
if (request.DisablePayloadSigning != null ? request.DisablePayloadSigning.Value : !signPayload)
if (request.UnsignedPayload || request.DisablePayloadSigning.GetValueOrDefault() || !signPayload)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetValueOrDefault will return false for the default value of DisablePayloadSigning. In that case it isn't part of the condition as it was before because before it would use the flag if it was false or true set explicitly and only use !signPayload if it was null. It didn't have to be true. Are you sure this logic is correct?

There is at least one test that sets DisablePayloadSigning to false explicitly and would still go into the if logic before.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this one since I did miss it and I didn't think it through, though I think (request.UnsignedPayload || request.DisablePayloadSigning.GetValueOrDefault() || !signPayload) is more appropriate since signPayload comes from the Signer constructor and I don't think it should be overridden if the user did set DisablePayloadSigning to false, but this isn't related to UnsignedPayload change and and keeping the original behavior seems reasonable.

/// <summary>
/// Gets and sets a flag that indicates if the payload shouldn't be signed.
/// </summary>
bool UnsignedPayload
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we can't use the existing DisablePayloadSigning property? It's already in IRequest and set in a few places: https://github.com/search?q=repo%3Aaws%2Faws-sdk-net%20DisablePayloadSigning&type=code

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason that I didn't want to use it is that it is documented that it is special for S3 and there is this logic around it that isn't related to the SEP
image
image

Copy link
Contributor

@boblodgett boblodgett Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could change the docs to not be S3 specific. Also, perhaps that special logic should be in the SEP if it isn't. Not signing the request and not using https was considered to not have enough validation and the same would apply to any other request if it wasn't S3.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree this should be called out in the SEP (I'd be surprised if we were OK with sending unsigned payloads over plain HTTP...)

I'd vote to keep the existing property and make it generic instead of adding a new one.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It kinda felt like a breaking change when changing the behavior of DisablePayloadSigning in this way, but since we going to release this in v4 then it should be fine to change it.

@muhammad-othman muhammad-othman force-pushed the muhamoth/DOTNET-7858-UnsignedPayload-Disable-signing-the-payload branch from 15afc77 to 3af208a Compare January 6, 2025 16:10
@muhammad-othman muhammad-othman force-pushed the muhamoth/DOTNET-7858-UnsignedPayload-Disable-signing-the-payload branch from 3af208a to 67e69bd Compare January 6, 2025 20:19
{
"core": {
"changeLogMessages": [
"Disable signing the payload when UnsignedPayload is set to true"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It isn't completely clear what UnsignedPayload this is now because the property was removed. Unless this is still referencing the trait in the model. This should probably be clarified:

Disable signing the payload when the operation is modeled as having an UnsignedPayload set to true.

Or

Disable signing the payload when the operation is modeled as having an unsigned payload.

@muhammad-othman muhammad-othman force-pushed the muhamoth/DOTNET-7858-UnsignedPayload-Disable-signing-the-payload branch from 311920a to 494c01f Compare January 7, 2025 21:49
@muhammad-othman muhammad-othman merged commit a75cfac into v4-development Jan 7, 2025
1 check passed
@muhammad-othman muhammad-othman deleted the muhamoth/DOTNET-7858-UnsignedPayload-Disable-signing-the-payload branch January 7, 2025 22:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants