Skip to content

Commit

Permalink
skip unsignable headers
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbao committed Nov 30, 2024
1 parent 19e6039 commit 00f1a53
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/Private/CanonicalRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,24 @@ public static class CanonicalRequest
/// </summary>
public static string HeaderValueSeparator { get; set; } = ", ";

// Partial reference:
// https://github.com/smithy-lang/smithy-typescript/blob/430021abf44f8a4d6c24de2dfa25709bf91a92c8/packages/signature-v4/src/constants.ts#L19-L35
private static HashSet<string> UnsignableHeaders = new(StringComparer.OrdinalIgnoreCase) {
"authorization",
"connection",
"expect",
"keep-alive",
"proxy-authenticate",
"proxy-authorization",
"proxy-connection",
"range",
"te",
"trailer",
"transfer-encoding",
"upgrade",
HeaderKeys.XAmznTraceIdHeader,
};

/// <returns>
/// The first value is the canonical request, the second value is the signed headers.
/// </returns>
Expand Down Expand Up @@ -202,6 +220,11 @@ void AddHeader(KeyValuePair<string, IEnumerable<string>> header)
{
var headerName = FormatHeaderName(header.Key);

if (UnsignableHeaders.Contains(headerName))
{
return;
}

// Create header if it doesn't already exist
if (!sortedHeaders.TryGetValue(headerName, out var headerValues))
{
Expand Down

0 comments on commit 00f1a53

Please sign in to comment.