@aws-sdk/cloudfront-signer 3.1056.0 → 3.1059.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
@@ -3,11 +3,12 @@
3
3
  var protocols = require('@smithy/core/protocols');
4
4
  var node_crypto = require('node:crypto');
5
5
 
6
- function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKey, ipAddress, policy, passphrase, }) {
6
+ function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKey, ipAddress, policy, passphrase, algorithm, }) {
7
7
  const cloudfrontSignBuilder = new CloudfrontSignBuilder({
8
8
  keyPairId,
9
9
  privateKey,
10
10
  passphrase,
11
+ algorithm,
11
12
  });
12
13
  if (!url && !policy) {
13
14
  throw new Error("@aws-sdk/cloudfront-signer: Please provide 'url' or 'policy'.");
@@ -35,18 +36,23 @@ function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKe
35
36
  });
36
37
  }
37
38
  const startFlag = baseUrl.includes("?") ? "&" : "?";
38
- const params = Object.entries(cloudfrontSignBuilder.createCloudfrontAttribute())
39
+ const attributes = cloudfrontSignBuilder.createCloudfrontAttribute();
40
+ if (algorithm === "SHA256") {
41
+ attributes["Hash-Algorithm"] = "SHA256";
42
+ }
43
+ const params = Object.entries(attributes)
39
44
  .filter(([, value]) => value !== undefined)
40
45
  .map(([key, value]) => `${protocols.extendedEncodeURIComponent(key)}=${protocols.extendedEncodeURIComponent(value)}`)
41
46
  .join("&");
42
47
  const urlString = baseUrl + startFlag + params;
43
48
  return getResource(urlString);
44
49
  }
45
- function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, }) {
50
+ function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, algorithm, }) {
46
51
  const cloudfrontSignBuilder = new CloudfrontSignBuilder({
47
52
  keyPairId,
48
53
  privateKey,
49
54
  passphrase,
55
+ algorithm,
50
56
  });
51
57
  if (policy) {
52
58
  cloudfrontSignBuilder.setCustomPolicy(policy);
@@ -70,6 +76,9 @@ function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan,
70
76
  if (cloudfrontCookieAttributes["Policy"]) {
71
77
  cookies["CloudFront-Policy"] = cloudfrontCookieAttributes["Policy"];
72
78
  }
79
+ if (algorithm === "SHA256") {
80
+ cookies["CloudFront-Hash-Algorithm"] = "SHA256";
81
+ }
73
82
  return cookies;
74
83
  }
75
84
  function encodeUrlPath(url) {
@@ -127,14 +136,16 @@ class CloudfrontSignBuilder {
127
136
  keyPairId;
128
137
  privateKey;
129
138
  passphrase;
139
+ algorithm;
130
140
  policy;
131
141
  customPolicy = false;
132
142
  dateLessThan;
133
- constructor({ privateKey, keyPairId, passphrase }) {
143
+ constructor({ privateKey, keyPairId, passphrase, algorithm }) {
134
144
  this.keyPairId = keyPairId;
135
145
  this.privateKey = privateKey;
136
146
  this.policy = "";
137
147
  this.passphrase = passphrase;
148
+ this.algorithm = algorithm ?? "SHA1";
138
149
  }
139
150
  buildPolicy(args) {
140
151
  const policy = {
@@ -240,7 +251,7 @@ class CloudfrontSignBuilder {
240
251
  };
241
252
  }
242
253
  signData(data, privateKey, passphrase) {
243
- const sign = node_crypto.createSign("RSA-SHA1");
254
+ const sign = node_crypto.createSign(this.algorithm === "SHA256" ? "RSA-SHA256" : "RSA-SHA1");
244
255
  sign.update(data);
245
256
  return sign.sign({ key: privateKey, passphrase }, "base64");
246
257
  }
package/dist-es/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./sign";
1
+ export { getSignedUrl, getSignedCookies } from "./sign";
package/dist-es/sign.js CHANGED
@@ -1,10 +1,11 @@
1
1
  import { extendedEncodeURIComponent } from "@smithy/core/protocols";
2
2
  import { createSign } from "node:crypto";
3
- export function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKey, ipAddress, policy, passphrase, }) {
3
+ export function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKey, ipAddress, policy, passphrase, algorithm, }) {
4
4
  const cloudfrontSignBuilder = new CloudfrontSignBuilder({
5
5
  keyPairId,
6
6
  privateKey,
7
7
  passphrase,
8
+ algorithm,
8
9
  });
9
10
  if (!url && !policy) {
10
11
  throw new Error("@aws-sdk/cloudfront-signer: Please provide 'url' or 'policy'.");
@@ -32,18 +33,23 @@ export function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, pr
32
33
  });
33
34
  }
34
35
  const startFlag = baseUrl.includes("?") ? "&" : "?";
35
- const params = Object.entries(cloudfrontSignBuilder.createCloudfrontAttribute())
36
+ const attributes = cloudfrontSignBuilder.createCloudfrontAttribute();
37
+ if (algorithm === "SHA256") {
38
+ attributes["Hash-Algorithm"] = "SHA256";
39
+ }
40
+ const params = Object.entries(attributes)
36
41
  .filter(([, value]) => value !== undefined)
37
42
  .map(([key, value]) => `${extendedEncodeURIComponent(key)}=${extendedEncodeURIComponent(value)}`)
38
43
  .join("&");
39
44
  const urlString = baseUrl + startFlag + params;
40
45
  return getResource(urlString);
41
46
  }
42
- export function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, }) {
47
+ export function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, algorithm, }) {
43
48
  const cloudfrontSignBuilder = new CloudfrontSignBuilder({
44
49
  keyPairId,
45
50
  privateKey,
46
51
  passphrase,
52
+ algorithm,
47
53
  });
48
54
  if (policy) {
49
55
  cloudfrontSignBuilder.setCustomPolicy(policy);
@@ -67,6 +73,9 @@ export function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLe
67
73
  if (cloudfrontCookieAttributes["Policy"]) {
68
74
  cookies["CloudFront-Policy"] = cloudfrontCookieAttributes["Policy"];
69
75
  }
76
+ if (algorithm === "SHA256") {
77
+ cookies["CloudFront-Hash-Algorithm"] = "SHA256";
78
+ }
70
79
  return cookies;
71
80
  }
72
81
  function encodeUrlPath(url) {
@@ -124,14 +133,16 @@ class CloudfrontSignBuilder {
124
133
  keyPairId;
125
134
  privateKey;
126
135
  passphrase;
136
+ algorithm;
127
137
  policy;
128
138
  customPolicy = false;
129
139
  dateLessThan;
130
- constructor({ privateKey, keyPairId, passphrase }) {
140
+ constructor({ privateKey, keyPairId, passphrase, algorithm }) {
131
141
  this.keyPairId = keyPairId;
132
142
  this.privateKey = privateKey;
133
143
  this.policy = "";
134
144
  this.passphrase = passphrase;
145
+ this.algorithm = algorithm ?? "SHA1";
135
146
  }
136
147
  buildPolicy(args) {
137
148
  const policy = {
@@ -237,7 +248,7 @@ class CloudfrontSignBuilder {
237
248
  };
238
249
  }
239
250
  signData(data, privateKey, passphrase) {
240
- const sign = createSign("RSA-SHA1");
251
+ const sign = createSign(this.algorithm === "SHA256" ? "RSA-SHA256" : "RSA-SHA1");
241
252
  sign.update(data);
242
253
  return sign.sign({ key: privateKey, passphrase }, "base64");
243
254
  }
@@ -1 +1,2 @@
1
- export * from "./sign";
1
+ export type { CloudfrontSignerAlgorithm, CloudfrontSignerCredentials, CloudfrontSignInput, CloudfrontSignInputWithParameters, CloudfrontSignInputWithPolicy, CloudfrontSignedCookiesOutput, CloudfrontSignInputBase, } from "./sign";
2
+ export { getSignedUrl, getSignedCookies } from "./sign";
@@ -3,6 +3,12 @@
3
3
  * @public
4
4
  */
5
5
  export type CloudfrontSignInput = CloudfrontSignInputWithParameters | CloudfrontSignInputWithPolicy;
6
+ /**
7
+ * The hash algorithm used for signing.
8
+ * @see https://aws.amazon.com/about-aws/whats-new/2026/04/amazon-cloudfront-sha-256-signed-urls/
9
+ * @public
10
+ */
11
+ export type CloudfrontSignerAlgorithm = "SHA1" | "SHA256";
6
12
  /**
7
13
  * @public
8
14
  */
@@ -11,8 +17,16 @@ export type CloudfrontSignerCredentials = {
11
17
  keyPairId: string;
12
18
  /** The content of the Cloudfront private key. */
13
19
  privateKey: string | Buffer;
14
- /** The passphrase of RSA-SHA1 key*/
20
+ /** The passphrase of the RSA key. */
15
21
  passphrase?: string;
22
+ /**
23
+ * The hash algorithm to use for signing.
24
+ * When set to "SHA256", the signed URL will include a Hash-Algorithm=SHA256 query parameter
25
+ * as required by CloudFront for FIPS 140-3 compliance.
26
+ *
27
+ * Default "SHA1".
28
+ */
29
+ algorithm?: CloudfrontSignerAlgorithm;
16
30
  };
17
31
  /**
18
32
  * @public
@@ -66,19 +80,21 @@ export interface CloudfrontSignedCookiesOutput {
66
80
  "CloudFront-Expires"?: number;
67
81
  /** Base64-encoded version of the JSON policy. */
68
82
  "CloudFront-Policy"?: string;
83
+ /** The hash algorithm used for signing. Present when algorithm is SHA256. */
84
+ "CloudFront-Hash-Algorithm"?: string;
69
85
  }
70
86
  /**
71
87
  * Creates a signed URL string using a canned or custom policy.
72
88
  * @public
73
89
  * @returns the input URL with signature attached as query parameters.
74
90
  */
75
- export declare function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKey, ipAddress, policy, passphrase, }: CloudfrontSignInput): string;
91
+ export declare function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, privateKey, ipAddress, policy, passphrase, algorithm, }: CloudfrontSignInput): string;
76
92
  /**
77
93
  * Creates signed cookies using a canned or custom policy.
78
94
  * @public
79
95
  * @returns an object with keys/values that can be added to cookies.
80
96
  */
81
- export declare function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, }: CloudfrontSignInput): CloudfrontSignedCookiesOutput;
97
+ export declare function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, algorithm, }: CloudfrontSignInput): CloudfrontSignedCookiesOutput;
82
98
  /**
83
99
  * @deprecated use CloudfrontSignInput, CloudfrontSignInputWithParameters, or CloudfrontSignInputWithPolicy.
84
100
  */
@@ -1 +1,10 @@
1
- export * from "./sign";
1
+ export {
2
+ CloudfrontSignerAlgorithm,
3
+ CloudfrontSignerCredentials,
4
+ CloudfrontSignInput,
5
+ CloudfrontSignInputWithParameters,
6
+ CloudfrontSignInputWithPolicy,
7
+ CloudfrontSignedCookiesOutput,
8
+ CloudfrontSignInputBase,
9
+ } from "./sign";
10
+ export { getSignedUrl, getSignedCookies } from "./sign";
@@ -1,10 +1,12 @@
1
1
  export type CloudfrontSignInput =
2
2
  | CloudfrontSignInputWithParameters
3
3
  | CloudfrontSignInputWithPolicy;
4
+ export type CloudfrontSignerAlgorithm = "SHA1" | "SHA256";
4
5
  export type CloudfrontSignerCredentials = {
5
6
  keyPairId: string;
6
7
  privateKey: string | Buffer;
7
8
  passphrase?: string;
9
+ algorithm?: CloudfrontSignerAlgorithm;
8
10
  };
9
11
  export type CloudfrontSignInputWithParameters = CloudfrontSignerCredentials & {
10
12
  url: string;
@@ -25,6 +27,7 @@ export interface CloudfrontSignedCookiesOutput {
25
27
  "CloudFront-Signature": string;
26
28
  "CloudFront-Expires"?: number;
27
29
  "CloudFront-Policy"?: string;
30
+ "CloudFront-Hash-Algorithm"?: string;
28
31
  }
29
32
  export declare function getSignedUrl({
30
33
  dateLessThan,
@@ -35,6 +38,7 @@ export declare function getSignedUrl({
35
38
  ipAddress,
36
39
  policy,
37
40
  passphrase,
41
+ algorithm,
38
42
  }: CloudfrontSignInput): string;
39
43
  export declare function getSignedCookies({
40
44
  ipAddress,
@@ -45,6 +49,7 @@ export declare function getSignedCookies({
45
49
  dateGreaterThan,
46
50
  policy,
47
51
  passphrase,
52
+ algorithm,
48
53
  }: CloudfrontSignInput): CloudfrontSignedCookiesOutput;
49
54
  export type CloudfrontSignInputBase = {
50
55
  url: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-sdk/cloudfront-signer",
3
- "version": "3.1056.0",
3
+ "version": "3.1059.0",
4
4
  "scripts": {
5
5
  "build": "concurrently 'yarn:build:types' 'yarn:build:es' && yarn build:cjs",
6
6
  "build:cjs": "node ../../scripts/compilation/inline cloudfront-signer",
@@ -11,7 +11,11 @@
11
11
  "clean": "premove dist-cjs dist-es dist-types tsconfig.cjs.tsbuildinfo tsconfig.es.tsbuildinfo tsconfig.types.tsbuildinfo",
12
12
  "extract:docs": "api-extractor run --local",
13
13
  "test": "yarn g:vitest run",
14
- "test:watch": "yarn g:vitest watch"
14
+ "test:watch": "yarn g:vitest watch",
15
+ "test:integration": "yarn g:vitest run -c vitest.config.integ.mts",
16
+ "test:integration:watch": "yarn g:vitest watch -c vitest.config.integ.mts",
17
+ "test:e2e": "yarn g:vitest run -c vitest.config.e2e.mts",
18
+ "test:e2e:watch": "yarn g:vitest watch -c vitest.config.e2e.mts"
15
19
  },
16
20
  "main": "./dist-cjs/index.js",
17
21
  "module": "./dist-es/index.js",
@@ -23,7 +27,7 @@
23
27
  },
24
28
  "license": "Apache-2.0",
25
29
  "dependencies": {
26
- "@smithy/core": "^3.24.5",
30
+ "@smithy/core": "^3.24.6",
27
31
  "tslib": "^2.6.2"
28
32
  },
29
33
  "files": [