aws-iam-language-server 0.0.14 → 0.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "aws-iam-language-server",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "type": "module",
5
5
  "bin": "./src/server.js",
6
6
  "publisher": "MichaelBarney",
package/readme.md CHANGED
@@ -78,6 +78,7 @@ This language server will provide diagnostics for some IAM policy issues, includ
78
78
  - no missing keys in a statement, (effect, action, resource or effect, action, principal)
79
79
  - no duplicate keys in a statement (including "not" variants like action/not action)
80
80
  - ensuring `Sid` uniqueness within a policy document
81
+ - `Sid` values are valid (alphanumeric for identity policies, allow spaces in resource policies)
81
82
  - effect has a valid value
82
83
  - defined actions are valid, or wildcards resolve to valid actions
83
84
  - arn parts are valid (partition, region, account id)
@@ -34,9 +34,10 @@ async function handleStandardDiagnostics(policyDocument) {
34
34
  const resourceValidator = new ResourceValidator();
35
35
  const conditionValidator = new ConditionValidator();
36
36
  for (const statement of policyDocument.statements) {
37
+ const isResourcePolicy = statement.entries.some((e) => e.key === 'Principal' || e.key === 'NotPrincipal');
37
38
  for (const entry of statement.entries) {
38
39
  if (entry.key === 'Sid') {
39
- diagnostics = diagnostics.concat(sidValidator.validate(entry));
40
+ diagnostics = diagnostics.concat(sidValidator.validate(entry, isResourcePolicy));
40
41
  }
41
42
  else if (entry.key === 'Effect') {
42
43
  diagnostics = diagnostics.concat(effectValidator.validate(entry));
@@ -81,9 +82,10 @@ async function handleHclBlockDiagnostics(policyDocument) {
81
82
  const resourceValidator = new ResourceValidator();
82
83
  const conditionValidator = new ConditionValidator();
83
84
  for (const statement of policyDocument.statements) {
85
+ const isResourcePolicy = statement.entries.some((e) => e.key === 'principals' || e.key === 'not_principals');
84
86
  for (const entry of statement.entries) {
85
87
  if (entry.key === 'sid') {
86
- diagnostics = diagnostics.concat(sidValidator.validate(entry));
88
+ diagnostics = diagnostics.concat(sidValidator.validate(entry, isResourcePolicy));
87
89
  }
88
90
  else if (entry.key === 'effect') {
89
91
  diagnostics = diagnostics.concat(effectValidator.validate(entry));
@@ -4,5 +4,5 @@ import { ElementValidator } from './base.ts';
4
4
  export declare class SidValidator extends ElementValidator {
5
5
  #private;
6
6
  constructor();
7
- validate(entry: StatementEntry): Array<Diagnostic>;
7
+ validate(entry: StatementEntry, isResourcePolicy?: boolean): Array<Diagnostic>;
8
8
  }
@@ -1,21 +1,30 @@
1
1
  import { ElementValidator } from "./base.js";
2
2
  import { createDiagnostic } from "./utils.js";
3
+ const strictSidPattern = /^[A-Za-z0-9]*$/;
4
+ const resourcePolicySidPattern = /^[A-Za-z0-9 ]*$/;
3
5
  export class SidValidator extends ElementValidator {
4
6
  #sids = {};
5
7
  constructor() {
6
8
  super();
7
9
  this.#sids = {};
8
10
  }
9
- validate(entry) {
11
+ validate(entry, isResourcePolicy = false) {
10
12
  const diagnostics = super.validate(entry);
11
13
  const sidValue = entry.values[0]?.text;
12
14
  if (!sidValue)
13
- return [];
15
+ return diagnostics;
14
16
  if (sidValue in this.#sids) {
15
17
  diagnostics.push(createDiagnostic(`Duplicate statement id value "${sidValue}"`, entry.valueRange));
16
18
  diagnostics.push(createDiagnostic(`Duplicate statement id value "${sidValue}"`, this.#sids[sidValue].valueRange));
17
19
  }
18
20
  this.#sids[sidValue] = entry;
21
+ const pattern = isResourcePolicy ? resourcePolicySidPattern : strictSidPattern;
22
+ if (!pattern.test(sidValue)) {
23
+ const message = isResourcePolicy
24
+ ? 'Sid must contain only ASCII letters (A-Z, a-z), digits (0-9), and spaces'
25
+ : 'Sid must contain only ASCII letters (A-Z, a-z) and digits (0-9)';
26
+ diagnostics.push(createDiagnostic(message, entry.values[0].range));
27
+ }
19
28
  return diagnostics;
20
29
  }
21
30
  }