@aws-sdk/cloudfront-signer 3.813.0 → 3.858.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 +12 -8
- package/dist-es/sign.js +12 -9
- package/package.json +2 -2
package/dist-cjs/index.js
CHANGED
|
@@ -68,9 +68,10 @@ function getSignedUrl({
|
|
|
68
68
|
}
|
|
69
69
|
baseUrl = resources[0].replace("*://", "https://");
|
|
70
70
|
}
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
71
|
+
const startFlag = baseUrl.includes("?") ? "&" : "?";
|
|
72
|
+
const params = Object.entries(cloudfrontSignBuilder.createCloudfrontAttribute()).filter(([, value]) => value !== void 0).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join("&");
|
|
73
|
+
const urlString = baseUrl + startFlag + params;
|
|
74
|
+
return getResource(urlString);
|
|
74
75
|
}
|
|
75
76
|
__name(getSignedUrl, "getSignedUrl");
|
|
76
77
|
function getSignedCookies({
|
|
@@ -117,15 +118,18 @@ function getPolicyResources(policy) {
|
|
|
117
118
|
return (parsedPolicy?.Statement ?? []).map((s) => s.Resource);
|
|
118
119
|
}
|
|
119
120
|
__name(getPolicyResources, "getPolicyResources");
|
|
120
|
-
function getResource(
|
|
121
|
-
|
|
121
|
+
function getResource(urlString) {
|
|
122
|
+
const protocol = urlString.slice(0, urlString.indexOf("//"));
|
|
123
|
+
switch (protocol) {
|
|
122
124
|
case "http:":
|
|
123
125
|
case "https:":
|
|
124
126
|
case "ws:":
|
|
125
127
|
case "wss:":
|
|
126
|
-
return
|
|
128
|
+
return urlString;
|
|
127
129
|
case "rtmp:":
|
|
128
|
-
|
|
130
|
+
const url = new URL(urlString);
|
|
131
|
+
const origin = `${protocol}//${url.hostname}`;
|
|
132
|
+
return urlString.substring(origin.length).replace(/(?::\d+)?\//, "");
|
|
129
133
|
default:
|
|
130
134
|
throw new Error("Invalid URI scheme. Scheme must be one of http, https, or rtmp");
|
|
131
135
|
}
|
|
@@ -269,7 +273,7 @@ var CloudfrontSignBuilder = class {
|
|
|
269
273
|
if (!url || !dateLessThan) {
|
|
270
274
|
return false;
|
|
271
275
|
}
|
|
272
|
-
const resource = getResource(
|
|
276
|
+
const resource = getResource(url);
|
|
273
277
|
const parsedDates = this.parseDateWindow(dateLessThan, dateGreaterThan);
|
|
274
278
|
this.dateLessThan = parsedDates.dateLessThan;
|
|
275
279
|
this.customPolicy = Boolean(parsedDates.dateGreaterThan) || Boolean(ipAddress);
|
package/dist-es/sign.js
CHANGED
|
@@ -30,13 +30,13 @@ export function getSignedUrl({ dateLessThan, dateGreaterThan, url, keyPairId, pr
|
|
|
30
30
|
}
|
|
31
31
|
baseUrl = resources[0].replace("*://", "https://");
|
|
32
32
|
}
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
.concat(Object.entries(cloudfrontSignBuilder.createCloudfrontAttribute()))
|
|
33
|
+
const startFlag = baseUrl.includes("?") ? "&" : "?";
|
|
34
|
+
const params = Object.entries(cloudfrontSignBuilder.createCloudfrontAttribute())
|
|
36
35
|
.filter(([, value]) => value !== undefined)
|
|
37
36
|
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
|
|
38
37
|
.join("&");
|
|
39
|
-
|
|
38
|
+
const urlString = baseUrl + startFlag + params;
|
|
39
|
+
return getResource(urlString);
|
|
40
40
|
}
|
|
41
41
|
export function getSignedCookies({ ipAddress, url, privateKey, keyPairId, dateLessThan, dateGreaterThan, policy, passphrase, }) {
|
|
42
42
|
const cloudfrontSignBuilder = new CloudfrontSignBuilder({
|
|
@@ -72,15 +72,18 @@ function getPolicyResources(policy) {
|
|
|
72
72
|
const parsedPolicy = typeof policy === "string" ? JSON.parse(policy) : policy;
|
|
73
73
|
return (parsedPolicy?.Statement ?? []).map((s) => s.Resource);
|
|
74
74
|
}
|
|
75
|
-
function getResource(
|
|
76
|
-
|
|
75
|
+
function getResource(urlString) {
|
|
76
|
+
const protocol = urlString.slice(0, urlString.indexOf("//"));
|
|
77
|
+
switch (protocol) {
|
|
77
78
|
case "http:":
|
|
78
79
|
case "https:":
|
|
79
80
|
case "ws:":
|
|
80
81
|
case "wss:":
|
|
81
|
-
return
|
|
82
|
+
return urlString;
|
|
82
83
|
case "rtmp:":
|
|
83
|
-
|
|
84
|
+
const url = new URL(urlString);
|
|
85
|
+
const origin = `${protocol}//${url.hostname}`;
|
|
86
|
+
return urlString.substring(origin.length).replace(/(?::\d+)?\//, "");
|
|
84
87
|
default:
|
|
85
88
|
throw new Error("Invalid URI scheme. Scheme must be one of http, https, or rtmp");
|
|
86
89
|
}
|
|
@@ -217,7 +220,7 @@ class CloudfrontSignBuilder {
|
|
|
217
220
|
if (!url || !dateLessThan) {
|
|
218
221
|
return false;
|
|
219
222
|
}
|
|
220
|
-
const resource = getResource(
|
|
223
|
+
const resource = getResource(url);
|
|
221
224
|
const parsedDates = this.parseDateWindow(dateLessThan, dateGreaterThan);
|
|
222
225
|
this.dateLessThan = parsedDates.dateLessThan;
|
|
223
226
|
this.customPolicy = Boolean(parsedDates.dateGreaterThan) || Boolean(ipAddress);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-sdk/cloudfront-signer",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.858.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 cloudfront-signer",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
},
|
|
23
23
|
"license": "Apache-2.0",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@smithy/url-parser": "^4.0.
|
|
25
|
+
"@smithy/url-parser": "^4.0.4",
|
|
26
26
|
"tslib": "^2.6.2"
|
|
27
27
|
},
|
|
28
28
|
"files": [
|