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

Requests signed with "connection" header are rejected by AWS #1198

Closed
cfbao opened this issue Nov 17, 2024 · 7 comments · Fixed by #1207
Closed

Requests signed with "connection" header are rejected by AWS #1198

cfbao opened this issue Nov 17, 2024 · 7 comments · Fixed by #1207
Assignees
Labels
bug Something isn't working

Comments

@cfbao
Copy link
Contributor

cfbao commented Nov 17, 2024

Describe the bug

Requests with "connection" header are rejected by API Gateway HTTP API with IAM auth.

To Reproduce

  • Create an HTTP API in API Gateway (e.g. aws apigatewayv2 create-api)
  • Add IAM auth to this API
  • Send a request with "connection: keep-alive" header to this API, signed using this package with appropriate AWS creds
  • Receive 403 {"message":"Forbidden"} response

Sample code

Environment.SetEnvironmentVariable("AWS_PROFILE", "<my-profile>");

var client = new HttpClient();

var request = new HttpRequestMessage(HttpMethod.Get, "<api-gateway-http-api-url>")
{
	Headers = {
		{ "Connection", ["keep-alive"] },
	},
};

var response = await client.SendAsync(
	request,
	"<region>",
	"execute-api",
	Amazon.Runtime.FallbackCredentialsFactory.GetCredentials()
);

Console.WriteLine(response.StatusCode);
Console.WriteLine(await response.Content.ReadAsStringAsync());

Expected behavior

The request is accepted.

Desktop (please complete the following information):

Windows 10 & Amazon Linux 2023

Additional context

Although not explicitly documented, it looks like AWS simply doesn't accept some headers in the signature (they accept them in the request, but not in the signature calculation).
See an explicit case here with the "connection" header: https://repost.aws/questions/QUWXtAMiggShedgHG3hLl3tg/ses-sigv4-usage-update-connection-header

Other libraries (including AWS SDKs) deal with this by hardcoding (& maintaining) a list of unsignable headers and/or allow users to supply a list of headers to sign/not sign.
e.g.

Supporting customization also makes it possible to use this package in environments where a proxy may alter request headers.

@cfbao cfbao added the bug Something isn't working label Nov 17, 2024
Copy link
Contributor

Hi there and welcome to this repository!

A maintainer will be with you shortly, but first and foremost I would like to thank you for taking the time to report this issue. Quality is of the highest priority for us, and we would never release anything with known defects. We aim to do our best but unfortunately you are here because you encountered something we didn't expect. Lets see if we can figure out what went wrong and provide a remedy for it.

@FantasticFiasco
Copy link
Owner

Hi @cfbao.

Thanks for providing this information, in such detail. I'd propose to split this work into two separate sequential steps. The first one would implement a fix for the current problem, where defined headers are skipped. Optimally we would refer to the list of headers maintained by the C# SDK, but if that isn't possible we can probably implement some kind of test that is asserting that our list contains the same elements as the SDKs.

The second step would be to implement the feature of being able to configure a list of ignored headers, without breaking backward compatibility.

Does this sound like an acceptable plan, and would you like to contribute any of the steps?

@cfbao
Copy link
Contributor Author

cfbao commented Nov 23, 2024

Yeah that sounds reasonable.
I'm happy to contribute.

From a cursory look, it seems the list of ignored headers are private members in AWS .NET SDK, they also contain fewer elements than some other languages' SDKs, and notably doesn't contain the "connection" header. It's possible that due to the .NET SDK signing code never being exposed for external use, it can get away with a more limited list, which however won't be sufficient for this library.

I can put up a PR first and we can discuss the detailed approach there.

@FantasticFiasco
Copy link
Owner

Sounds awesome!

@FantasticFiasco
Copy link
Owner

I'm currently migrating to .NET 8, and then I'll release a new version for you.

Thank you for being patient, this took longer than it ought to have.

@FantasticFiasco
Copy link
Owner

Your fix has been included in v5.0.0. Thanks for the contribution!

@cfbao
Copy link
Contributor Author

cfbao commented Dec 23, 2024

Never apologize for OSS work!
Thanks for merging my PR. I also really appreciate the integration tests you added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants