@webpieces/code-rules 0.4.863 → 0.4.864
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 +6 -6
- package/src/rule-help.js +1 -1
- package/src/rule-help.js.map +1 -1
- package/src/security-policy-shapes.d.ts +15 -0
- package/src/security-policy-shapes.js +114 -0
- package/src/security-policy-shapes.js.map +1 -0
- package/src/validate-ensure-we-are-secure.js +42 -17
- package/src/validate-ensure-we-are-secure.js.map +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webpieces/code-rules",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.864",
|
|
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.
|
|
19
|
+
"@webpieces/rules-config": "0.4.864",
|
|
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.
|
|
24
|
-
"@webpieces/repo-workflow-core": "0.4.
|
|
25
|
-
"@webpieces/rules-sdk": "0.4.
|
|
23
|
+
"@webpieces/tooling-common": "0.4.864",
|
|
24
|
+
"@webpieces/repo-workflow-core": "0.4.864",
|
|
25
|
+
"@webpieces/rules-sdk": "0.4.864"
|
|
26
26
|
},
|
|
27
27
|
"publishConfig": {
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@webpieces/tooling-testkit": "0.4.
|
|
31
|
+
"@webpieces/tooling-testkit": "0.4.864"
|
|
32
32
|
},
|
|
33
33
|
"exports": {
|
|
34
34
|
".": "./src/index.js",
|
package/src/rule-help.js
CHANGED
|
@@ -25,7 +25,7 @@ exports.ruleHelp = {
|
|
|
25
25
|
'inject-annotation-not-needed-for-concrete-class': new rules_sdk_1.RuleHelp('Inject concrete classes by their class token without redundant annotations.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
26
26
|
'framework-tag': new rules_sdk_1.RuleHelp('Match project framework tags to their actual code and package usage.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
27
27
|
'role-tag': new rules_sdk_1.RuleHelp('Match project role tags to their actual API and implementation responsibilities.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
28
|
-
'ensure-we-are-secure': new rules_sdk_1.RuleHelp('
|
|
28
|
+
'ensure-we-are-secure': new rules_sdk_1.RuleHelp('Audit canonical WpAuth credential alternatives and WpAuthorization operation policies on every HTTP endpoint; audit explicit IPC boundaries.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
29
29
|
'no-inline-import-in-api-lib': new rules_sdk_1.RuleHelp('Keep API library type imports explicit and named.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
30
30
|
'one-enum-spelling-in-api-lib': new rules_sdk_1.RuleHelp('Use one enum declaration spelling in API libraries.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
|
31
31
|
'no-utility-types-in-api-lib': new rules_sdk_1.RuleHelp('Use explicit named API data contracts instead of utility types.', 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.'),
|
package/src/rule-help.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule-help.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-help.ts"],"names":[],"mappings":";;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CACzI;IACD,2BAA2B,EAAE,IAAI,oBAAQ,CACrC,yDAAyD,EACzD,sIAAsI,CACzI;IACD,iDAAiD,EAAE,IAAI,oBAAQ,CAC3D,6EAA6E,EAC7E,sIAAsI,CACzI;IACD,eAAe,EAAE,IAAI,oBAAQ,CACzB,sEAAsE,EACtE,sIAAsI,CACzI;IACD,UAAU,EAAE,IAAI,oBAAQ,CACpB,kFAAkF,EAClF,sIAAsI,CACzI;IACD,sBAAsB,EAAE,IAAI,oBAAQ,CAChC,
|
|
1
|
+
{"version":3,"file":"rule-help.js","sourceRoot":"","sources":["../../../../../packages/tooling/code-rules/src/rule-help.ts"],"names":[],"mappings":";;;AAAA,oDAAgD;AAEhD,gEAAgE;AACnD,QAAA,QAAQ,GAAuC;IACxD,kBAAkB,EAAE,IAAI,oBAAQ,CAC5B,mDAAmD,EACnD,sIAAsI,CACzI;IACD,gBAAgB,EAAE,IAAI,oBAAQ,CAC1B,wDAAwD,EACxD,sIAAsI,CACzI;IACD,qBAAqB,EAAE,IAAI,oBAAQ,CAC/B,oDAAoD,EACpD,sIAAsI,CACzI;IACD,yBAAyB,EAAE,IAAI,oBAAQ,CACnC,oEAAoE,EACpE,sIAAsI,CACzI;IACD,gBAAgB,EAAE,IAAI,oBAAQ,CAC1B,wEAAwE,EACxE,sIAAsI,CACzI;IACD,iBAAiB,EAAE,IAAI,oBAAQ,CAC3B,0EAA0E,EAC1E,sIAAsI,CACzI;IACD,sBAAsB,EAAE,IAAI,oBAAQ,CAChC,sEAAsE,EACtE,sIAAsI,CACzI;IACD,kBAAkB,EAAE,IAAI,oBAAQ,CAC5B,qEAAqE,EACrE,sIAAsI,CACzI;IACD,gBAAgB,EAAE,IAAI,oBAAQ,CAC1B,wEAAwE,EACxE,sIAAsI,CACzI;IACD,qBAAqB,EAAE,IAAI,oBAAQ,CAC/B,mEAAmE,EACnE,sIAAsI,CACzI;IACD,yBAAyB,EAAE,IAAI,oBAAQ,CACnC,uEAAuE,EACvE,sIAAsI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/** Owner-authored guidance consumed by the registry catalog. */\nexport const ruleHelp: Readonly<Record<string, RuleHelp>> = {\n 'max-method-lines': new RuleHelp(\n 'Limit method length in the configured scan scope.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'max-file-lines': new RuleHelp(\n 'Limit source file length in the configured scan scope.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'require-return-type': new RuleHelp(\n 'Require explicit function and method return types.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-inline-type-literals': new RuleHelp(\n 'Use named data classes instead of inline object type declarations.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-any-unknown': new RuleHelp(\n 'Require concrete types outside explicitly permitted opaque boundaries.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-implicit-any': new RuleHelp(\n 'Require explicit parameter types when inference does not establish them.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'prisma-validate-dtos': new RuleHelp(\n 'Validate Prisma-facing DTO declarations against the generated model.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'prisma-converter': new RuleHelp(\n 'Validate the converters between Prisma models and application DTOs.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-destructure': new RuleHelp(\n 'Use whole values or explicit property access instead of destructuring.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'catch-error-pattern': new RuleHelp(\n 'Narrow caught errors through the shared error conversion pattern.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-unmanaged-exceptions': new RuleHelp(\n 'Handle or explicitly document exceptions at the responsible boundary.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'angular-no-direct-api-in-resolver': new RuleHelp(\n 'Keep direct API client construction out of Angular resolvers.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-symbol-di-tokens': new RuleHelp(\n 'Use class tokens for dependency injection instead of symbol tokens.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-client-creation-outside-server-or-client': new RuleHelp(\n 'Construct API clients only in their designated server or client layer.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-custom-css': new RuleHelp(\n 'Use the configured styling system instead of custom CSS in governed files.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-state-paths-in-templates': new RuleHelp(\n 'Use the declared state binding pattern in application templates.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-process-exit-outside-main': new RuleHelp(\n 'Restrict process termination to executable application boundaries.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-function-outside-class': new RuleHelp(\n 'Put business operations in instance methods on classes.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'inject-annotation-not-needed-for-concrete-class': new RuleHelp(\n 'Inject concrete classes by their class token without redundant annotations.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'framework-tag': new RuleHelp(\n 'Match project framework tags to their actual code and package usage.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'role-tag': new RuleHelp(\n 'Match project role tags to their actual API and implementation responsibilities.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'ensure-we-are-secure': new RuleHelp(\n 'Audit canonical WpAuth credential alternatives and WpAuthorization operation policies on every HTTP endpoint; audit explicit IPC boundaries.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-inline-import-in-api-lib': new RuleHelp(\n 'Keep API library type imports explicit and named.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'one-enum-spelling-in-api-lib': new RuleHelp(\n 'Use one enum declaration spelling in API libraries.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'no-utility-types-in-api-lib': new RuleHelp(\n 'Use explicit named API data contracts instead of utility types.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'required-type-suffix': new RuleHelp(\n 'Require configured suffixes on API contract types.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'framework-tsconfig': new RuleHelp(\n 'Align framework-specific TypeScript settings with project declarations.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n 'framework-packages': new RuleHelp(\n 'Align framework packages with the configured project requirements.',\n 'Apply this policy in source, or review its explicit settings in {configFile}. An intentional opt-out requires complete OFF settings.',\n ),\n};\n"]}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import * as ts from 'typescript';
|
|
2
|
+
export declare class SecurityPolicyShapeProblem {
|
|
3
|
+
readonly code: string;
|
|
4
|
+
readonly message: string;
|
|
5
|
+
constructor(code: string, message: string);
|
|
6
|
+
}
|
|
7
|
+
/** Literal declarations must be inspectable; runtime registration additionally checks erased values. */
|
|
8
|
+
export declare class SecurityPolicyShapes {
|
|
9
|
+
static authentication(call: ts.CallExpression | null, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[];
|
|
10
|
+
private static descriptor;
|
|
11
|
+
static authorization(call: ts.CallExpression | null, isPublic: boolean, named: ReadonlyMap<string, string>, namespaces: ReadonlySet<string>): readonly SecurityPolicyShapeProblem[];
|
|
12
|
+
private static validatePolicyFields;
|
|
13
|
+
private static authorizationType;
|
|
14
|
+
private static canonicalName;
|
|
15
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SecurityPolicyShapes = exports.SecurityPolicyShapeProblem = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const ts = tslib_1.__importStar(require("typescript"));
|
|
6
|
+
class SecurityPolicyShapeProblem {
|
|
7
|
+
code;
|
|
8
|
+
message;
|
|
9
|
+
constructor(code, message) {
|
|
10
|
+
this.code = code;
|
|
11
|
+
this.message = message;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.SecurityPolicyShapeProblem = SecurityPolicyShapeProblem;
|
|
15
|
+
/** Literal declarations must be inspectable; runtime registration additionally checks erased values. */
|
|
16
|
+
class SecurityPolicyShapes {
|
|
17
|
+
// webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
|
|
18
|
+
static authentication(call, named, namespaces) {
|
|
19
|
+
const array = call?.arguments[0];
|
|
20
|
+
if (!array || !ts.isArrayLiteralExpression(array) || !array.elements.length) {
|
|
21
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', '@WpAuth requires a nonempty inline array of canonical credential descriptors.')];
|
|
22
|
+
}
|
|
23
|
+
const seen = new Set();
|
|
24
|
+
const problems = [];
|
|
25
|
+
for (const element of array.elements) {
|
|
26
|
+
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.'));
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
seen.add(name);
|
|
32
|
+
if (ts.isCallExpression(element))
|
|
33
|
+
problems.push(...this.descriptor(name, element));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return problems;
|
|
37
|
+
}
|
|
38
|
+
// webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
|
|
39
|
+
static descriptor(name, call) {
|
|
40
|
+
if (name === 'jwt' && call.arguments.length)
|
|
41
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'jwt() takes no policy; put roles/application policy in @WpAuthorization.')];
|
|
42
|
+
if (['sharedSecret', 'webhook', 'apiKey'].includes(name) && !call.arguments.length)
|
|
43
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', `${name}(...) requires its named credential configuration.`)];
|
|
44
|
+
if (name === 'apiKey' && !call.arguments[1])
|
|
45
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey(regime, credentials) requires a nonempty credentials tuple.')];
|
|
46
|
+
if (name === 'apiKey' && ts.isArrayLiteralExpression(call.arguments[1]) && !call.arguments[1].elements.length)
|
|
47
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTH_METHODS', 'apiKey credentials cannot be empty.')];
|
|
48
|
+
return [];
|
|
49
|
+
}
|
|
50
|
+
// webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
|
|
51
|
+
static authorization(call, isPublic, named, namespaces) {
|
|
52
|
+
const object = call?.arguments[0];
|
|
53
|
+
if (!object || !ts.isObjectLiteralExpression(object))
|
|
54
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', '@WpAuthorization requires an inline discriminated policy; opaque expressions are not proof of a secure declaration.')];
|
|
55
|
+
const fields = new Map();
|
|
56
|
+
for (const property of object.properties) {
|
|
57
|
+
if (!ts.isPropertyAssignment(property) || (!ts.isIdentifier(property.name) && !ts.isStringLiteral(property.name)))
|
|
58
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Authorization policy cannot use spreads, computed fields, or shorthand values.')];
|
|
59
|
+
if (fields.has(property.name.text))
|
|
60
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Authorization policy contains duplicate fields.')];
|
|
61
|
+
fields.set(property.name.text, property.initializer);
|
|
62
|
+
}
|
|
63
|
+
const type = this.authorizationType(fields.get('authType'), named, namespaces);
|
|
64
|
+
const shape = this.validatePolicyFields(type, fields);
|
|
65
|
+
if (shape.length)
|
|
66
|
+
return shape;
|
|
67
|
+
if (isPublic !== (type === 'ANONYMOUS'))
|
|
68
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_PAIRING', 'Pair @WpAuthPublic with ANONYMOUS; protected @WpAuth requires protected/CUSTOM authorization.')];
|
|
69
|
+
return [];
|
|
70
|
+
}
|
|
71
|
+
// webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
|
|
72
|
+
static validatePolicyFields(type, fields) {
|
|
73
|
+
if (!type || !['ALL_USERS', 'ROLES', 'SERVICE_ONLY', 'USERS_OR_SERVICES', 'ANONYMOUS', 'CUSTOM'].includes(type))
|
|
74
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'Declare a canonical AuthorizationType branch.')];
|
|
75
|
+
const allowed = new Set(['authType']);
|
|
76
|
+
if (type === 'ROLES')
|
|
77
|
+
allowed.add('roles');
|
|
78
|
+
if (type === 'ANONYMOUS')
|
|
79
|
+
allowed.add('reason');
|
|
80
|
+
if (type === 'CUSTOM')
|
|
81
|
+
allowed.add('appPolicy');
|
|
82
|
+
if ([...fields.keys()].some((key) => !allowed.has(key)))
|
|
83
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'roles belongs only on ROLES, reason only on ANONYMOUS, and application fields only under CUSTOM.appPolicy.')];
|
|
84
|
+
if (type === 'ROLES') {
|
|
85
|
+
const roles = fields.get('roles');
|
|
86
|
+
if (!roles || !ts.isArrayLiteralExpression(roles) || !roles.elements.length || !roles.elements.every((role) => ts.isStringLiteral(role) && role.text.trim().length > 0))
|
|
87
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'ROLES requires a nonempty inline tuple of nonempty role strings.')];
|
|
88
|
+
}
|
|
89
|
+
if (type === 'ANONYMOUS') {
|
|
90
|
+
const reason = fields.get('reason');
|
|
91
|
+
if (!reason || !ts.isStringLiteral(reason) || !reason.text.trim())
|
|
92
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'ANONYMOUS requires a nonempty reason.')];
|
|
93
|
+
}
|
|
94
|
+
if (type === 'CUSTOM' && !fields.has('appPolicy'))
|
|
95
|
+
return [new SecurityPolicyShapeProblem('HTTP_AUTHORIZATION_POLICY', 'CUSTOM requires appPolicy and a validating AuthorizationHook at startup.')];
|
|
96
|
+
return [];
|
|
97
|
+
}
|
|
98
|
+
// webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
|
|
99
|
+
static authorizationType(expression, named, namespaces) {
|
|
100
|
+
if (!expression || !ts.isPropertyAccessExpression(expression) || this.canonicalName(expression.expression, named, namespaces) !== 'AuthorizationType')
|
|
101
|
+
return undefined;
|
|
102
|
+
return expression.name.text;
|
|
103
|
+
}
|
|
104
|
+
// webpieces-disable no-function-outside-class -- stateless contract validation or scope metadata reader used before DI registration
|
|
105
|
+
static canonicalName(expression, named, namespaces) {
|
|
106
|
+
if (ts.isIdentifier(expression))
|
|
107
|
+
return named.get(expression.text);
|
|
108
|
+
if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression) && namespaces.has(expression.expression.text))
|
|
109
|
+
return expression.name.text;
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.SecurityPolicyShapes = SecurityPolicyShapes;
|
|
114
|
+
//# sourceMappingURL=security-policy-shapes.js.map
|
|
@@ -0,0 +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,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,KAAK,EAAE,MAAM,EAAE,c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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"]}
|
|
@@ -10,22 +10,19 @@ const tslib_1 = require("tslib");
|
|
|
10
10
|
const fs = tslib_1.__importStar(require("fs"));
|
|
11
11
|
const path = tslib_1.__importStar(require("path"));
|
|
12
12
|
const ts = tslib_1.__importStar(require("typescript"));
|
|
13
|
+
const security_policy_shapes_1 = require("./security-policy-shapes");
|
|
13
14
|
const rules_config_1 = require("@webpieces/rules-config");
|
|
14
15
|
const rule_configs_1 = require("./configs/rule-configs");
|
|
15
16
|
const tooling_common_1 = require("@webpieces/tooling-common");
|
|
16
17
|
const inversify_1 = require("inversify");
|
|
17
18
|
const code_validator_1 = require("./code-validator");
|
|
18
|
-
const HTTP_AUTH = new Set([
|
|
19
|
-
|
|
20
|
-
'WpAuthOidc',
|
|
21
|
-
'WpAuthWebhook',
|
|
22
|
-
'WpAuthSharedSecret',
|
|
23
|
-
'WpAuthApiKey',
|
|
24
|
-
'WpAuthLocalOnly',
|
|
25
|
-
'WpAuthPublic',
|
|
26
|
-
]);
|
|
19
|
+
const HTTP_AUTH = new Set(['WpAuth', 'WpAuthPublic']);
|
|
20
|
+
const LEGACY_AUTH = new Set(['WpAuthJwt', 'WpAuthOidc', 'WpAuthWebhook', 'WpAuthSharedSecret', 'WpAuthApiKey', 'WpAuthLocalOnly', 'WpMcpAuthJwt']);
|
|
27
21
|
const CONTRACT_DECORATORS = new Set([
|
|
28
22
|
...HTTP_AUTH,
|
|
23
|
+
...LEGACY_AUTH,
|
|
24
|
+
'WpAuthorization', 'WpLocalOnly', 'AuthorizationType',
|
|
25
|
+
'jwt', 'oidc', 'sharedSecret', 'webhook', 'apiKey',
|
|
29
26
|
'ApiPath',
|
|
30
27
|
'Endpoint',
|
|
31
28
|
'WpInternal',
|
|
@@ -48,10 +45,12 @@ class DecoratorUse {
|
|
|
48
45
|
name;
|
|
49
46
|
decorator;
|
|
50
47
|
call;
|
|
51
|
-
|
|
48
|
+
imports;
|
|
49
|
+
constructor(name, decorator, call, imports) {
|
|
52
50
|
this.name = name;
|
|
53
51
|
this.decorator = decorator;
|
|
54
52
|
this.call = call;
|
|
53
|
+
this.imports = imports;
|
|
55
54
|
}
|
|
56
55
|
}
|
|
57
56
|
class CanonicalImports {
|
|
@@ -61,6 +60,10 @@ class CanonicalImports {
|
|
|
61
60
|
// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper
|
|
62
61
|
function isCanonicalModule(moduleName) {
|
|
63
62
|
return (moduleName === '@webpieces/core-util' ||
|
|
63
|
+
moduleName === '@webpieces/http-routing' ||
|
|
64
|
+
moduleName === '@webpieces/http-client-browser' ||
|
|
65
|
+
moduleName.endsWith('/core-util/src/http/auth-mode') ||
|
|
66
|
+
moduleName.endsWith('/core-util/src/http/authorization') ||
|
|
64
67
|
moduleName === '@webpieces/core-util/ipc' ||
|
|
65
68
|
moduleName.endsWith('/core-util/src/http/decorators') ||
|
|
66
69
|
moduleName.includes('/core-util/src/ipc/'));
|
|
@@ -94,13 +97,13 @@ function decoratorUse(decorator, imports) {
|
|
|
94
97
|
const callee = call?.expression ?? expr;
|
|
95
98
|
if (ts.isIdentifier(callee)) {
|
|
96
99
|
const canonical = imports.named.get(callee.text);
|
|
97
|
-
return canonical ? new DecoratorUse(canonical, decorator, call) : null;
|
|
100
|
+
return canonical ? new DecoratorUse(canonical, decorator, call, imports) : null;
|
|
98
101
|
}
|
|
99
102
|
if (ts.isPropertyAccessExpression(callee) &&
|
|
100
103
|
ts.isIdentifier(callee.expression) &&
|
|
101
104
|
imports.namespaces.has(callee.expression.text)) {
|
|
102
105
|
return CONTRACT_DECORATORS.has(callee.name.text)
|
|
103
|
-
? new DecoratorUse(callee.name.text, decorator, call)
|
|
106
|
+
? new DecoratorUse(callee.name.text, decorator, call, imports)
|
|
104
107
|
: null;
|
|
105
108
|
}
|
|
106
109
|
return null;
|
|
@@ -149,10 +152,11 @@ function checkHttpMethod(file, source, method, uses, out) {
|
|
|
149
152
|
const auth = uses.filter((use) => HTTP_AUTH.has(use.name));
|
|
150
153
|
const ipc = uses.filter((use) => use.name === 'WpIpcEndpoint');
|
|
151
154
|
const label = methodName(method);
|
|
155
|
+
checkAuthorization(file, source, method, uses, out);
|
|
152
156
|
if (endpoints.length > 1)
|
|
153
157
|
add(out, file, source, method, 'HTTP_MULTIPLE_ENDPOINTS', `${label} has multiple @Endpoint decorators.`);
|
|
154
158
|
if (endpoints.length > 0 && auth.length !== 1) {
|
|
155
|
-
add(out, file, source, method, 'HTTP_AUTH_COUNT', `${label} must have exactly one method-level @WpAuth
|
|
159
|
+
add(out, file, source, method, 'HTTP_AUTH_COUNT', `${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.`);
|
|
156
160
|
}
|
|
157
161
|
if (endpoints.length === 0 && auth.length > 0)
|
|
158
162
|
add(out, file, source, auth[0].decorator, 'HTTP_ORPHAN_AUTH', `${label} has @WpAuth* but no @Endpoint.`);
|
|
@@ -163,11 +167,32 @@ function checkHttpMethod(file, source, method, uses, out) {
|
|
|
163
167
|
if (ipc.length > 0)
|
|
164
168
|
add(out, file, source, ipc[0].decorator, 'HTTP_IPC_MIX', `${label} mixes HTTP and IPC endpoint metadata.`);
|
|
165
169
|
}
|
|
170
|
+
// webpieces-disable no-function-outside-class -- stateless security declaration audit shared by all served endpoints
|
|
171
|
+
function checkAuthorization(file, source, method, uses, out) {
|
|
172
|
+
const endpoint = uses.some((use) => use.name === 'Endpoint');
|
|
173
|
+
const authorization = uses.filter((use) => use.name === 'WpAuthorization');
|
|
174
|
+
if (endpoint && authorization.length !== 1)
|
|
175
|
+
add(out, file, source, method, 'HTTP_AUTHORIZATION_COUNT', `${methodName(method)} requires exactly one method-level @WpAuthorization; found ${authorization.length}.`);
|
|
176
|
+
if (!endpoint && authorization.length)
|
|
177
|
+
add(out, file, source, method, 'HTTP_ORPHAN_AUTHORIZATION', '@WpAuthorization requires an @Endpoint.');
|
|
178
|
+
const isPublic = uses.some((use) => use.name === 'WpAuthPublic');
|
|
179
|
+
for (const use of uses) {
|
|
180
|
+
if (LEGACY_AUTH.has(use.name))
|
|
181
|
+
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.`);
|
|
182
|
+
const problems = use.name === 'WpAuth'
|
|
183
|
+
? security_policy_shapes_1.SecurityPolicyShapes.authentication(use.call, use.imports.named, use.imports.namespaces)
|
|
184
|
+
: use.name === 'WpAuthorization'
|
|
185
|
+
? security_policy_shapes_1.SecurityPolicyShapes.authorization(use.call, isPublic, use.imports.named, use.imports.namespaces)
|
|
186
|
+
: [];
|
|
187
|
+
for (const problem of problems)
|
|
188
|
+
add(out, file, source, use.decorator, problem.code, problem.message);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
166
191
|
// webpieces-disable no-function-outside-class -- stateless TypeScript AST security validator helper
|
|
167
192
|
function checkInternalMethod(file, source, method, uses, out, ids) {
|
|
168
193
|
const ipc = uses.filter((use) => use.name === 'WpIpcEndpoint');
|
|
169
194
|
const endpoint = uses.some((use) => use.name === 'Endpoint');
|
|
170
|
-
const auth = uses.some((use) => HTTP_AUTH.has(use.name));
|
|
195
|
+
const auth = uses.some((use) => (HTTP_AUTH.has(use.name) || LEGACY_AUTH.has(use.name) || use.name === 'WpAuthorization' || use.name === 'WpLocalOnly'));
|
|
171
196
|
const label = methodName(method);
|
|
172
197
|
if (ipc.length !== 1)
|
|
173
198
|
add(out, file, source, method, 'IPC_ENDPOINT_COUNT', `${label} must have exactly one @WpIpcEndpoint('stable-method-id'); found ${ipc.length}.`);
|
|
@@ -217,7 +242,7 @@ class ApiClassAudit {
|
|
|
217
242
|
this.methodUses = this.methods.map((method) => decoratorsOf(method, imports));
|
|
218
243
|
this.apiPaths = this.classUses.filter((use) => use.name === 'ApiPath');
|
|
219
244
|
this.internals = this.classUses.filter((use) => use.name === 'WpInternal');
|
|
220
|
-
this.classAuth = this.classUses.filter((use) => HTTP_AUTH.has(use.name));
|
|
245
|
+
this.classAuth = this.classUses.filter((use) => HTTP_AUTH.has(use.name) || LEGACY_AUTH.has(use.name) || use.name === 'WpAuthorization' || use.name === 'WpLocalOnly');
|
|
221
246
|
this.hasHttpMethod = this.methodUses.some((uses) => uses.some((use) => use.name === 'Endpoint'));
|
|
222
247
|
this.hasIpcMethod = this.methodUses.some((uses) => uses.some((use) => use.name === 'WpIpcEndpoint'));
|
|
223
248
|
this.className = statement.name?.text ?? '<anonymous class>';
|
|
@@ -360,7 +385,7 @@ function securityContractsError(violations) {
|
|
|
360
385
|
const first = violations[0];
|
|
361
386
|
const message = 'API contracts in directly changed projects are not explicit and secure.\n' + details;
|
|
362
387
|
return new rules_config_1.RuleFailError("ensure-we-are-secure", message, first?.line, first === undefined ? undefined : `[${first.code}] ${first.message}`, [
|
|
363
|
-
new rules_config_1.Option("Put exactly one authenticated method-level @WpAuth
|
|
388
|
+
new rules_config_1.Option("Put exactly one authenticated method-level @WpAuth or @WpAuthPublic decorator on every @Endpoint. Use @WpAuthPublic('non-empty reason') only when anonymous access is deliberate.", true),
|
|
364
389
|
new rules_config_1.Option("For IPC-only contracts, replace HTTP metadata with class-level @WpInternal('stable-api-id') and exactly one @WpIpcEndpoint('stable-method-id') per method."),
|
|
365
390
|
]);
|
|
366
391
|
}
|
|
@@ -373,7 +398,7 @@ let EnsureWeAreSecureValidator = class EnsureWeAreSecureValidator extends code_v
|
|
|
373
398
|
super(config, 'ensure-we-are-secure', 'ensure-we-are-secure');
|
|
374
399
|
}
|
|
375
400
|
async run(workspaceRoot) {
|
|
376
|
-
if (
|
|
401
|
+
if (this.config.mode === 'OFF')
|
|
377
402
|
return { success: true };
|
|
378
403
|
const base = process.env['NX_BASE'] ?? (0, rules_config_1.detectBase)(workspaceRoot);
|
|
379
404
|
if (base === null || base === undefined) {
|
|
@@ -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":";;;AA2dA,0EAUC;AA+BD,wDA8BC;AAGD,wDA2BC;AAGD,4DAIC;;AAvkBD,+FAA+F;AAC/F,+CAAyB;AACzB,mDAA6B;AAC7B,uDAAiC;AACjC,0DAA6F;AAC7F,yDAAiE;AACjE,8DAA0D;AAC1D,yCAA2D;AAC3D,qDAAiE;AAEjE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC;IACtB,WAAW;IACX,YAAY;IACZ,eAAe;IACf,oBAAoB;IACpB,cAAc;IACd,iBAAiB;IACjB,cAAc;CACjB,CAAC,CAAC;AACH,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAChC,GAAG,SAAS;IACZ,SAAS;IACT,UAAU;IACV,YAAY;IACZ,eAAe;CAClB,CAAC,CAAC;AAEH,MAAa,yBAAyB;IAErB;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,OAAe;QAHf,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,SAAI,GAAJ,IAAI,CAAQ;QACZ,YAAO,GAAP,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OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACpE,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,IAAI,IAAA,yBAAU,EAAC,aAAa,CAAC,CAAC;QACjE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,wBAAwB,EAAE,CAAC;QACrC,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,8BAAe,EAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YACzE,MAAM,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,+BAA+B,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACtE,MAAM,UAAU,GAAG,sBAAsB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAChE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACtD,MAAM,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;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 { 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([\n 'WpAuthJwt',\n 'WpAuthOidc',\n 'WpAuthWebhook',\n 'WpAuthSharedSecret',\n 'WpAuthApiKey',\n 'WpAuthLocalOnly',\n 'WpAuthPublic',\n]);\nconst CONTRACT_DECORATORS = new Set([\n ...HTTP_AUTH,\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 ) {}\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/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) : 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)\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 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* 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 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));\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));\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* 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') === '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;AAEjE,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC,CAAC;AACtD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,YAAY,EAAE,eAAe,EAAE,oBAAoB,EAAE,cAAc,EAAE,iBAAiB,EAAE,cAAc,CAAC,CAAC,CAAC;AACnJ,MAAM,mBAAmB,GAAG,IAAI,GAAG,CAAC;IAChC,GAAG,SAAS;IACZ,GAAG,WAAW;IACd,iBAAiB,EAAE,aAAa,EAAE,mBAAmB;IACrD,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,SAAS,EAAE,QAAQ;IAClD,SAAS;IACT,UAAU;IACV,YAAY;IACZ,eAAe;CAClB,CAAC,CAAC;AAEH,MAAa,yBAAyB;IAErB;IACA;IACA;IACA;IAJb,YACa,IAAY,EACZ,IAAY,EACZ,IAAY,EACZ,OAAe;QAHf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AS,CAAC,IAAI,IAAA,yBAAU,EAAC,aAAa,CAAC,CAAC;QACjE,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACtC,MAAM,wBAAwB,EAAE,CAAC;QACrC,CAAC;QACD,MAAM,OAAO,GAAG,IAAA,8BAAe,EAAC,aAAa,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;YACzE,MAAM,EAAE,KAAK;SAChB,CAAC,CAAC;QACH,MAAM,KAAK,GAAG,+BAA+B,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;QACtE,MAAM,UAAU,GAAG,sBAAsB,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;QAChE,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;QACtD,MAAM,sBAAsB,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;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"]}
|