@webpieces/code-rules 0.4.923 → 0.4.925

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": "@webpieces/code-rules",
3
- "version": "0.4.923",
3
+ "version": "0.4.925",
4
4
  "description": "Standalone code validation rules extracted from architecture-validators, no Nx dependency required",
5
5
  "type": "commonjs",
6
6
  "main": "./src/index.js",
@@ -16,19 +16,19 @@
16
16
  "directory": "packages/tooling/code-rules"
17
17
  },
18
18
  "dependencies": {
19
- "@webpieces/rules-config": "0.4.923",
19
+ "@webpieces/rules-config": "0.4.925",
20
20
  "@inversifyjs/binding-decorators": "1.1.5",
21
21
  "inversify": "7.10.4",
22
22
  "reflect-metadata": "0.2.2",
23
- "@webpieces/tooling-common": "0.4.923",
24
- "@webpieces/repo-workflow-core": "0.4.923",
25
- "@webpieces/rules-sdk": "0.4.923"
23
+ "@webpieces/tooling-common": "0.4.925",
24
+ "@webpieces/repo-workflow-core": "0.4.925",
25
+ "@webpieces/rules-sdk": "0.4.925"
26
26
  },
27
27
  "publishConfig": {
28
28
  "access": "public"
29
29
  },
30
30
  "devDependencies": {
31
- "@webpieces/tooling-testkit": "0.4.923"
31
+ "@webpieces/tooling-testkit": "0.4.925"
32
32
  },
33
33
  "exports": {
34
34
  ".": "./src/index.js",
@@ -8,6 +8,11 @@ export declare class SecurityPolicyShapeProblem {
8
8
  export declare class SecurityPolicyShapes {
9
9
  static authentication(call: ts.CallExpression | null, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[];
10
10
  private static descriptor;
11
+ /**
12
+ * `oidcSvcs([...])` takes ONE list naming at least one service account. An inline list is checked here;
13
+ * any other expression is left to the `OidcCallers` type and the runtime `AuthDeclaration` backstop.
14
+ */
15
+ private static oidcServices;
11
16
  static authorization(call: ts.CallExpression | null, isPublic: boolean, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[];
12
17
  private static validatePolicyFields;
13
18
  private static authorizationType;
@@ -12,6 +12,19 @@ class SecurityPolicyShapeProblem {
12
12
  }
13
13
  }
14
14
  exports.SecurityPolicyShapeProblem = SecurityPolicyShapeProblem;
15
+ /**
16
+ * Every canonical credential descriptor and the uniqueness key it occupies in one @WpAuth: its credential
17
+ * kind, except OIDC, which is keyed on kind plus `callerScope` exactly as the runtime `AuthDeclaration`
18
+ * keys it. So `oidcSameProject()` and `oidcSvcs([...])` may pair on one endpoint, and two of either may not.
19
+ */
20
+ const DESCRIPTOR_KEYS = new Map([
21
+ ['jwt', 'jwt'],
22
+ ['oidcSameProject', 'oidc:same-project'],
23
+ ['oidcSvcs', 'oidc:services'],
24
+ ['sharedSecret', 'shared-secret'],
25
+ ['webhook', 'webhook'],
26
+ ['apiKey', 'apikey'],
27
+ ]);
15
28
  /** Literal declarations must be inspectable; runtime registration additionally checks erased values. */
16
29
  class SecurityPolicyShapes {
17
30
  // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
@@ -20,15 +33,16 @@ class SecurityPolicyShapes {
20
33
  if (!array || !ts.isArrayLiteralExpression(array) || !array.elements.length) {
21
34
  return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth requires a nonempty inline array of canonical credential descriptors.')];
22
35
  }
23
- const seen = new Set();
36
+ const seenKeys = new Set();
24
37
  const problems = [];
25
38
  for (const element of array.elements) {
26
39
  const name = ts.isCallExpression(element) ? this.canonicalName(element.expression, named, namespaces) : undefined;
27
- if (!name || !['jwt', 'oidc', 'sharedSecret', 'webhook', 'apiKey'].includes(name) || seen.has(name)) {
28
- problems.push(new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth accepts unique jwt/oidc/sharedSecret/webhook/apiKey descriptors; public/locality are separate declarations.'));
40
+ const key = name === undefined ? undefined : DESCRIPTOR_KEYS.get(name);
41
+ if (!name || !key || seenKeys.has(key)) {
42
+ problems.push(new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth accepts unique jwt/oidcSameProject/oidcSvcs/sharedSecret/webhook/apiKey descriptors; public/locality are separate declarations.'));
29
43
  }
30
44
  else {
31
- seen.add(name);
45
+ seenKeys.add(key);
32
46
  if (ts.isCallExpression(element))
33
47
  problems.push(...this.descriptor(name, element));
34
48
  }
@@ -39,6 +53,10 @@ class SecurityPolicyShapes {
39
53
  static descriptor(name, call) {
40
54
  if (name === 'jwt' && call.arguments.length)
41
55
  return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'jwt() takes no policy; put roles/application policy in @WpAuthorization.')];
56
+ if (name === 'oidcSameProject' && call.arguments.length)
57
+ return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'oidcSameProject() takes no arguments; name service accounts with oidcSvcs([...]) instead.')];
58
+ if (name === 'oidcSvcs')
59
+ return this.oidcServices(call);
42
60
  if (['sharedSecret', 'webhook', 'apiKey'].includes(name) && !call.arguments.length)
43
61
  return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', `${name}(...) requires its named credential configuration.`)];
44
62
  if (name === 'apiKey' && !call.arguments[1])
@@ -47,6 +65,19 @@ class SecurityPolicyShapes {
47
65
  return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey credentials cannot be empty.')];
48
66
  return [];
49
67
  }
68
+ /**
69
+ * `oidcSvcs([...])` takes ONE list naming at least one service account. An inline list is checked here;
70
+ * any other expression is left to the `OidcCallers` type and the runtime `AuthDeclaration` backstop.
71
+ */
72
+ // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
73
+ static oidcServices(call) {
74
+ const list = call.arguments[0];
75
+ const blank = (element) => ts.isStringLiteral(element) && element.text.trim().length === 0;
76
+ if (call.arguments.length !== 1 || !list || (ts.isArrayLiteralExpression(list) && (!list.elements.length || list.elements.some(blank)))) {
77
+ return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', "oidcSvcs([...]) requires one nonempty list of service accounts; use oidcSameProject() for this GCP project's service accounts.")];
78
+ }
79
+ return [];
80
+ }
50
81
  // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
51
82
  static authorization(call, isPublic, named, namespaces) {
52
83
  const object = call?.arguments[0];
@@ -1 +1 @@
1
- {"version":3,"file":"security-policy-shapes.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/security-policy-shapes.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AAEjC,MAAa,0BAA0B;IACd;IAAuB;IAA5C,YAAqB,IAAY,EAAW,OAAe;QAAtC,SAAI,GAAJ,IAAI,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;CAClE;AAFD,gEAEC;AAED,wGAAwG;AACxG,MAAa,oBAAoB;IAC7B,oIAAoI;IACpI,MAAM,CAAC,cAAc,CAAC,IAA8B,EAAE,KAAkC,EAAE,UAA+B;QACrH,MAAM,KAAK,GAAG,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,CAAC,KAAK,IAAI,CAAC,EAAE,CAAC,wBAAwB,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YAC1E,OAAO,CAAC,IAAI,0BAA0B,CAAC,mBAAmB,EAAE,+EAA+E,CAAC,CAAC,CAAC;QAClJ,CAAC;QACD,MAAM,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;QAC/B,MAAM,QAAQ,GAAiC,EAAE,CAAC;QAClD,KAAK,MAAM,OAAO,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;YACnC,MAAM,IAAI,GAAG,EAAE,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAClH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KAAK,mBAAmB;YAAE,OAAO,SAAS,CAAC;QACxK,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,oIAAoI;IAC5H,MAAM,CAAC,aAAa,CAAC,UAAyB,EAAE,KAAkC,EAAE,UAA+B;QACvH,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACnE,IAAI,EAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QACnK,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AA/ED,oDA+EC","sourcesContent":["import * as ts from 'typescript';\n\nexport class SecurityPolicyShapeProblem {\n constructor(readonly code: string, readonly message: string) {}\n}\n\n/** Literal declarations must be inspectable; runtime registration additionally checks erased values. */\nexport class SecurityPolicyShapes {\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n static authentication(call: ts.CallExpression | null, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[] {\n const array = call?.arguments[0];\n if (!array || !ts.isArrayLiteralExpression(array) || !array.elements.length) {\n return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth requires a nonempty inline array of canonical credential descriptors.')];\n }\n const seen = new Set<string>();\n const problems: SecurityPolicyShapeProblem[] = [];\n for (const element of array.elements) {\n const name = ts.isCallExpression(element) ? this.canonicalName(element.expression, named, namespaces) : undefined;\n if (!name || !['jwt', 'oidc', 'sharedSecret', 'webhook', 'apiKey'].includes(name) || seen.has(name)) {\n problems.push(new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth accepts unique jwt/oidc/sharedSecret/webhook/apiKey descriptors; public/locality are separate declarations.'));\n } else {\n seen.add(name);\n if (ts.isCallExpression(element)) problems.push(...this.descriptor(name, element));\n }\n }\n return problems;\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static descriptor(name: string, call: ts.CallExpression): readonly SecurityPolicyShapeProblem[] {\n if (name === 'jwt' && call.arguments.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'jwt() takes no policy; put roles/application policy in @WpAuthorization.')];\n if (['sharedSecret', 'webhook', 'apiKey'].includes(name) && !call.arguments.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', `${name}(...) requires its named credential configuration.`)];\n if (name === 'apiKey' && !call.arguments[1]) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey(regime, credentials) requires a nonempty credentials tuple.')];\n if (name === 'apiKey' && ts.isArrayLiteralExpression(call.arguments[1]) && !call.arguments[1].elements.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey credentials cannot be empty.')];\n return [];\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n static authorization(call: ts.CallExpression | null, isPublic: boolean, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[] {\n const object = call?.arguments[0];\n if (!object || !ts.isObjectLiteralExpression(object)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', '@WpAuthorization requires an inline discriminated policy; opaque expressions are not proof of a secure declaration.')];\n const fields = new Map<string, ts.Expression>();\n for (const property of object.properties) {\n if (!ts.isPropertyAssignment(property) || (!ts.isIdentifier(property.name) && !ts.isStringLiteral(property.name))) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Authorization policy cannot use spreads, computed fields, or shorthand values.')];\n if (fields.has(property.name.text)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Authorization policy contains duplicate fields.')];\n fields.set(property.name.text, property.initializer);\n }\n const type = this.authorizationType(fields.get('authType'), named, namespaces);\n const shape = this.validatePolicyFields(type, fields);\n if (shape.length) return shape;\n if (isPublic !== (type === 'ANONYMOUS')) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_PAIRING', 'Pair @WpAuthPublic with ANONYMOUS; protected @WpAuth requires protected/CUSTOM authorization.')];\n return [];\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static validatePolicyFields(type: string | undefined, fields: ReadonlyMap<string, ts.Expression>): readonly SecurityPolicyShapeProblem[] {\n if (!type || !['ALL_USERS', 'ROLES', 'SERVICE_ONLY', 'USERS_OR_SERVICES', 'ANONYMOUS', 'CUSTOM'].includes(type)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Declare a canonical AuthorizationType branch.')];\n const allowed = new Set(['authType']);\n if (type === 'ROLES') allowed.add('roles');\n if (type === 'ANONYMOUS') allowed.add('reason');\n if (type === 'CUSTOM') allowed.add('appPolicy');\n if ([...fields.keys()].some((key: string) => !allowed.has(key))) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'roles belongs only on ROLES, reason only on ANONYMOUS, and application fields only under CUSTOM.appPolicy.')];\n if (type === 'ROLES') {\n const roles = fields.get('roles');\n if (!roles || !ts.isArrayLiteralExpression(roles) || !roles.elements.length || !roles.elements.every((role: ts.Expression) => ts.isStringLiteral(role) && role.text.trim().length > 0)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'ROLES requires a nonempty inline tuple of nonempty role strings.')];\n }\n if (type === 'ANONYMOUS') {\n const reason = fields.get('reason');\n if (!reason || !ts.isStringLiteral(reason) || !reason.text.trim()) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'ANONYMOUS requires a nonempty reason.')];\n }\n if (type === 'CUSTOM' && !fields.has('appPolicy')) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'CUSTOM requires appPolicy and a validating AuthorizationHook at startup.')];\n return [];\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static authorizationType(expression: ts.Expression | undefined, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): string | undefined {\n if (!expression || !ts.isPropertyAccessExpression(expression) || this.canonicalName(expression.expression, named, namespaces) !== 'AuthorizationType') return undefined;\n return expression.name.text;\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static canonicalName(expression: ts.Expression, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): string | undefined {\n if (ts.isIdentifier(expression)) return named.get(expression.text);\n if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression) && namespaces.has(expression.expression.text)) return expression.name.text;\n return undefined;\n }\n}\n"]}
1
+ {"version":3,"file":"security-policy-shapes.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/security-policy-shapes.ts"],"names":[],"mappings":";;;;AAAA,uDAAiC;AAEjC,MAAa,0BAA0B;IACd;IAAuB;IAA5C,YAAqB,IAAY,EAAW,OAAe;QAAtC,SAAI,GAAJ,IAAI,CAAQ;QAAW,YAAO,GAAP,OAAO,CAAQ;IAAG,CAAC;CAClE;AAFD,gEAEC;AAED;;;;GAIG;AACH,MAAM,eAAe,GAAgC,IAAI,GAAG,CAAC;IACzD,CAAC,KAAK,EAAE,KAAK,CAAC;IACd,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IACxC,CAAC,UAAU,EAAE,eAAe,CAAC;IAC7B,CAAC,cAAc,EAAE,eAAe,CAAC;IACjC,CAAC,SAAS,EAAE,SAAS,CAAC;IACtB,CAAC,QAAQ,EAAE,QAAQ,CAAC;CACvB,CAAC,CAAC;AAEH,wGAAwG;AACxG,MAAa,oBAAoB;IAC7B,oIAAoI;IACpI,MAAM,CAAC,cAAc,CAAC,IAA8B,EAAE,KAAk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AC;YAAE,OAAO,CAAC,IAAI,0BAA0B,CAAC,2BAA2B,EAAE,0EAA0E,CAAC,CAAC,CAAC;QACpM,OAAO,EAAE,CAAC;IACd,CAAC;IAED,oIAAoI;IAC5H,MAAM,CAAC,iBAAiB,CAAC,UAAqC,EAAE,KAAkC,EAAE,UAA+B;QACvI,IAAI,CAAC,UAAU,IAAI,CAAC,EAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,UAAU,CAAC,UAAU,EAAE,KAAK,EAAE,UAAU,CAAC,KAAK,mBAAmB;YAAE,OAAO,SAAS,CAAC;QACxK,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;IAChC,CAAC;IAED,oIAAoI;IAC5H,MAAM,CAAC,aAAa,CAAC,UAAyB,EAAE,KAAkC,EAAE,UAA+B;QACvH,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC;YAAE,OAAO,KAAK,CAAC,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC;QACnE,IAAI,EAAE,CAAC,0BAA0B,CAAC,UAAU,CAAC,IAAI,EAAE,CAAC,YAAY,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,UAAU,CAAC,GAAG,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC;YAAE,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;QACnK,OAAO,SAAS,CAAC;IACrB,CAAC;CACJ;AAhGD,oDAgGC","sourcesContent":["import * as ts from 'typescript';\n\nexport class SecurityPolicyShapeProblem {\n constructor(readonly code: string, readonly message: string) {}\n}\n\n/**\n * Every canonical credential descriptor and the uniqueness key it occupies in one @WpAuth: its credential\n * kind, except OIDC, which is keyed on kind plus `callerScope` exactly as the runtime `AuthDeclaration`\n * keys it. So `oidcSameProject()` and `oidcSvcs([...])` may pair on one endpoint, and two of either may not.\n */\nconst DESCRIPTOR_KEYS: ReadonlyMap<string, string> = new Map([\n ['jwt', 'jwt'],\n ['oidcSameProject', 'oidc:same-project'],\n ['oidcSvcs', 'oidc:services'],\n ['sharedSecret', 'shared-secret'],\n ['webhook', 'webhook'],\n ['apiKey', 'apikey'],\n]);\n\n/** Literal declarations must be inspectable; runtime registration additionally checks erased values. */\nexport class SecurityPolicyShapes {\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n static authentication(call: ts.CallExpression | null, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[] {\n const array = call?.arguments[0];\n if (!array || !ts.isArrayLiteralExpression(array) || !array.elements.length) {\n return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth requires a nonempty inline array of canonical credential descriptors.')];\n }\n const seenKeys = new Set<string>();\n const problems: SecurityPolicyShapeProblem[] = [];\n for (const element of array.elements) {\n const name = ts.isCallExpression(element) ? this.canonicalName(element.expression, named, namespaces) : undefined;\n const key = name === undefined ? undefined : DESCRIPTOR_KEYS.get(name);\n if (!name || !key || seenKeys.has(key)) {\n problems.push(new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth accepts unique jwt/oidcSameProject/oidcSvcs/sharedSecret/webhook/apiKey descriptors; public/locality are separate declarations.'));\n } else {\n seenKeys.add(key);\n if (ts.isCallExpression(element)) problems.push(...this.descriptor(name, element));\n }\n }\n return problems;\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static descriptor(name: string, call: ts.CallExpression): readonly SecurityPolicyShapeProblem[] {\n if (name === 'jwt' && call.arguments.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'jwt() takes no policy; put roles/application policy in @WpAuthorization.')];\n if (name === 'oidcSameProject' && call.arguments.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'oidcSameProject() takes no arguments; name service accounts with oidcSvcs([...]) instead.')];\n if (name === 'oidcSvcs') return this.oidcServices(call);\n if (['sharedSecret', 'webhook', 'apiKey'].includes(name) && !call.arguments.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', `${name}(...) requires its named credential configuration.`)];\n if (name === 'apiKey' && !call.arguments[1]) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey(regime, credentials) requires a nonempty credentials tuple.')];\n if (name === 'apiKey' && ts.isArrayLiteralExpression(call.arguments[1]) && !call.arguments[1].elements.length) return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey credentials cannot be empty.')];\n return [];\n }\n\n /**\n * `oidcSvcs([...])` takes ONE list naming at least one service account. An inline list is checked here;\n * any other expression is left to the `OidcCallers` type and the runtime `AuthDeclaration` backstop.\n */\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static oidcServices(call: ts.CallExpression): readonly SecurityPolicyShapeProblem[] {\n const list = call.arguments[0];\n const blank = (element: ts.Expression): boolean => ts.isStringLiteral(element) && element.text.trim().length === 0;\n if (call.arguments.length !== 1 || !list || (ts.isArrayLiteralExpression(list) && (!list.elements.length || list.elements.some(blank)))) {\n return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', \"oidcSvcs([...]) requires one nonempty list of service accounts; use oidcSameProject() for this GCP project's service accounts.\")];\n }\n return [];\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n static authorization(call: ts.CallExpression | null, isPublic: boolean, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[] {\n const object = call?.arguments[0];\n if (!object || !ts.isObjectLiteralExpression(object)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', '@WpAuthorization requires an inline discriminated policy; opaque expressions are not proof of a secure declaration.')];\n const fields = new Map<string, ts.Expression>();\n for (const property of object.properties) {\n if (!ts.isPropertyAssignment(property) || (!ts.isIdentifier(property.name) && !ts.isStringLiteral(property.name))) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Authorization policy cannot use spreads, computed fields, or shorthand values.')];\n if (fields.has(property.name.text)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Authorization policy contains duplicate fields.')];\n fields.set(property.name.text, property.initializer);\n }\n const type = this.authorizationType(fields.get('authType'), named, namespaces);\n const shape = this.validatePolicyFields(type, fields);\n if (shape.length) return shape;\n if (isPublic !== (type === 'ANONYMOUS')) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_PAIRING', 'Pair @WpAuthPublic with ANONYMOUS; protected @WpAuth requires protected/CUSTOM authorization.')];\n return [];\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static validatePolicyFields(type: string | undefined, fields: ReadonlyMap<string, ts.Expression>): readonly SecurityPolicyShapeProblem[] {\n if (!type || !['ALL_USERS', 'ROLES', 'SERVICE_ONLY', 'USERS_OR_SERVICES', 'ANONYMOUS', 'CUSTOM'].includes(type)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Declare a canonical AuthorizationType branch.')];\n const allowed = new Set(['authType']);\n if (type === 'ROLES') allowed.add('roles');\n if (type === 'ANONYMOUS') allowed.add('reason');\n if (type === 'CUSTOM') allowed.add('appPolicy');\n if ([...fields.keys()].some((key: string) => !allowed.has(key))) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'roles belongs only on ROLES, reason only on ANONYMOUS, and application fields only under CUSTOM.appPolicy.')];\n if (type === 'ROLES') {\n const roles = fields.get('roles');\n if (!roles || !ts.isArrayLiteralExpression(roles) || !roles.elements.length || !roles.elements.every((role: ts.Expression) => ts.isStringLiteral(role) && role.text.trim().length > 0)) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'ROLES requires a nonempty inline tuple of nonempty role strings.')];\n }\n if (type === 'ANONYMOUS') {\n const reason = fields.get('reason');\n if (!reason || !ts.isStringLiteral(reason) || !reason.text.trim()) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'ANONYMOUS requires a nonempty reason.')];\n }\n if (type === 'CUSTOM' && !fields.has('appPolicy')) return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'CUSTOM requires appPolicy and a validating AuthorizationHook at startup.')];\n return [];\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static authorizationType(expression: ts.Expression | undefined, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): string | undefined {\n if (!expression || !ts.isPropertyAccessExpression(expression) || this.canonicalName(expression.expression, named, namespaces) !== 'AuthorizationType') return undefined;\n return expression.name.text;\n }\n\n // webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration\n private static canonicalName(expression: ts.Expression, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): string | undefined {\n if (ts.isIdentifier(expression)) return named.get(expression.text);\n if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression) && namespaces.has(expression.expression.text)) return expression.name.text;\n return undefined;\n }\n}\n"]}
@@ -22,7 +22,7 @@ const CONTRACT_DECORATORS = new Set([
22
22
  ...HTTP_AUTH,
23
23
  ...LEGACY_AUTH,
24
24
  'WpAuthorization', 'WpLocalOnly', 'AuthorizationType',
25
- 'jwt', 'oidc', 'sharedSecret', 'webhook', 'apiKey',
25
+ 'jwt', 'oidcSameProject', 'oidcSvcs', 'sharedSecret', 'webhook', 'apiKey',
26
26
  'ApiPath',
27
27
  'Endpoint',
28
28
  'WpInternal',
@@ -1 +1 @@
1
- {"version":3,"file":"validate-ensure-we-are-secure.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-ensure-we-are-secure.ts"],"names":[],"mappings":";;;AAgfA,0EAUC;AA+BD,wDA8BC;AAGD,wDA2BC;AAGD,4DAIC;;AA5lBD,+FAA+F;AAC/F,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,qEAAgE;AAChE,0DAA6F;AAC7F,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;CACJ,CAAA;AAnBY,gEAA0B;qCAA1B,0BAA0B;IADtC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEjB,sCAAuB;GADlC,0BAA0B,CAmBtC","sourcesContent":["/** Audits explicit HTTP authentication and IPC-only contracts in directly changed projects. */\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { SecurityPolicyShapes } from './security-policy-shapes';\nimport { getChangedFiles, detectBase, Option, RuleFailError } from \"@webpieces/rules-config\";\nimport { EnsureWeAreSecureConfig } from \"./configs/rule-configs\";\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { CodeValidator, ExecutorResult } from './code-validator';\n\nconst HTTP_AUTH = new Set(['WpAuth', 'WpAuthPublic']);\nconst LEGACY_AUTH = new Set(['WpAuthJwt', 'WpAuthOidc', 'WpAuthWebhook', 'WpAuthSharedSecret', 'WpAuthApiKey', 'WpAuthLocalOnly', 'WpMcpAuthJwt']);\nconst CONTRACT_DECORATORS = new Set([\n ...HTTP_AUTH,\n ...LEGACY_AUTH,\n 'WpAuthorization', 'WpLocalOnly', 'AuthorizationType',\n 'jwt', 'oidc', 'sharedSecret', 'webhook', 'apiKey',\n 'ApiPath',\n 'Endpoint',\n 'WpInternal',\n 'WpIpcEndpoint',\n]);\n\nexport class SecurityContractViolation {\n constructor(\n readonly file: string,\n readonly line: number,\n readonly code: string,\n readonly message: string,\n ) {}\n}\n\nclass DecoratorUse {\n constructor(\n readonly name: string,\n readonly decorator: ts.Decorator,\n readonly call: ts.CallExpression | null,\n readonly imports: CanonicalImports,\n ) {}\n}\n\nclass CanonicalImports {\n readonly named = new Map<string, string>();\n readonly namespaces = new Set<string>();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction isCanonicalModule(moduleName: string): boolean {\n return (\n moduleName === '@webpieces/core-util' ||\n moduleName === '@webpieces/http-routing' ||\n moduleName === '@webpieces/http-client-browser' ||\n moduleName.endsWith('/core-util/src/http/auth-mode') ||\n moduleName.endsWith('/core-util/src/http/authorization') ||\n moduleName === '@webpieces/core-util/ipc' ||\n moduleName.endsWith('/core-util/src/http/decorators') ||\n moduleName.includes('/core-util/src/ipc/')\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction importsOf(source: ts.SourceFile): CanonicalImports {\n const result = new CanonicalImports();\n for (const statement of source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))\n continue;\n if (!isCanonicalModule(statement.moduleSpecifier.text)) continue;\n const bindings = statement.importClause?.namedBindings;\n if (bindings && ts.isNamedImports(bindings)) {\n for (const item of bindings.elements) {\n const exported = item.propertyName?.text ?? item.name.text;\n if (CONTRACT_DECORATORS.has(exported)) result.named.set(item.name.text, exported);\n }\n } else if (bindings && ts.isNamespaceImport(bindings)) {\n result.namespaces.add(bindings.name.text);\n }\n }\n return result;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction decoratorUse(decorator: ts.Decorator, imports: CanonicalImports): DecoratorUse | null {\n const expr = decorator.expression;\n const call = ts.isCallExpression(expr) ? expr : null;\n const callee = call?.expression ?? expr;\n if (ts.isIdentifier(callee)) {\n const canonical = imports.named.get(callee.text);\n return canonical ? new DecoratorUse(canonical, decorator, call, imports) : null;\n }\n if (\n ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n imports.namespaces.has(callee.expression.text)\n ) {\n return CONTRACT_DECORATORS.has(callee.name.text)\n ? new DecoratorUse(callee.name.text, decorator, call, imports)\n : null;\n }\n return null;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction decoratorsOf(node: ts.Node, imports: CanonicalImports): DecoratorUse[] {\n if (!ts.canHaveDecorators(node)) return [];\n return (ts.getDecorators(node) ?? [])\n .map((decorator: ts.Decorator) => decoratorUse(decorator, imports))\n .filter((use): use is DecoratorUse => use !== null);\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction lineOf(source: ts.SourceFile, node: ts.Node): number {\n return source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction literalId(use: DecoratorUse): string | null {\n const arg = use.call?.arguments[0];\n if (!arg || (!ts.isStringLiteral(arg) && !ts.isNoSubstitutionTemplateLiteral(arg))) return null;\n const value = arg.text.trim();\n return value.length > 0 ? value : null;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction methodName(method: ts.MethodDeclaration): string {\n return ts.isIdentifier(method.name) || ts.isStringLiteral(method.name)\n ? method.name.text\n : method.name.getText();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction hasPromiseReturn(method: ts.MethodDeclaration): boolean {\n const type = method.type;\n return (\n type !== undefined &&\n ts.isTypeReferenceNode(type) &&\n ts.isIdentifier(type.typeName) &&\n type.typeName.text === 'Promise'\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction add(\n out: SecurityContractViolation[],\n file: string,\n source: ts.SourceFile,\n node: ts.Node,\n code: string,\n message: string,\n): void {\n out.push(new SecurityContractViolation(file, lineOf(source, node), code, message));\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkHttpMethod(\n file: string,\n source: ts.SourceFile,\n method: ts.MethodDeclaration,\n uses: DecoratorUse[],\n out: SecurityContractViolation[],\n): void {\n const endpoints = uses.filter((use: DecoratorUse) => use.name === 'Endpoint');\n const auth = uses.filter((use: DecoratorUse) => HTTP_AUTH.has(use.name));\n const ipc = uses.filter((use: DecoratorUse) => use.name === 'WpIpcEndpoint');\n const label = methodName(method);\n checkAuthorization(file, source, method, uses, out);\n if (endpoints.length > 1)\n add(\n out,\n file,\n source,\n method,\n 'HTTP_MULTIPLE_ENDPOINTS',\n `${label} has multiple @Endpoint decorators.`,\n );\n if (endpoints.length > 0 && auth.length !== 1) {\n add(\n out,\n file,\n source,\n method,\n 'HTTP_AUTH_COUNT',\n `${label} must have exactly one method-level @WpAuth or @WpAuthPublic decorator; found ${auth.length}. Prefer an authenticated mode; use @WpAuthPublic('reason') only for deliberate anonymous access.`,\n );\n }\n if (endpoints.length === 0 && auth.length > 0)\n add(\n out,\n file,\n source,\n auth[0]!.decorator,\n 'HTTP_ORPHAN_AUTH',\n `${label} has @WpAuth* but no @Endpoint.`,\n );\n for (const publicUse of auth.filter((use: DecoratorUse) => use.name === 'WpAuthPublic')) {\n if (literalId(publicUse) === null)\n add(\n out,\n file,\n source,\n publicUse.decorator,\n 'HTTP_PUBLIC_REASON',\n `${label} must use @WpAuthPublic('non-empty reason').`,\n );\n }\n if (ipc.length > 0)\n add(\n out,\n file,\n source,\n ipc[0]!.decorator,\n 'HTTP_IPC_MIX',\n `${label} mixes HTTP and IPC endpoint metadata.`,\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless security declaration audit shared by all served endpoints\nfunction checkAuthorization(file: string, source: ts.SourceFile, method: ts.MethodDeclaration, uses: DecoratorUse[], out: SecurityContractViolation[]): void {\n const endpoint = uses.some((use: DecoratorUse) => use.name === 'Endpoint');\n const authorization = uses.filter((use: DecoratorUse) => use.name === 'WpAuthorization');\n if (endpoint && authorization.length !== 1) add(out, file, source, method, 'HTTP_AUTHORIZATION_COUNT', `${methodName(method)} requires exactly one method-level @WpAuthorization; found ${authorization.length}.`);\n if (!endpoint && authorization.length) add(out, file, source, method, 'HTTP_ORPHAN_AUTHORIZATION', '@WpAuthorization requires an @Endpoint.');\n const isPublic = uses.some((use: DecoratorUse) => use.name === 'WpAuthPublic');\n for (const use of uses) {\n if (LEGACY_AUTH.has(use.name)) add(out, file, source, use.decorator, 'HTTP_AUTH_MIGRATION', `@${use.name} was removed. Migrate credentials to @WpAuth([...]), operation policy to @WpAuthorization, and locality to @WpLocalOnly.`);\n const problems = use.name === 'WpAuth'\n ? SecurityPolicyShapes.authentication(use.call, use.imports.named, use.imports.namespaces)\n : use.name === 'WpAuthorization'\n ? SecurityPolicyShapes.authorization(use.call, isPublic, use.imports.named, use.imports.namespaces)\n : [];\n for (const problem of problems) add(out, file, source, use.decorator, problem.code, problem.message);\n }\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkInternalMethod(\n file: string,\n source: ts.SourceFile,\n method: ts.MethodDeclaration,\n uses: DecoratorUse[],\n out: SecurityContractViolation[],\n ids: Set<string>,\n): void {\n const ipc = uses.filter((use: DecoratorUse) => use.name === 'WpIpcEndpoint');\n const endpoint = uses.some((use: DecoratorUse) => use.name === 'Endpoint');\n const auth = uses.some((use: DecoratorUse) => (HTTP_AUTH.has(use.name) || LEGACY_AUTH.has(use.name) || use.name === 'WpAuthorization' || use.name === 'WpLocalOnly'));\n const label = methodName(method);\n if (ipc.length !== 1)\n add(\n out,\n file,\n source,\n method,\n 'IPC_ENDPOINT_COUNT',\n `${label} must have exactly one @WpIpcEndpoint('stable-method-id'); found ${ipc.length}.`,\n );\n if (endpoint || auth)\n add(\n out,\n file,\n source,\n method,\n 'IPC_HTTP_MIX',\n `${label} is internal and cannot use @Endpoint or @WpAuth*.`,\n );\n if (method.parameters.length !== 1)\n add(\n out,\n file,\n source,\n method,\n 'IPC_DTO_COUNT',\n `${label} must accept exactly one DTO argument; found ${method.parameters.length}.`,\n );\n if (!hasPromiseReturn(method))\n add(\n out,\n file,\n source,\n method,\n 'IPC_PROMISE_RETURN',\n `${label} must declare a Promise return type.`,\n );\n for (const use of ipc) {\n const id = literalId(use);\n if (id === null)\n add(\n out,\n file,\n source,\n use.decorator,\n 'IPC_METHOD_ID',\n `${label} requires a non-empty inline stable method id.`,\n );\n else if (ids.has(id))\n add(\n out,\n file,\n source,\n use.decorator,\n 'IPC_DUPLICATE_METHOD_ID',\n `${label} duplicates IPC method id '${id}'.`,\n );\n else ids.add(id);\n }\n}\n\nclass InternalApiId {\n constructor(\n readonly id: string,\n readonly file: string,\n readonly source: ts.SourceFile,\n readonly node: ts.Node,\n ) {}\n}\n\nclass ApiClassAudit {\n readonly classUses: DecoratorUse[];\n readonly methods: ts.MethodDeclaration[];\n readonly methodUses: DecoratorUse[][];\n readonly apiPaths: DecoratorUse[];\n readonly internals: DecoratorUse[];\n readonly classAuth: DecoratorUse[];\n readonly hasHttpMethod: boolean;\n readonly hasIpcMethod: boolean;\n readonly className: string;\n\n constructor(\n readonly statement: ts.ClassDeclaration,\n imports: CanonicalImports,\n ) {\n this.classUses = decoratorsOf(statement, imports);\n this.methods = statement.members.filter(ts.isMethodDeclaration);\n this.methodUses = this.methods.map((method: ts.MethodDeclaration) =>\n decoratorsOf(method, imports),\n );\n this.apiPaths = this.classUses.filter((use: DecoratorUse) => use.name === 'ApiPath');\n this.internals = this.classUses.filter((use: DecoratorUse) => use.name === 'WpInternal');\n this.classAuth = this.classUses.filter((use: DecoratorUse) => HTTP_AUTH.has(use.name) || LEGACY_AUTH.has(use.name) || use.name === 'WpAuthorization' || use.name === 'WpLocalOnly');\n this.hasHttpMethod = this.methodUses.some((uses: DecoratorUse[]) =>\n uses.some((use: DecoratorUse) => use.name === 'Endpoint'),\n );\n this.hasIpcMethod = this.methodUses.some((uses: DecoratorUse[]) =>\n uses.some((use: DecoratorUse) => use.name === 'WpIpcEndpoint'),\n );\n this.className = statement.name?.text ?? '<anonymous class>';\n }\n\n get isHttp(): boolean {\n return this.apiPaths.length > 0 || this.hasHttpMethod;\n }\n\n get isInternal(): boolean {\n return this.internals.length > 0 || this.hasIpcMethod;\n }\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkClassShape(\n file: string,\n source: ts.SourceFile,\n audit: ApiClassAudit,\n out: SecurityContractViolation[],\n): void {\n if (audit.hasHttpMethod && audit.apiPaths.length === 0)\n add(\n out,\n file,\n source,\n audit.statement,\n 'HTTP_MISSING_API_PATH',\n `${audit.className} has @Endpoint methods but no @ApiPath.`,\n );\n if (audit.hasIpcMethod && audit.internals.length === 0)\n add(\n out,\n file,\n source,\n audit.statement,\n 'IPC_MISSING_INTERNAL',\n `${audit.className} has @WpIpcEndpoint methods but no @WpInternal('stable-api-id').`,\n );\n if (audit.apiPaths.length > 1)\n add(\n out,\n file,\n source,\n audit.statement,\n 'HTTP_API_PATH_COUNT',\n `${audit.className} has multiple @ApiPath decorators.`,\n );\n if (audit.internals.length > 1)\n add(\n out,\n file,\n source,\n audit.statement,\n 'IPC_INTERNAL_COUNT',\n `${audit.className} has multiple @WpInternal decorators.`,\n );\n if (audit.classAuth.length > 0)\n add(\n out,\n file,\n source,\n audit.classAuth[0]!.decorator,\n 'HTTP_CLASS_AUTH',\n `${audit.className} cannot declare class-level @WpAuth*; annotate every @Endpoint method.`,\n );\n if (audit.isHttp && audit.isInternal)\n add(\n out,\n file,\n source,\n audit.statement,\n 'HTTP_IPC_CLASS_MIX',\n `${audit.className} mixes HTTP and internal IPC contract metadata.`,\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkClassMethods(\n file: string,\n source: ts.SourceFile,\n audit: ApiClassAudit,\n out: SecurityContractViolation[],\n apiIds: InternalApiId[],\n): void {\n if (audit.internals.length === 0) {\n if (audit.isHttp)\n audit.methods.forEach((method: ts.MethodDeclaration, index: number) =>\n checkHttpMethod(file, source, method, audit.methodUses[index]!, out),\n );\n return;\n }\n const internal = audit.internals[0]!;\n const id = literalId(internal);\n if (id === null)\n add(\n out,\n file,\n source,\n internal.decorator,\n 'IPC_API_ID',\n `${audit.className} requires @WpInternal('non-empty-stable-api-id').`,\n );\n else apiIds.push(new InternalApiId(id, file, source, internal.decorator));\n if (audit.apiPaths.length > 0)\n add(\n out,\n file,\n source,\n audit.apiPaths[0]!.decorator,\n 'IPC_API_PATH',\n `${audit.className} is internal and cannot use @ApiPath.`,\n );\n const ids = new Set<string>();\n audit.methods.forEach((method: ts.MethodDeclaration, index: number) =>\n checkInternalMethod(file, source, method, audit.methodUses[index]!, out, ids),\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction auditFile(\n file: string,\n workspaceRoot: string,\n apiIds: InternalApiId[],\n): SecurityContractViolation[] {\n const content = fs.readFileSync(path.join(workspaceRoot, file), 'utf-8');\n const source = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);\n const imports = importsOf(source);\n const out: SecurityContractViolation[] = [];\n for (const statement of source.statements) {\n if (!ts.isClassDeclaration(statement)) continue;\n const audit = new ApiClassAudit(statement, imports);\n if (!audit.isHttp && !audit.isInternal && audit.classAuth.length === 0) continue;\n checkClassShape(file, source, audit, out);\n checkClassMethods(file, source, audit, out, apiIds);\n }\n return out;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction owningProjectJson(workspaceRoot: string, relativeFile: string): string | null {\n let dir = path.dirname(relativeFile);\n while (dir !== '.' && dir !== '') {\n const candidate = path.join(dir, 'project.json');\n if (fs.existsSync(path.join(workspaceRoot, candidate))) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return fs.existsSync(path.join(workspaceRoot, 'project.json')) ? 'project.json' : null;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nexport function findDirectlyChangedProjectRoots(\n workspaceRoot: string,\n changedFiles: string[],\n): string[] {\n const roots = new Set<string>();\n for (const file of changedFiles) {\n const projectJson = owningProjectJson(workspaceRoot, file);\n if (projectJson !== null) roots.add(path.dirname(projectJson));\n }\n return [...roots].sort();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction projectFiles(workspaceRoot: string, projectRoot: string): string[] {\n const files: string[] = [];\n const fullRoot = path.join(workspaceRoot, projectRoot);\n const walk = (dir: string): void => {\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === '.git')\n continue;\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) walk(full);\n else if (\n /\\.tsx?$/.test(entry.name) &&\n !entry.name.endsWith('.d.ts') &&\n !entry.name.endsWith('.spec.ts') &&\n !entry.name.endsWith('.test.ts') &&\n !entry.name.endsWith('.spec.tsx') &&\n !entry.name.endsWith('.test.tsx')\n ) {\n const rel = path.relative(workspaceRoot, full);\n const owner = owningProjectJson(workspaceRoot, rel);\n if (owner !== null && path.dirname(owner) === projectRoot) files.push(rel);\n }\n }\n };\n if (fs.existsSync(fullRoot)) walk(fullRoot);\n return files.sort();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nexport function auditSecurityContracts(\n workspaceRoot: string,\n projectRoots: string[],\n): SecurityContractViolation[] {\n const apiIds: InternalApiId[] = [];\n const files = projectRoots.flatMap((root: string) => projectFiles(workspaceRoot, root));\n const out = files.flatMap((file: string) => auditFile(file, workspaceRoot, apiIds));\n const byId = new Map<string, InternalApiId[]>();\n for (const api of apiIds) byId.set(api.id, [...(byId.get(api.id) ?? []), api]);\n for (const entry of byId.entries()) {\n const id = entry[0];\n const duplicates = entry[1];\n if (duplicates.length < 2) continue;\n for (const duplicate of duplicates)\n add(\n out,\n duplicate.file,\n duplicate.source,\n duplicate.node,\n 'IPC_DUPLICATE_API_ID',\n `Duplicate internal API id '${id}'.`,\n );\n }\n return out.sort(\n (a: SecurityContractViolation, b: SecurityContractViolation) =>\n a.file.localeCompare(b.file) ||\n a.line - b.line ||\n a.code.localeCompare(b.code) ||\n a.message.localeCompare(b.message),\n );\n}\n\n// webpieces-disable no-function-outside-class -- one structured rule failure shared by tests and runner\nexport function securityContractsError(\n violations: readonly SecurityContractViolation[],\n): RuleFailError {\n const details = violations\n .map(\n (violation: SecurityContractViolation): string =>\n ` ${violation.file}:${String(violation.line)} [${violation.code}] ${violation.message}`,\n )\n .join('\\n');\n const first = violations[0];\n const message =\n 'API contracts in directly changed projects are not explicit and secure.\\n' + details;\n return new RuleFailError(\n \"ensure-we-are-secure\",\n message,\n first?.line,\n first === undefined ? undefined : `[${first.code}] ${first.message}`,\n [\n new Option(\n \"Put exactly one authenticated method-level @WpAuth or @WpAuthPublic decorator on every @Endpoint. Use @WpAuthPublic('non-empty reason') only when anonymous access is deliberate.\",\n true,\n ),\n new Option(\n \"For IPC-only contracts, replace HTTP metadata with class-level @WpInternal('stable-api-id') and exactly one @WpIpcEndpoint('stable-method-id') per method.\",\n ),\n ],\n );\n}\n\n// webpieces-disable no-function-outside-class -- one plumbing failure shared by tests and runner\nexport function missingSecurityBaseError(): InformAiError {\n return new InformAiError(\n 'ensure-we-are-secure could not determine the comparison base. Set NX_BASE to the base branch or commit and retry.',\n );\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class EnsureWeAreSecureValidator extends CodeValidator<EnsureWeAreSecureConfig> {\n constructor(config: EnsureWeAreSecureConfig) {\n super(config, 'ensure-we-are-secure', 'ensure-we-are-secure');\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n if (this.config.mode === 'OFF') return { success: true };\n const base = process.env['NX_BASE'] ?? detectBase(workspaceRoot);\n if (base === null || base === undefined) {\n throw missingSecurityBaseError();\n }\n const changed = getChangedFiles(workspaceRoot, base, process.env['NX_HEAD'], {\n tsOnly: false,\n });\n const roots = findDirectlyChangedProjectRoots(workspaceRoot, changed);\n const violations = auditSecurityContracts(workspaceRoot, roots);\n if (violations.length === 0) return { success: true };\n throw securityContractsError(violations);\n }\n}\n"]}
1
+ {"version":3,"file":"validate-ensure-we-are-secure.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/validate-ensure-we-are-secure.ts"],"names":[],"mappings":";;;AAgfA,0EAUC;AA+BD,wDA8BC;AAGD,wDA2BC;AAGD,4DAIC;;AA5lBD,+FAA+F;AAC/F,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,qEAAgE;AAChE,0DAA6F;AAC7F,yDAAiE;AACjE,8DAA0D;AAC1D,yCAA2D;AAC3D,qDAAiE;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AA0B;IADtC,IAAA,sBAAU,EAAC,8BAAkB,CAAC,SAAS,CAAC;6CAEjB,sCAAuB;GADlC,0BAA0B,CAmBtC","sourcesContent":["/** Audits explicit HTTP authentication and IPC-only contracts in directly changed projects. */\nimport * as fs from 'fs';\nimport * as path from 'path';\nimport * as ts from 'typescript';\nimport { SecurityPolicyShapes } from './security-policy-shapes';\nimport { getChangedFiles, detectBase, Option, RuleFailError } from \"@webpieces/rules-config\";\nimport { EnsureWeAreSecureConfig } from \"./configs/rule-configs\";\nimport { InformAiError } from '@webpieces/tooling-common';\nimport { injectable, bindingScopeValues } from 'inversify';\nimport { CodeValidator, ExecutorResult } from './code-validator';\n\nconst HTTP_AUTH = new Set(['WpAuth', 'WpAuthPublic']);\nconst LEGACY_AUTH = new Set(['WpAuthJwt', 'WpAuthOidc', 'WpAuthWebhook', 'WpAuthSharedSecret', 'WpAuthApiKey', 'WpAuthLocalOnly', 'WpMcpAuthJwt']);\nconst CONTRACT_DECORATORS = new Set([\n ...HTTP_AUTH,\n ...LEGACY_AUTH,\n 'WpAuthorization', 'WpLocalOnly', 'AuthorizationType',\n 'jwt', 'oidcSameProject', 'oidcSvcs', 'sharedSecret', 'webhook', 'apiKey',\n 'ApiPath',\n 'Endpoint',\n 'WpInternal',\n 'WpIpcEndpoint',\n]);\n\nexport class SecurityContractViolation {\n constructor(\n readonly file: string,\n readonly line: number,\n readonly code: string,\n readonly message: string,\n ) {}\n}\n\nclass DecoratorUse {\n constructor(\n readonly name: string,\n readonly decorator: ts.Decorator,\n readonly call: ts.CallExpression | null,\n readonly imports: CanonicalImports,\n ) {}\n}\n\nclass CanonicalImports {\n readonly named = new Map<string, string>();\n readonly namespaces = new Set<string>();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction isCanonicalModule(moduleName: string): boolean {\n return (\n moduleName === '@webpieces/core-util' ||\n moduleName === '@webpieces/http-routing' ||\n moduleName === '@webpieces/http-client-browser' ||\n moduleName.endsWith('/core-util/src/http/auth-mode') ||\n moduleName.endsWith('/core-util/src/http/authorization') ||\n moduleName === '@webpieces/core-util/ipc' ||\n moduleName.endsWith('/core-util/src/http/decorators') ||\n moduleName.includes('/core-util/src/ipc/')\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction importsOf(source: ts.SourceFile): CanonicalImports {\n const result = new CanonicalImports();\n for (const statement of source.statements) {\n if (!ts.isImportDeclaration(statement) || !ts.isStringLiteral(statement.moduleSpecifier))\n continue;\n if (!isCanonicalModule(statement.moduleSpecifier.text)) continue;\n const bindings = statement.importClause?.namedBindings;\n if (bindings && ts.isNamedImports(bindings)) {\n for (const item of bindings.elements) {\n const exported = item.propertyName?.text ?? item.name.text;\n if (CONTRACT_DECORATORS.has(exported)) result.named.set(item.name.text, exported);\n }\n } else if (bindings && ts.isNamespaceImport(bindings)) {\n result.namespaces.add(bindings.name.text);\n }\n }\n return result;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction decoratorUse(decorator: ts.Decorator, imports: CanonicalImports): DecoratorUse | null {\n const expr = decorator.expression;\n const call = ts.isCallExpression(expr) ? expr : null;\n const callee = call?.expression ?? expr;\n if (ts.isIdentifier(callee)) {\n const canonical = imports.named.get(callee.text);\n return canonical ? new DecoratorUse(canonical, decorator, call, imports) : null;\n }\n if (\n ts.isPropertyAccessExpression(callee) &&\n ts.isIdentifier(callee.expression) &&\n imports.namespaces.has(callee.expression.text)\n ) {\n return CONTRACT_DECORATORS.has(callee.name.text)\n ? new DecoratorUse(callee.name.text, decorator, call, imports)\n : null;\n }\n return null;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction decoratorsOf(node: ts.Node, imports: CanonicalImports): DecoratorUse[] {\n if (!ts.canHaveDecorators(node)) return [];\n return (ts.getDecorators(node) ?? [])\n .map((decorator: ts.Decorator) => decoratorUse(decorator, imports))\n .filter((use): use is DecoratorUse => use !== null);\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction lineOf(source: ts.SourceFile, node: ts.Node): number {\n return source.getLineAndCharacterOfPosition(node.getStart(source)).line + 1;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction literalId(use: DecoratorUse): string | null {\n const arg = use.call?.arguments[0];\n if (!arg || (!ts.isStringLiteral(arg) && !ts.isNoSubstitutionTemplateLiteral(arg))) return null;\n const value = arg.text.trim();\n return value.length > 0 ? value : null;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction methodName(method: ts.MethodDeclaration): string {\n return ts.isIdentifier(method.name) || ts.isStringLiteral(method.name)\n ? method.name.text\n : method.name.getText();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction hasPromiseReturn(method: ts.MethodDeclaration): boolean {\n const type = method.type;\n return (\n type !== undefined &&\n ts.isTypeReferenceNode(type) &&\n ts.isIdentifier(type.typeName) &&\n type.typeName.text === 'Promise'\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction add(\n out: SecurityContractViolation[],\n file: string,\n source: ts.SourceFile,\n node: ts.Node,\n code: string,\n message: string,\n): void {\n out.push(new SecurityContractViolation(file, lineOf(source, node), code, message));\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkHttpMethod(\n file: string,\n source: ts.SourceFile,\n method: ts.MethodDeclaration,\n uses: DecoratorUse[],\n out: SecurityContractViolation[],\n): void {\n const endpoints = uses.filter((use: DecoratorUse) => use.name === 'Endpoint');\n const auth = uses.filter((use: DecoratorUse) => HTTP_AUTH.has(use.name));\n const ipc = uses.filter((use: DecoratorUse) => use.name === 'WpIpcEndpoint');\n const label = methodName(method);\n checkAuthorization(file, source, method, uses, out);\n if (endpoints.length > 1)\n add(\n out,\n file,\n source,\n method,\n 'HTTP_MULTIPLE_ENDPOINTS',\n `${label} has multiple @Endpoint decorators.`,\n );\n if (endpoints.length > 0 && auth.length !== 1) {\n add(\n out,\n file,\n source,\n method,\n 'HTTP_AUTH_COUNT',\n `${label} must have exactly one method-level @WpAuth or @WpAuthPublic decorator; found ${auth.length}. Prefer an authenticated mode; use @WpAuthPublic('reason') only for deliberate anonymous access.`,\n );\n }\n if (endpoints.length === 0 && auth.length > 0)\n add(\n out,\n file,\n source,\n auth[0]!.decorator,\n 'HTTP_ORPHAN_AUTH',\n `${label} has @WpAuth* but no @Endpoint.`,\n );\n for (const publicUse of auth.filter((use: DecoratorUse) => use.name === 'WpAuthPublic')) {\n if (literalId(publicUse) === null)\n add(\n out,\n file,\n source,\n publicUse.decorator,\n 'HTTP_PUBLIC_REASON',\n `${label} must use @WpAuthPublic('non-empty reason').`,\n );\n }\n if (ipc.length > 0)\n add(\n out,\n file,\n source,\n ipc[0]!.decorator,\n 'HTTP_IPC_MIX',\n `${label} mixes HTTP and IPC endpoint metadata.`,\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless security declaration audit shared by all served endpoints\nfunction checkAuthorization(file: string, source: ts.SourceFile, method: ts.MethodDeclaration, uses: DecoratorUse[], out: SecurityContractViolation[]): void {\n const endpoint = uses.some((use: DecoratorUse) => use.name === 'Endpoint');\n const authorization = uses.filter((use: DecoratorUse) => use.name === 'WpAuthorization');\n if (endpoint && authorization.length !== 1) add(out, file, source, method, 'HTTP_AUTHORIZATION_COUNT', `${methodName(method)} requires exactly one method-level @WpAuthorization; found ${authorization.length}.`);\n if (!endpoint && authorization.length) add(out, file, source, method, 'HTTP_ORPHAN_AUTHORIZATION', '@WpAuthorization requires an @Endpoint.');\n const isPublic = uses.some((use: DecoratorUse) => use.name === 'WpAuthPublic');\n for (const use of uses) {\n if (LEGACY_AUTH.has(use.name)) add(out, file, source, use.decorator, 'HTTP_AUTH_MIGRATION', `@${use.name} was removed. Migrate credentials to @WpAuth([...]), operation policy to @WpAuthorization, and locality to @WpLocalOnly.`);\n const problems = use.name === 'WpAuth'\n ? SecurityPolicyShapes.authentication(use.call, use.imports.named, use.imports.namespaces)\n : use.name === 'WpAuthorization'\n ? SecurityPolicyShapes.authorization(use.call, isPublic, use.imports.named, use.imports.namespaces)\n : [];\n for (const problem of problems) add(out, file, source, use.decorator, problem.code, problem.message);\n }\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkInternalMethod(\n file: string,\n source: ts.SourceFile,\n method: ts.MethodDeclaration,\n uses: DecoratorUse[],\n out: SecurityContractViolation[],\n ids: Set<string>,\n): void {\n const ipc = uses.filter((use: DecoratorUse) => use.name === 'WpIpcEndpoint');\n const endpoint = uses.some((use: DecoratorUse) => use.name === 'Endpoint');\n const auth = uses.some((use: DecoratorUse) => (HTTP_AUTH.has(use.name) || LEGACY_AUTH.has(use.name) || use.name === 'WpAuthorization' || use.name === 'WpLocalOnly'));\n const label = methodName(method);\n if (ipc.length !== 1)\n add(\n out,\n file,\n source,\n method,\n 'IPC_ENDPOINT_COUNT',\n `${label} must have exactly one @WpIpcEndpoint('stable-method-id'); found ${ipc.length}.`,\n );\n if (endpoint || auth)\n add(\n out,\n file,\n source,\n method,\n 'IPC_HTTP_MIX',\n `${label} is internal and cannot use @Endpoint or @WpAuth*.`,\n );\n if (method.parameters.length !== 1)\n add(\n out,\n file,\n source,\n method,\n 'IPC_DTO_COUNT',\n `${label} must accept exactly one DTO argument; found ${method.parameters.length}.`,\n );\n if (!hasPromiseReturn(method))\n add(\n out,\n file,\n source,\n method,\n 'IPC_PROMISE_RETURN',\n `${label} must declare a Promise return type.`,\n );\n for (const use of ipc) {\n const id = literalId(use);\n if (id === null)\n add(\n out,\n file,\n source,\n use.decorator,\n 'IPC_METHOD_ID',\n `${label} requires a non-empty inline stable method id.`,\n );\n else if (ids.has(id))\n add(\n out,\n file,\n source,\n use.decorator,\n 'IPC_DUPLICATE_METHOD_ID',\n `${label} duplicates IPC method id '${id}'.`,\n );\n else ids.add(id);\n }\n}\n\nclass InternalApiId {\n constructor(\n readonly id: string,\n readonly file: string,\n readonly source: ts.SourceFile,\n readonly node: ts.Node,\n ) {}\n}\n\nclass ApiClassAudit {\n readonly classUses: DecoratorUse[];\n readonly methods: ts.MethodDeclaration[];\n readonly methodUses: DecoratorUse[][];\n readonly apiPaths: DecoratorUse[];\n readonly internals: DecoratorUse[];\n readonly classAuth: DecoratorUse[];\n readonly hasHttpMethod: boolean;\n readonly hasIpcMethod: boolean;\n readonly className: string;\n\n constructor(\n readonly statement: ts.ClassDeclaration,\n imports: CanonicalImports,\n ) {\n this.classUses = decoratorsOf(statement, imports);\n this.methods = statement.members.filter(ts.isMethodDeclaration);\n this.methodUses = this.methods.map((method: ts.MethodDeclaration) =>\n decoratorsOf(method, imports),\n );\n this.apiPaths = this.classUses.filter((use: DecoratorUse) => use.name === 'ApiPath');\n this.internals = this.classUses.filter((use: DecoratorUse) => use.name === 'WpInternal');\n this.classAuth = this.classUses.filter((use: DecoratorUse) => HTTP_AUTH.has(use.name) || LEGACY_AUTH.has(use.name) || use.name === 'WpAuthorization' || use.name === 'WpLocalOnly');\n this.hasHttpMethod = this.methodUses.some((uses: DecoratorUse[]) =>\n uses.some((use: DecoratorUse) => use.name === 'Endpoint'),\n );\n this.hasIpcMethod = this.methodUses.some((uses: DecoratorUse[]) =>\n uses.some((use: DecoratorUse) => use.name === 'WpIpcEndpoint'),\n );\n this.className = statement.name?.text ?? '<anonymous class>';\n }\n\n get isHttp(): boolean {\n return this.apiPaths.length > 0 || this.hasHttpMethod;\n }\n\n get isInternal(): boolean {\n return this.internals.length > 0 || this.hasIpcMethod;\n }\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkClassShape(\n file: string,\n source: ts.SourceFile,\n audit: ApiClassAudit,\n out: SecurityContractViolation[],\n): void {\n if (audit.hasHttpMethod && audit.apiPaths.length === 0)\n add(\n out,\n file,\n source,\n audit.statement,\n 'HTTP_MISSING_API_PATH',\n `${audit.className} has @Endpoint methods but no @ApiPath.`,\n );\n if (audit.hasIpcMethod && audit.internals.length === 0)\n add(\n out,\n file,\n source,\n audit.statement,\n 'IPC_MISSING_INTERNAL',\n `${audit.className} has @WpIpcEndpoint methods but no @WpInternal('stable-api-id').`,\n );\n if (audit.apiPaths.length > 1)\n add(\n out,\n file,\n source,\n audit.statement,\n 'HTTP_API_PATH_COUNT',\n `${audit.className} has multiple @ApiPath decorators.`,\n );\n if (audit.internals.length > 1)\n add(\n out,\n file,\n source,\n audit.statement,\n 'IPC_INTERNAL_COUNT',\n `${audit.className} has multiple @WpInternal decorators.`,\n );\n if (audit.classAuth.length > 0)\n add(\n out,\n file,\n source,\n audit.classAuth[0]!.decorator,\n 'HTTP_CLASS_AUTH',\n `${audit.className} cannot declare class-level @WpAuth*; annotate every @Endpoint method.`,\n );\n if (audit.isHttp && audit.isInternal)\n add(\n out,\n file,\n source,\n audit.statement,\n 'HTTP_IPC_CLASS_MIX',\n `${audit.className} mixes HTTP and internal IPC contract metadata.`,\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction checkClassMethods(\n file: string,\n source: ts.SourceFile,\n audit: ApiClassAudit,\n out: SecurityContractViolation[],\n apiIds: InternalApiId[],\n): void {\n if (audit.internals.length === 0) {\n if (audit.isHttp)\n audit.methods.forEach((method: ts.MethodDeclaration, index: number) =>\n checkHttpMethod(file, source, method, audit.methodUses[index]!, out),\n );\n return;\n }\n const internal = audit.internals[0]!;\n const id = literalId(internal);\n if (id === null)\n add(\n out,\n file,\n source,\n internal.decorator,\n 'IPC_API_ID',\n `${audit.className} requires @WpInternal('non-empty-stable-api-id').`,\n );\n else apiIds.push(new InternalApiId(id, file, source, internal.decorator));\n if (audit.apiPaths.length > 0)\n add(\n out,\n file,\n source,\n audit.apiPaths[0]!.decorator,\n 'IPC_API_PATH',\n `${audit.className} is internal and cannot use @ApiPath.`,\n );\n const ids = new Set<string>();\n audit.methods.forEach((method: ts.MethodDeclaration, index: number) =>\n checkInternalMethod(file, source, method, audit.methodUses[index]!, out, ids),\n );\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction auditFile(\n file: string,\n workspaceRoot: string,\n apiIds: InternalApiId[],\n): SecurityContractViolation[] {\n const content = fs.readFileSync(path.join(workspaceRoot, file), 'utf-8');\n const source = ts.createSourceFile(file, content, ts.ScriptTarget.Latest, true);\n const imports = importsOf(source);\n const out: SecurityContractViolation[] = [];\n for (const statement of source.statements) {\n if (!ts.isClassDeclaration(statement)) continue;\n const audit = new ApiClassAudit(statement, imports);\n if (!audit.isHttp && !audit.isInternal && audit.classAuth.length === 0) continue;\n checkClassShape(file, source, audit, out);\n checkClassMethods(file, source, audit, out, apiIds);\n }\n return out;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction owningProjectJson(workspaceRoot: string, relativeFile: string): string | null {\n let dir = path.dirname(relativeFile);\n while (dir !== '.' && dir !== '') {\n const candidate = path.join(dir, 'project.json');\n if (fs.existsSync(path.join(workspaceRoot, candidate))) return candidate;\n const parent = path.dirname(dir);\n if (parent === dir) break;\n dir = parent;\n }\n return fs.existsSync(path.join(workspaceRoot, 'project.json')) ? 'project.json' : null;\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nexport function findDirectlyChangedProjectRoots(\n workspaceRoot: string,\n changedFiles: string[],\n): string[] {\n const roots = new Set<string>();\n for (const file of changedFiles) {\n const projectJson = owningProjectJson(workspaceRoot, file);\n if (projectJson !== null) roots.add(path.dirname(projectJson));\n }\n return [...roots].sort();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nfunction projectFiles(workspaceRoot: string, projectRoot: string): string[] {\n const files: string[] = [];\n const fullRoot = path.join(workspaceRoot, projectRoot);\n const walk = (dir: string): void => {\n for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {\n if (entry.name === 'node_modules' || entry.name === 'dist' || entry.name === '.git')\n continue;\n const full = path.join(dir, entry.name);\n if (entry.isDirectory()) walk(full);\n else if (\n /\\.tsx?$/.test(entry.name) &&\n !entry.name.endsWith('.d.ts') &&\n !entry.name.endsWith('.spec.ts') &&\n !entry.name.endsWith('.test.ts') &&\n !entry.name.endsWith('.spec.tsx') &&\n !entry.name.endsWith('.test.tsx')\n ) {\n const rel = path.relative(workspaceRoot, full);\n const owner = owningProjectJson(workspaceRoot, rel);\n if (owner !== null && path.dirname(owner) === projectRoot) files.push(rel);\n }\n }\n };\n if (fs.existsSync(fullRoot)) walk(fullRoot);\n return files.sort();\n}\n\n// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper\nexport function auditSecurityContracts(\n workspaceRoot: string,\n projectRoots: string[],\n): SecurityContractViolation[] {\n const apiIds: InternalApiId[] = [];\n const files = projectRoots.flatMap((root: string) => projectFiles(workspaceRoot, root));\n const out = files.flatMap((file: string) => auditFile(file, workspaceRoot, apiIds));\n const byId = new Map<string, InternalApiId[]>();\n for (const api of apiIds) byId.set(api.id, [...(byId.get(api.id) ?? []), api]);\n for (const entry of byId.entries()) {\n const id = entry[0];\n const duplicates = entry[1];\n if (duplicates.length < 2) continue;\n for (const duplicate of duplicates)\n add(\n out,\n duplicate.file,\n duplicate.source,\n duplicate.node,\n 'IPC_DUPLICATE_API_ID',\n `Duplicate internal API id '${id}'.`,\n );\n }\n return out.sort(\n (a: SecurityContractViolation, b: SecurityContractViolation) =>\n a.file.localeCompare(b.file) ||\n a.line - b.line ||\n a.code.localeCompare(b.code) ||\n a.message.localeCompare(b.message),\n );\n}\n\n// webpieces-disable no-function-outside-class -- one structured rule failure shared by tests and runner\nexport function securityContractsError(\n violations: readonly SecurityContractViolation[],\n): RuleFailError {\n const details = violations\n .map(\n (violation: SecurityContractViolation): string =>\n ` ${violation.file}:${String(violation.line)} [${violation.code}] ${violation.message}`,\n )\n .join('\\n');\n const first = violations[0];\n const message =\n 'API contracts in directly changed projects are not explicit and secure.\\n' + details;\n return new RuleFailError(\n \"ensure-we-are-secure\",\n message,\n first?.line,\n first === undefined ? undefined : `[${first.code}] ${first.message}`,\n [\n new Option(\n \"Put exactly one authenticated method-level @WpAuth or @WpAuthPublic decorator on every @Endpoint. Use @WpAuthPublic('non-empty reason') only when anonymous access is deliberate.\",\n true,\n ),\n new Option(\n \"For IPC-only contracts, replace HTTP metadata with class-level @WpInternal('stable-api-id') and exactly one @WpIpcEndpoint('stable-method-id') per method.\",\n ),\n ],\n );\n}\n\n// webpieces-disable no-function-outside-class -- one plumbing failure shared by tests and runner\nexport function missingSecurityBaseError(): InformAiError {\n return new InformAiError(\n 'ensure-we-are-secure could not determine the comparison base. Set NX_BASE to the base branch or commit and retry.',\n );\n}\n\n@injectable(bindingScopeValues.Singleton)\nexport class EnsureWeAreSecureValidator extends CodeValidator<EnsureWeAreSecureConfig> {\n constructor(config: EnsureWeAreSecureConfig) {\n super(config, 'ensure-we-are-secure', 'ensure-we-are-secure');\n }\n\n async run(workspaceRoot: string): Promise<ExecutorResult> {\n if (this.config.mode === 'OFF') return { success: true };\n const base = process.env['NX_BASE'] ?? detectBase(workspaceRoot);\n if (base === null || base === undefined) {\n throw missingSecurityBaseError();\n }\n const changed = getChangedFiles(workspaceRoot, base, process.env['NX_HEAD'], {\n tsOnly: false,\n });\n const roots = findDirectlyChangedProjectRoots(workspaceRoot, changed);\n const violations = auditSecurityContracts(workspaceRoot, roots);\n if (violations.length === 0) return { success: true };\n throw securityContractsError(violations);\n }\n}\n"]}