link2aws 1.0.18 → 1.0.19
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/link2aws.js +29 -0
- package/package.json +1 -1
package/link2aws.js
CHANGED
|
@@ -2,8 +2,30 @@
|
|
|
2
2
|
// https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/resource-ids.html
|
|
3
3
|
class ARN {
|
|
4
4
|
constructor(text) {
|
|
5
|
+
if (typeof(text) != 'string') {
|
|
6
|
+
throw Error("ARN must be a string");
|
|
7
|
+
}
|
|
8
|
+
|
|
5
9
|
text = text.trim();
|
|
6
10
|
|
|
11
|
+
// length limit
|
|
12
|
+
// There is no documented limit for ARNs in general.
|
|
13
|
+
// For IAM User, the documented limit is 2048.
|
|
14
|
+
// Please file an issue if you can find a resource type
|
|
15
|
+
// with a higher documented limit.
|
|
16
|
+
if (text.length > 2048) {
|
|
17
|
+
throw Error("ARN too long");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Check for invalid characters.
|
|
21
|
+
// This is meant to catch malicious inputs. This will not
|
|
22
|
+
// catch all invalid ARNs, as some resource types have
|
|
23
|
+
// stricter rules. Please file an issue if you are aware
|
|
24
|
+
// of a valid ARN that is rejected by this check.
|
|
25
|
+
if (!/^[a-zA-Z0-9:/+=,.@_*#\-]*$/.test(text)) {
|
|
26
|
+
throw Error("ARN contains invalid characters");
|
|
27
|
+
}
|
|
28
|
+
|
|
7
29
|
// split into tokens; leaving resource-id with colons together
|
|
8
30
|
var firstTokens = text.split(':');
|
|
9
31
|
var tokens = firstTokens.splice(0, 6);
|
|
@@ -54,6 +76,13 @@ class ARN {
|
|
|
54
76
|
throw Error("Bad number of tokens");
|
|
55
77
|
}
|
|
56
78
|
|
|
79
|
+
// region must have valid format.
|
|
80
|
+
// This is security relevant as it is used as a subdomain
|
|
81
|
+
// before the console domain.
|
|
82
|
+
if (this.region != '' && !/^[a-z0-9-]*$/.test(this.region)) {
|
|
83
|
+
throw Error(`Bad region: "${this.region}"`);
|
|
84
|
+
}
|
|
85
|
+
|
|
57
86
|
this._linkTemplates = this._getLinkTemplates();
|
|
58
87
|
}
|
|
59
88
|
|