Skip to content

Commit 154651e

Browse files
author
Bret Ambrose
committed
Move filter to a set, add user-agent to unsigned headers
1 parent 349b560 commit 154651e

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

aws-cpp-sdk-core/include/aws/core/auth/AWSAuthSigner.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include <aws/core/Region.h>
2121
#include <aws/core/utils/memory/AWSMemory.h>
22+
#include <aws/core/utils/memory/stl/AWSSet.h>
2223
#include <aws/core/utils/DateTime.h>
2324
#include <aws/core/utils/Array.h>
2425

@@ -130,13 +131,16 @@ namespace Aws
130131
Aws::String GenerateStringToSign(const Aws::String& dateValue, const Aws::String& simpleDate, const Aws::String& canonicalRequestHash) const;
131132
const Aws::Utils::ByteBuffer& ComputeLongLivedHash(const Aws::String& secretKey, const Aws::String& simpleDate) const;
132133

133-
static bool ShouldSignHeader(const Aws::String& header);
134+
bool ShouldSignHeader(const Aws::String& header) const;
134135

135136
std::shared_ptr<Auth::AWSCredentialsProvider> m_credentialsProvider;
136137
Aws::String m_serviceName;
137138
Aws::String m_region;
138139
Aws::UniquePtr<Aws::Utils::Crypto::Sha256> m_hash;
139140
Aws::UniquePtr<Aws::Utils::Crypto::Sha256HMAC> m_HMAC;
141+
142+
Aws::Set<Aws::String> m_unsignedHeaders;
143+
140144
//these next four fields are ONLY for caching purposes and do not change
141145
//the logical state of the signer. They are marked mutable so the
142146
//interface can remain const.

aws-cpp-sdk-core/source/auth/AWSAuthSigner.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ AWSAuthV4Signer::AWSAuthV4Signer(const std::shared_ptr<Auth::AWSCredentialsProvi
129129
m_region(region),
130130
m_hash(Aws::MakeUnique<Aws::Utils::Crypto::Sha256>(v4LogTag)),
131131
m_HMAC(Aws::MakeUnique<Aws::Utils::Crypto::Sha256HMAC>(v4LogTag)),
132+
m_unsignedHeaders({"user-agent", "x-amzn-trace-id"}),
132133
m_signPayloads(signPayloads),
133134
m_urlEscapePath(urlEscapePath)
134135
{
@@ -141,10 +142,10 @@ AWSAuthV4Signer::~AWSAuthV4Signer()
141142
// empty destructor in .cpp file to keep from needing the implementation of (AWSCredentialsProvider, Sha256, Sha256HMAC) in the header file
142143
}
143144

144-
// If this ever grows, convert to a static hash set initialized on InitAPI
145-
bool AWSAuthV4Signer::ShouldSignHeader(const Aws::String& header)
145+
146+
bool AWSAuthV4Signer::ShouldSignHeader(const Aws::String& header) const
146147
{
147-
return Aws::Utils::StringUtils::ToLower(header.c_str()) != Aws::String("x-amzn-trace-id");
148+
return m_unsignedHeaders.find(Aws::Utils::StringUtils::ToLower(header.c_str())) == m_unsignedHeaders.cend();
148149
}
149150

150151
bool AWSAuthV4Signer::SignRequest(Aws::Http::HttpRequest& request) const

0 commit comments

Comments
 (0)