Skip to content

Commit

Permalink
fix(signature-v4): add hoistable headers config
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed Sep 30, 2024
1 parent 41a96d4 commit e10b2a9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .changeset/happy-emus-crash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"@smithy/signature-v4": minor
"@smithy/types": minor
---

configurable hoisted headers
3 changes: 2 additions & 1 deletion packages/signature-v4/src/SignatureV4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ export class SignatureV4 implements RequestPresigner, RequestSigner, StringSigne
unsignableHeaders,
unhoistableHeaders,
signableHeaders,
hoistableHeaders,
signingRegion,
signingService,
} = options;
Expand All @@ -146,7 +147,7 @@ export class SignatureV4 implements RequestPresigner, RequestSigner, StringSigne
}

const scope = createScope(shortDate, region, signingService ?? this.service);
const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders });
const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders, hoistableHeaders });

if (credentials.sessionToken) {
request.query[TOKEN_QUERY_PARAM] = credentials.sessionToken;
Expand Down
7 changes: 5 additions & 2 deletions packages/signature-v4/src/moveHeadersToQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import type { HttpRequest as IHttpRequest, QueryParameterBag } from "@smithy/typ
*/
export const moveHeadersToQuery = (
request: IHttpRequest,
options: { unhoistableHeaders?: Set<string> } = {}
options: { unhoistableHeaders?: Set<string>, hoistableHeaders?: Set<string> } = {}
): IHttpRequest & { query: QueryParameterBag } => {
const { headers, query = {} as QueryParameterBag } = HttpRequest.clone(request);
for (const name of Object.keys(headers)) {
const lname = name.toLowerCase();
if (lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
if (
(lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) ||
options.hoistableHeaders?.has(lname)
) {
query[name] = headers[name];
delete headers[name];
}
Expand Down
2 changes: 2 additions & 0 deletions packages/types/src/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ export interface RequestPresigningArguments extends RequestSigningArguments {
* lower case and then checked for existence in the unhoistableHeaders set.
*/
unhoistableHeaders?: Set<string>;

hoistableHeaders?: Set<string>;
}

/**
Expand Down

0 comments on commit e10b2a9

Please sign in to comment.