@aws-sdk/s3-request-presigner 3.658.1 → 3.663.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/README.md CHANGED
@@ -10,18 +10,6 @@ generate signed url for S3.
10
10
 
11
11
  You can generated presigned url from S3 client and command. Here's the example:
12
12
 
13
- JavaScript Example:
14
-
15
- ```javascript
16
- const { getSignedUrl } = require("@aws-sdk/s3-request-presigner");
17
- const { S3Client, GetObjectCommand } = require("@aws-sdk/client-s3");
18
- const client = new S3Client(clientParams);
19
- const command = new GetObjectCommand(getObjectParams);
20
- const url = await getSignedUrl(client, command, { expiresIn: 3600 });
21
- ```
22
-
23
- ES6 Example
24
-
25
13
  ```javascript
26
14
  import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
27
15
  import { S3Client, GetObjectCommand } from "@aws-sdk/client-s3";
@@ -34,32 +22,11 @@ You can get signed URL for other S3 operations too, like `PutObjectCommand`.
34
22
  `expiresIn` config from the examples above is optional. If not set, it's default
35
23
  at `900`.
36
24
 
37
- If your request contains server-side encryption(`SSE*`) configurations, because
38
- of S3 limitation, you need to send corresponding headers along with the
39
- presigned url. For more information, please go to [S3 SSE reference](https://docs.aws.amazon.com/AmazonS3/latest/dev/KMSUsingRESTAPI.html)
40
-
41
25
  If you already have a request, you can pre-sign the request following the
42
26
  section bellow.
43
27
 
44
28
  ### Get Presigned URL from an Existing Request
45
29
 
46
- JavaScript Example:
47
-
48
- ```javascript
49
- const { S3RequestPresigner } = require("@aws-sdk/s3-request-presigner");
50
- const { Sha256 } = require("@aws-crypto/sha256-browser");
51
- const { Hash } = require("@smithy/hash-node");
52
- const signer = new S3RequestPresigner({
53
- region: regionProvider,
54
- credentials: credentialsProvider,
55
- sha256: Hash.bind(null, "sha256"), // In Node.js
56
- //sha256: Sha256 // In browsers
57
- });
58
- const presigned = await signer.presign(request);
59
- ```
60
-
61
- ES6 Example:
62
-
63
30
  ```javascript
64
31
  import { S3RequestPresigner } from "@aws-sdk/s3-request-presigner";
65
32
  import { Sha256 } from "@aws-crypto/sha256-browser";
@@ -84,13 +51,6 @@ const signer = new S3RequestPresigner({
84
51
  });
85
52
  ```
86
53
 
87
- If your request contains server-side encryption(`x-amz-server-side-encryption*`)
88
- headers, because of S3 limitation, you need to send these headers along
89
- with the presigned url. That is to say, the url only from calling `formatUrl()`
90
- to `presigned` is not sufficient to make a request. You need to send the
91
- server-side encryption headers along with the url. These headers remain in the
92
- `presigned.headers`
93
-
94
54
  ### Get Presigned URL with headers that cannot be signed
95
55
 
96
56
  By using the `getSignedUrl` with a `S3Client` you are able to sign your
@@ -140,4 +100,26 @@ const presigned = getSignedUrl(s3Client, command, {
140
100
  });
141
101
  ```
142
102
 
143
- For more information, please go to [S3 SSE reference](https://docs.aws.amazon.com/AmazonS3/latest/dev/KMSUsingRESTAPI.html)
103
+ ### PutObject with use of `hoistableHeaders`
104
+
105
+ `hoistableHeaders` overrides the default behavior of not hoisting
106
+ any headers that begin with `x-amz-*`.
107
+
108
+ ```js
109
+ // example: Server Side Encryption headers
110
+ import { getSignedUrl } from "@aws-sdk/s3-request-presigner";
111
+ import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
112
+
113
+ const params = {
114
+ Key: "...",
115
+ Bucket: "...",
116
+ ServerSideEncryption: "aws:kms",
117
+ SSEKMSKeyId: "arn:aws:kms:us-west-2:0000:key/abcd-1234-abcd",
118
+ };
119
+ const s3Client = new S3Client();
120
+ const command = new PutObjectCommand(params);
121
+
122
+ const preSignedUrl = await getSignedUrl(s3Client, command, {
123
+ hoistableHeaders: new Set(["x-amz-server-side-encryption", "x-amz-server-side-encryption-aws-kms-key-id"]),
124
+ });
125
+ ```
package/dist-cjs/index.js CHANGED
@@ -51,10 +51,16 @@ var _S3RequestPresigner = class _S3RequestPresigner {
51
51
  };
52
52
  this.signer = new import_signature_v4_multi_region.SignatureV4MultiRegion(resolvedOptions);
53
53
  }
54
- presign(requestToSign, { unsignableHeaders = /* @__PURE__ */ new Set(), unhoistableHeaders = /* @__PURE__ */ new Set(), ...options } = {}) {
54
+ presign(requestToSign, {
55
+ unsignableHeaders = /* @__PURE__ */ new Set(),
56
+ hoistableHeaders = /* @__PURE__ */ new Set(),
57
+ unhoistableHeaders = /* @__PURE__ */ new Set(),
58
+ ...options
59
+ } = {}) {
55
60
  this.prepareRequest(requestToSign, {
56
61
  unsignableHeaders,
57
- unhoistableHeaders
62
+ unhoistableHeaders,
63
+ hoistableHeaders
58
64
  });
59
65
  return this.signer.presign(requestToSign, {
60
66
  expiresIn: 900,
@@ -63,10 +69,16 @@ var _S3RequestPresigner = class _S3RequestPresigner {
63
69
  ...options
64
70
  });
65
71
  }
66
- presignWithCredentials(requestToSign, credentials, { unsignableHeaders = /* @__PURE__ */ new Set(), unhoistableHeaders = /* @__PURE__ */ new Set(), ...options } = {}) {
72
+ presignWithCredentials(requestToSign, credentials, {
73
+ unsignableHeaders = /* @__PURE__ */ new Set(),
74
+ hoistableHeaders = /* @__PURE__ */ new Set(),
75
+ unhoistableHeaders = /* @__PURE__ */ new Set(),
76
+ ...options
77
+ } = {}) {
67
78
  this.prepareRequest(requestToSign, {
68
79
  unsignableHeaders,
69
- unhoistableHeaders
80
+ unhoistableHeaders,
81
+ hoistableHeaders
70
82
  });
71
83
  return this.signer.presignWithCredentials(requestToSign, credentials, {
72
84
  expiresIn: 900,
@@ -75,10 +87,16 @@ var _S3RequestPresigner = class _S3RequestPresigner {
75
87
  ...options
76
88
  });
77
89
  }
78
- prepareRequest(requestToSign, { unsignableHeaders = /* @__PURE__ */ new Set(), unhoistableHeaders = /* @__PURE__ */ new Set() } = {}) {
90
+ prepareRequest(requestToSign, {
91
+ unsignableHeaders = /* @__PURE__ */ new Set(),
92
+ unhoistableHeaders = /* @__PURE__ */ new Set(),
93
+ hoistableHeaders = /* @__PURE__ */ new Set()
94
+ } = {}) {
79
95
  unsignableHeaders.add("content-type");
80
96
  Object.keys(requestToSign.headers).map((header) => header.toLowerCase()).filter((header) => header.startsWith("x-amz-server-side-encryption")).forEach((header) => {
81
- unhoistableHeaders.add(header);
97
+ if (!hoistableHeaders.has(header)) {
98
+ unhoistableHeaders.add(header);
99
+ }
82
100
  });
83
101
  requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
84
102
  const currentHostHeader = requestToSign.headers.host;
@@ -10,10 +10,11 @@ export class S3RequestPresigner {
10
10
  };
11
11
  this.signer = new SignatureV4MultiRegion(resolvedOptions);
12
12
  }
13
- presign(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
13
+ presign(requestToSign, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
14
14
  this.prepareRequest(requestToSign, {
15
15
  unsignableHeaders,
16
16
  unhoistableHeaders,
17
+ hoistableHeaders,
17
18
  });
18
19
  return this.signer.presign(requestToSign, {
19
20
  expiresIn: 900,
@@ -22,10 +23,11 @@ export class S3RequestPresigner {
22
23
  ...options,
23
24
  });
24
25
  }
25
- presignWithCredentials(requestToSign, credentials, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
26
+ presignWithCredentials(requestToSign, credentials, { unsignableHeaders = new Set(), hoistableHeaders = new Set(), unhoistableHeaders = new Set(), ...options } = {}) {
26
27
  this.prepareRequest(requestToSign, {
27
28
  unsignableHeaders,
28
29
  unhoistableHeaders,
30
+ hoistableHeaders,
29
31
  });
30
32
  return this.signer.presignWithCredentials(requestToSign, credentials, {
31
33
  expiresIn: 900,
@@ -34,13 +36,15 @@ export class S3RequestPresigner {
34
36
  ...options,
35
37
  });
36
38
  }
37
- prepareRequest(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set() } = {}) {
39
+ prepareRequest(requestToSign, { unsignableHeaders = new Set(), unhoistableHeaders = new Set(), hoistableHeaders = new Set(), } = {}) {
38
40
  unsignableHeaders.add("content-type");
39
41
  Object.keys(requestToSign.headers)
40
42
  .map((header) => header.toLowerCase())
41
43
  .filter((header) => header.startsWith("x-amz-server-side-encryption"))
42
44
  .forEach((header) => {
43
- unhoistableHeaders.add(header);
45
+ if (!hoistableHeaders.has(header)) {
46
+ unhoistableHeaders.add(header);
47
+ }
44
48
  });
45
49
  requestToSign.headers[SHA256_HEADER] = UNSIGNED_PAYLOAD;
46
50
  const currentHostHeader = requestToSign.headers.host;
@@ -8,8 +8,8 @@ export type S3RequestPresignerOptions = PartialBy<SignatureV4MultiRegionInit, "s
8
8
  export declare class S3RequestPresigner implements RequestPresigner {
9
9
  private readonly signer;
10
10
  constructor(options: S3RequestPresignerOptions);
11
- presign(requestToSign: IHttpRequest, { unsignableHeaders, unhoistableHeaders, ...options }?: RequestPresigningArguments): Promise<IHttpRequest>;
12
- presignWithCredentials(requestToSign: IHttpRequest, credentials: AwsCredentialIdentity, { unsignableHeaders, unhoistableHeaders, ...options }?: RequestPresigningArguments): Promise<IHttpRequest>;
11
+ presign(requestToSign: IHttpRequest, { unsignableHeaders, hoistableHeaders, unhoistableHeaders, ...options }?: RequestPresigningArguments): Promise<IHttpRequest>;
12
+ presignWithCredentials(requestToSign: IHttpRequest, credentials: AwsCredentialIdentity, { unsignableHeaders, hoistableHeaders, unhoistableHeaders, ...options }?: RequestPresigningArguments): Promise<IHttpRequest>;
13
13
  private prepareRequest;
14
14
  }
15
15
  export {};
@@ -20,6 +20,7 @@ export declare class S3RequestPresigner implements RequestPresigner {
20
20
  requestToSign: IHttpRequest,
21
21
  {
22
22
  unsignableHeaders,
23
+ hoistableHeaders,
23
24
  unhoistableHeaders,
24
25
  ...options
25
26
  }?: RequestPresigningArguments
@@ -29,6 +30,7 @@ export declare class S3RequestPresigner implements RequestPresigner {
29
30
  credentials: AwsCredentialIdentity,
30
31
  {
31
32
  unsignableHeaders,
33
+ hoistableHeaders,
32
34
  unhoistableHeaders,
33
35
  ...options
34
36
  }?: RequestPresigningArguments
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/s3-request-presigner",
3
- "version": "3.658.1",
3
+ "version": "3.663.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
6
6
  "build:cjs": "node ../../scripts/compilation/inline s3-request-presigner",
@@ -21,18 +21,18 @@
21
21
  },
22
22
  "license": "Apache-2.0",
23
23
  "dependencies": {
24
- "@aws-sdk/signature-v4-multi-region": "3.658.1",
25
- "@aws-sdk/types": "3.654.0",
26
- "@aws-sdk/util-format-url": "3.654.0",
27
- "@smithy/middleware-endpoint": "^3.1.3",
28
- "@smithy/protocol-http": "^4.1.3",
29
- "@smithy/smithy-client": "^3.3.5",
30
- "@smithy/types": "^3.4.2",
24
+ "@aws-sdk/signature-v4-multi-region": "3.662.0",
25
+ "@aws-sdk/types": "3.662.0",
26
+ "@aws-sdk/util-format-url": "3.662.0",
27
+ "@smithy/middleware-endpoint": "^3.1.4",
28
+ "@smithy/protocol-http": "^4.1.4",
29
+ "@smithy/smithy-client": "^3.3.6",
30
+ "@smithy/types": "^3.5.0",
31
31
  "tslib": "^2.6.2"
32
32
  },
33
33
  "devDependencies": {
34
- "@aws-sdk/client-s3": "3.658.1",
35
- "@smithy/hash-node": "^3.0.6",
34
+ "@aws-sdk/client-s3": "3.663.0",
35
+ "@smithy/hash-node": "^3.0.7",
36
36
  "@tsconfig/recommended": "1.0.1",
37
37
  "@types/node": "^16.18.96",
38
38
  "concurrently": "7.0.0",