@smithy/signature-v4 4.1.3 → 4.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist-cjs/index.js CHANGED
@@ -136,22 +136,20 @@ var import_util_uri_escape = require("@smithy/util-uri-escape");
136
136
  var getCanonicalQuery = /* @__PURE__ */ __name(({ query = {} }) => {
137
137
  const keys = [];
138
138
  const serialized = {};
139
- for (const key of Object.keys(query).sort()) {
139
+ for (const key of Object.keys(query)) {
140
140
  if (key.toLowerCase() === SIGNATURE_HEADER) {
141
141
  continue;
142
142
  }
143
- keys.push(key);
143
+ const encodedKey = (0, import_util_uri_escape.escapeUri)(key);
144
+ keys.push(encodedKey);
144
145
  const value = query[key];
145
146
  if (typeof value === "string") {
146
- serialized[key] = `${(0, import_util_uri_escape.escapeUri)(key)}=${(0, import_util_uri_escape.escapeUri)(value)}`;
147
+ serialized[encodedKey] = `${encodedKey}=${(0, import_util_uri_escape.escapeUri)(value)}`;
147
148
  } else if (Array.isArray(value)) {
148
- serialized[key] = value.slice(0).reduce(
149
- (encoded, value2) => encoded.concat([`${(0, import_util_uri_escape.escapeUri)(key)}=${(0, import_util_uri_escape.escapeUri)(value2)}`]),
150
- []
151
- ).sort().join("&");
149
+ serialized[encodedKey] = value.slice(0).reduce((encoded, value2) => encoded.concat([`${encodedKey}=${(0, import_util_uri_escape.escapeUri)(value2)}`]), []).sort().join("&");
152
150
  }
153
151
  }
154
- return keys.map((key) => serialized[key]).filter((serialized2) => serialized2).join("&");
152
+ return keys.sort().map((key) => serialized[key]).filter((serialized2) => serialized2).join("&");
155
153
  }, "getCanonicalQuery");
156
154
 
157
155
  // src/getPayloadHash.ts
@@ -310,11 +308,11 @@ var hasHeader = /* @__PURE__ */ __name((soughtHeader, headers) => {
310
308
  // src/moveHeadersToQuery.ts
311
309
  var import_protocol_http = require("@smithy/protocol-http");
312
310
  var moveHeadersToQuery = /* @__PURE__ */ __name((request, options = {}) => {
313
- var _a;
311
+ var _a, _b;
314
312
  const { headers, query = {} } = import_protocol_http.HttpRequest.clone(request);
315
313
  for (const name of Object.keys(headers)) {
316
314
  const lname = name.toLowerCase();
317
- if (lname.slice(0, 6) === "x-amz-" && !((_a = options.unhoistableHeaders) == null ? void 0 : _a.has(lname))) {
315
+ if (lname.slice(0, 6) === "x-amz-" && !((_a = options.unhoistableHeaders) == null ? void 0 : _a.has(lname)) || ((_b = options.hoistableHeaders) == null ? void 0 : _b.has(lname))) {
318
316
  query[name] = headers[name];
319
317
  delete headers[name];
320
318
  }
@@ -378,6 +376,7 @@ var _SignatureV4 = class _SignatureV4 {
378
376
  unsignableHeaders,
379
377
  unhoistableHeaders,
380
378
  signableHeaders,
379
+ hoistableHeaders,
381
380
  signingRegion,
382
381
  signingService
383
382
  } = options;
@@ -391,7 +390,7 @@ var _SignatureV4 = class _SignatureV4 {
391
390
  );
392
391
  }
393
392
  const scope = createScope(shortDate, region, signingService ?? this.service);
394
- const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders });
393
+ const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders, hoistableHeaders });
395
394
  if (credentials.sessionToken) {
396
395
  request.query[TOKEN_QUERY_PARAM] = credentials.sessionToken;
397
396
  }
@@ -23,7 +23,7 @@ export class SignatureV4 {
23
23
  this.credentialProvider = normalizeProvider(credentials);
24
24
  }
25
25
  async presign(originalRequest, options = {}) {
26
- const { signingDate = new Date(), expiresIn = 3600, unsignableHeaders, unhoistableHeaders, signableHeaders, signingRegion, signingService, } = options;
26
+ const { signingDate = new Date(), expiresIn = 3600, unsignableHeaders, unhoistableHeaders, signableHeaders, hoistableHeaders, signingRegion, signingService, } = options;
27
27
  const credentials = await this.credentialProvider();
28
28
  this.validateResolvedCredentials(credentials);
29
29
  const region = signingRegion ?? (await this.regionProvider());
@@ -32,7 +32,7 @@ export class SignatureV4 {
32
32
  return Promise.reject("Signature version 4 presigned URLs" + " must have an expiration date less than one week in" + " the future");
33
33
  }
34
34
  const scope = createScope(shortDate, region, signingService ?? this.service);
35
- const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders });
35
+ const request = moveHeadersToQuery(prepareRequest(originalRequest), { unhoistableHeaders, hoistableHeaders });
36
36
  if (credentials.sessionToken) {
37
37
  request.query[TOKEN_QUERY_PARAM] = credentials.sessionToken;
38
38
  }
@@ -3,24 +3,26 @@ import { SIGNATURE_HEADER } from "./constants";
3
3
  export const getCanonicalQuery = ({ query = {} }) => {
4
4
  const keys = [];
5
5
  const serialized = {};
6
- for (const key of Object.keys(query).sort()) {
6
+ for (const key of Object.keys(query)) {
7
7
  if (key.toLowerCase() === SIGNATURE_HEADER) {
8
8
  continue;
9
9
  }
10
- keys.push(key);
10
+ const encodedKey = escapeUri(key);
11
+ keys.push(encodedKey);
11
12
  const value = query[key];
12
13
  if (typeof value === "string") {
13
- serialized[key] = `${escapeUri(key)}=${escapeUri(value)}`;
14
+ serialized[encodedKey] = `${encodedKey}=${escapeUri(value)}`;
14
15
  }
15
16
  else if (Array.isArray(value)) {
16
- serialized[key] = value
17
+ serialized[encodedKey] = value
17
18
  .slice(0)
18
- .reduce((encoded, value) => encoded.concat([`${escapeUri(key)}=${escapeUri(value)}`]), [])
19
+ .reduce((encoded, value) => encoded.concat([`${encodedKey}=${escapeUri(value)}`]), [])
19
20
  .sort()
20
21
  .join("&");
21
22
  }
22
23
  }
23
24
  return keys
25
+ .sort()
24
26
  .map((key) => serialized[key])
25
27
  .filter((serialized) => serialized)
26
28
  .join("&");
@@ -3,7 +3,8 @@ export const moveHeadersToQuery = (request, options = {}) => {
3
3
  const { headers, query = {} } = HttpRequest.clone(request);
4
4
  for (const name of Object.keys(headers)) {
5
5
  const lname = name.toLowerCase();
6
- if (lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) {
6
+ if ((lname.slice(0, 6) === "x-amz-" && !options.unhoistableHeaders?.has(lname)) ||
7
+ options.hoistableHeaders?.has(lname)) {
7
8
  query[name] = headers[name];
8
9
  delete headers[name];
9
10
  }
@@ -4,6 +4,7 @@ import type { HttpRequest as IHttpRequest, QueryParameterBag } from "@smithy/typ
4
4
  */
5
5
  export declare const moveHeadersToQuery: (request: IHttpRequest, options?: {
6
6
  unhoistableHeaders?: Set<string>;
7
+ hoistableHeaders?: Set<string>;
7
8
  }) => IHttpRequest & {
8
9
  query: QueryParameterBag;
9
10
  };
@@ -4,6 +4,7 @@ import { HttpRequest as IHttpRequest, QueryParameterBag } from "@smithy/types";
4
4
  */
5
5
  export declare const moveHeadersToQuery: (request: IHttpRequest, options?: {
6
6
  unhoistableHeaders?: Set<string>;
7
+ hoistableHeaders?: Set<string>;
7
8
  }) => IHttpRequest & {
8
9
  query: QueryParameterBag;
9
10
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smithy/signature-v4",
3
- "version": "4.1.3",
3
+ "version": "4.2.0",
4
4
  "description": "A standalone implementation of the AWS Signature V4 request signing algorithm",
5
5
  "main": "./dist-cjs/index.js",
6
6
  "module": "./dist-es/index.js",
@@ -25,10 +25,10 @@
25
25
  "license": "Apache-2.0",
26
26
  "dependencies": {
27
27
  "@smithy/is-array-buffer": "^3.0.0",
28
- "@smithy/protocol-http": "^4.1.3",
29
- "@smithy/types": "^3.4.2",
28
+ "@smithy/protocol-http": "^4.1.4",
29
+ "@smithy/types": "^3.5.0",
30
30
  "@smithy/util-hex-encoding": "^3.0.0",
31
- "@smithy/util-middleware": "^3.0.6",
31
+ "@smithy/util-middleware": "^3.0.7",
32
32
  "@smithy/util-uri-escape": "^3.0.0",
33
33
  "@smithy/util-utf8": "^3.0.0",
34
34
  "tslib": "^2.6.2"