link2aws 1.0.18 → 1.0.20

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.
Files changed (3) hide show
  1. package/README.md +5 -0
  2. package/link2aws.js +30 -1
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -23,6 +23,11 @@ Or run directly from source:
23
23
  # firefox link2aws.github.io/index.html
24
24
  ```
25
25
 
26
+ You can make links that auto-redirect to the AWS console by appending `#arn...` like this:
27
+
28
+ https://link2aws.github.io/#arn:aws:ec2:us-west-1:136693071363:image/ami-0851c4af3ebd71c35
29
+
30
+
26
31
  ### Use as command line tool
27
32
 
28
33
  Via NPM:
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
 
@@ -404,7 +433,7 @@ class ARN {
404
433
  "dhcp-options": null,
405
434
  "elastic-gpu": null,
406
435
  "fpga-image": null,
407
- "image": null,
436
+ "image": () => `https://${this.region}.${this.console}/ec2/home?region=${this.region}#ImageDetails:imageId=${this.resource}`,
408
437
  "instance": () => `https://${this.region}.${this.console}/ec2/v2/home`,
409
438
  "internet-gateway": null,
410
439
  "key-pair": null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "link2aws",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "Convert ARN (Amazon Resource Name) to AWS Console link",
5
5
  "main": "link2aws.js",
6
6
  "directories": {