FantasticFiasco / aws-signature-version-4

The buttoned-up and boring, but deeply analyzed, implementation of SigV4 in .NET
Apache License 2.0
76 stars 18 forks source link

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

Open cfbao opened 5 hours ago

cfbao commented 5 hours ago

Describe the bug

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

To Reproduce

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.

github-actions[bot] commented 5 hours ago

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.