@code-sentinel-cli/code-sentinel-cli 4.0.13-avtest.0 → 4.0.13
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/dist/bin.js +675 -99
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +21 -0
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +3 -2
- package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +6 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +1 -1
- package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +6 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +1 -1
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +17 -4
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +3 -2
- package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +7 -1
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +1 -1
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +4 -0
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +1 -1
- package/dist/builtin-rules/static/angular/button-accessible-name.rule.js +261 -5
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +141 -30
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +7 -7
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +41 -38
- package/dist/builtin-rules/static/general/no-circular-import.rule.js +1 -1
- package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +1 -1
- package/dist/index.d.ts +9 -3
- package/dist/index.js +676 -100
- package/package.json +2 -2
|
@@ -2,16 +2,49 @@ import { asTsMorphSourceFile } from '@code-sentinel/parsers';
|
|
|
2
2
|
import { Node } from 'ts-morph';
|
|
3
3
|
|
|
4
4
|
// builtin-rules/static/angular/no-leaky-subscription.rule.ts
|
|
5
|
-
var TERMINATING_OPERATORS = /* @__PURE__ */ new Set([
|
|
6
|
-
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
5
|
+
var TERMINATING_OPERATORS = /* @__PURE__ */ new Set(["takeUntil", "takeUntilDestroyed", "take", "first"]);
|
|
6
|
+
var LIFETIME_EXTENDING_OPERATORS = /* @__PURE__ */ new Set([
|
|
7
|
+
"switchMap",
|
|
8
|
+
"mergeMap",
|
|
9
|
+
"concatMap",
|
|
10
|
+
"exhaustMap",
|
|
11
|
+
"switchAll",
|
|
12
|
+
"mergeAll",
|
|
13
|
+
"concatAll",
|
|
14
|
+
"exhaustAll",
|
|
15
|
+
"expand",
|
|
16
|
+
"repeat",
|
|
17
|
+
"repeatWhen",
|
|
18
|
+
"retry",
|
|
19
|
+
"retryWhen",
|
|
20
|
+
"concatWith",
|
|
21
|
+
"mergeWith",
|
|
22
|
+
"catchError",
|
|
23
|
+
"debounceTime",
|
|
24
|
+
"debounce",
|
|
25
|
+
"delay",
|
|
26
|
+
"delayWhen",
|
|
27
|
+
"auditTime",
|
|
28
|
+
"throttleTime",
|
|
11
29
|
"last",
|
|
12
30
|
"single",
|
|
13
31
|
"toArray"
|
|
14
32
|
]);
|
|
33
|
+
var LIFETIME_PRESERVING_OPERATORS = /* @__PURE__ */ new Set([
|
|
34
|
+
"map",
|
|
35
|
+
"filter",
|
|
36
|
+
"tap",
|
|
37
|
+
"finalize",
|
|
38
|
+
"scan",
|
|
39
|
+
"distinct",
|
|
40
|
+
"distinctUntilChanged",
|
|
41
|
+
"startWith",
|
|
42
|
+
"skip",
|
|
43
|
+
"skipWhile",
|
|
44
|
+
"skipUntil",
|
|
45
|
+
"pairwise",
|
|
46
|
+
"takeWhile"
|
|
47
|
+
]);
|
|
15
48
|
var LONG_LIVED_MEMBERS = /* @__PURE__ */ new Set([
|
|
16
49
|
"valueChanges",
|
|
17
50
|
"statusChanges",
|
|
@@ -23,7 +56,7 @@ var LONG_LIVED_MEMBERS = /* @__PURE__ */ new Set([
|
|
|
23
56
|
"events"
|
|
24
57
|
// Router.events
|
|
25
58
|
]);
|
|
26
|
-
var LONG_LIVED_FACTORIES = /* @__PURE__ */ new Set(["fromEvent", "interval"
|
|
59
|
+
var LONG_LIVED_FACTORIES = /* @__PURE__ */ new Set(["fromEvent", "interval"]);
|
|
27
60
|
var ONE_SHOT_MEMBERS = /* @__PURE__ */ new Set([
|
|
28
61
|
"afterClose",
|
|
29
62
|
"afterClosed",
|
|
@@ -32,22 +65,36 @@ var ONE_SHOT_MEMBERS = /* @__PURE__ */ new Set([
|
|
|
32
65
|
"beforeClose",
|
|
33
66
|
"onClose"
|
|
34
67
|
]);
|
|
35
|
-
var
|
|
36
|
-
var HTTP_RECEIVER_RE = /(service|http|api|client)$/i;
|
|
68
|
+
var HTTP_METHODS = /* @__PURE__ */ new Set(["get", "post", "put", "patch", "delete", "head", "options"]);
|
|
37
69
|
var MANAGED_COLLECTOR_METHODS = /* @__PURE__ */ new Set(["add"]);
|
|
38
70
|
var isTerminatingPipe = (expression) => {
|
|
39
71
|
if (!Node.isCallExpression(expression)) return false;
|
|
40
72
|
const inner = expression.getExpression();
|
|
41
73
|
if (!Node.isPropertyAccessExpression(inner)) return false;
|
|
42
74
|
if (inner.getName() !== "pipe") return false;
|
|
75
|
+
let bounded = isTerminatingPipe(inner.getExpression());
|
|
43
76
|
for (const arg of expression.getArguments()) {
|
|
44
|
-
if (!Node.isCallExpression(arg))
|
|
77
|
+
if (!Node.isCallExpression(arg)) {
|
|
78
|
+
bounded = false;
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
45
81
|
const argExpr = arg.getExpression();
|
|
46
|
-
if (Node.isIdentifier(argExpr)
|
|
47
|
-
|
|
82
|
+
if (!Node.isIdentifier(argExpr)) {
|
|
83
|
+
bounded = false;
|
|
84
|
+
continue;
|
|
48
85
|
}
|
|
86
|
+
const imported = argExpr.getSourceFile().getImportDeclarations().filter(
|
|
87
|
+
(d) => ["rxjs", "rxjs/operators", "@angular/core/rxjs-interop"].includes(
|
|
88
|
+
d.getModuleSpecifierValue()
|
|
89
|
+
)
|
|
90
|
+
).flatMap((d) => d.getNamedImports()).find((i) => (i.getAliasNode()?.getText() ?? i.getName()) === argExpr.getText());
|
|
91
|
+
const name = imported?.getName() ?? argExpr.getText();
|
|
92
|
+
if (!TERMINATING_OPERATORS.has(name) && !LIFETIME_PRESERVING_OPERATORS.has(name))
|
|
93
|
+
bounded = false;
|
|
94
|
+
if (LIFETIME_EXTENDING_OPERATORS.has(name)) bounded = false;
|
|
95
|
+
if (TERMINATING_OPERATORS.has(name)) bounded = true;
|
|
49
96
|
}
|
|
50
|
-
return
|
|
97
|
+
return bounded;
|
|
51
98
|
};
|
|
52
99
|
var unwrapPipe = (node) => {
|
|
53
100
|
let cur = node;
|
|
@@ -61,10 +108,28 @@ var unwrapPipe = (node) => {
|
|
|
61
108
|
}
|
|
62
109
|
return cur;
|
|
63
110
|
};
|
|
64
|
-
var
|
|
65
|
-
if (Node.isPropertyAccessExpression(
|
|
66
|
-
|
|
67
|
-
|
|
111
|
+
var isInjectedReceiver = (receiver, moduleName, exportedName) => {
|
|
112
|
+
if (!Node.isPropertyAccessExpression(receiver) || receiver.getExpression().getText() !== "this")
|
|
113
|
+
return false;
|
|
114
|
+
const sf = receiver.getSourceFile();
|
|
115
|
+
const imports = sf.getImportDeclarations();
|
|
116
|
+
const httpNames = imports.filter((d) => d.getModuleSpecifierValue() === moduleName).flatMap(
|
|
117
|
+
(d) => d.getNamedImports().filter((i) => i.getName() === exportedName).map((i) => i.getAliasNode()?.getText() ?? i.getName())
|
|
118
|
+
);
|
|
119
|
+
const injectNames = imports.filter((d) => d.getModuleSpecifierValue() === "@angular/core").flatMap(
|
|
120
|
+
(d) => d.getNamedImports().filter((i) => i.getName() === "inject").map((i) => i.getAliasNode()?.getText() ?? i.getName())
|
|
121
|
+
);
|
|
122
|
+
const cls = receiver.getFirstAncestor(Node.isClassDeclaration);
|
|
123
|
+
if (!cls) return false;
|
|
124
|
+
const field = cls.getProperty(receiver.getName());
|
|
125
|
+
const initializer = field?.getInitializer();
|
|
126
|
+
if (initializer && Node.isCallExpression(initializer) && injectNames.includes(initializer.getExpression().getText()) && httpNames.includes(initializer.getArguments()[0]?.getText() ?? ""))
|
|
127
|
+
return true;
|
|
128
|
+
return cls.getConstructors().some(
|
|
129
|
+
(ctor) => ctor.getParameters().some(
|
|
130
|
+
(param) => param.isParameterProperty() && param.getName() === receiver.getName() && httpNames.includes(param.getTypeNode()?.getText() ?? "")
|
|
131
|
+
)
|
|
132
|
+
);
|
|
68
133
|
};
|
|
69
134
|
var trailingName = (node) => {
|
|
70
135
|
if (Node.isPropertyAccessExpression(node)) return node.getName();
|
|
@@ -72,21 +137,41 @@ var trailingName = (node) => {
|
|
|
72
137
|
return void 0;
|
|
73
138
|
};
|
|
74
139
|
var classifySource = (receiver) => {
|
|
140
|
+
if (Node.isCallExpression(receiver)) {
|
|
141
|
+
const expression = receiver.getExpression();
|
|
142
|
+
if (Node.isPropertyAccessExpression(expression) && expression.getName() === "pipe") {
|
|
143
|
+
const sourceKind = classifySource(expression.getExpression());
|
|
144
|
+
if (sourceKind !== "one-shot") return sourceKind;
|
|
145
|
+
const transparent = receiver.getArguments().every((arg) => {
|
|
146
|
+
if (!Node.isCallExpression(arg)) return false;
|
|
147
|
+
const operator = arg.getExpression();
|
|
148
|
+
return Node.isIdentifier(operator) && LIFETIME_PRESERVING_OPERATORS.has(operator.getText());
|
|
149
|
+
});
|
|
150
|
+
return transparent ? "one-shot" : "unclassified";
|
|
151
|
+
}
|
|
152
|
+
}
|
|
75
153
|
const src = unwrapPipe(receiver);
|
|
76
154
|
if (Node.isPropertyAccessExpression(src) && LONG_LIVED_MEMBERS.has(src.getName())) {
|
|
77
|
-
|
|
155
|
+
if (src.getName() === "events" && isInjectedReceiver(src.getExpression(), "@angular/router", "Router")) {
|
|
156
|
+
return "long-lived";
|
|
157
|
+
}
|
|
158
|
+
return "member-risk";
|
|
78
159
|
}
|
|
79
160
|
if (Node.isCallExpression(src)) {
|
|
80
161
|
const callee = src.getExpression();
|
|
81
162
|
if (Node.isIdentifier(callee) && LONG_LIVED_FACTORIES.has(callee.getText())) {
|
|
82
163
|
return "long-lived";
|
|
83
164
|
}
|
|
84
|
-
if (Node.isIdentifier(callee) &&
|
|
85
|
-
|
|
165
|
+
if (Node.isIdentifier(callee) && callee.getText() === "timer") {
|
|
166
|
+
const period = src.getArguments()[1];
|
|
167
|
+
if (period === void 0) return "one-shot";
|
|
168
|
+
if (Node.isNumericLiteral(period)) return "long-lived";
|
|
169
|
+
return "unclassified";
|
|
86
170
|
}
|
|
87
171
|
if (Node.isPropertyAccessExpression(callee)) {
|
|
88
172
|
if (ONE_SHOT_MEMBERS.has(callee.getName())) return "one-shot";
|
|
89
|
-
if (
|
|
173
|
+
if (HTTP_METHODS.has(callee.getName()) && isInjectedReceiver(callee.getExpression(), "@angular/common/http", "HttpClient"))
|
|
174
|
+
return "one-shot";
|
|
90
175
|
}
|
|
91
176
|
}
|
|
92
177
|
if (Node.isPropertyAccessExpression(src) && ONE_SHOT_MEMBERS.has(src.getName())) {
|
|
@@ -118,7 +203,24 @@ var assignmentTargetName = (subscribeCall) => {
|
|
|
118
203
|
}
|
|
119
204
|
return void 0;
|
|
120
205
|
};
|
|
206
|
+
var isReturnedObservableTeardown = (subscribeCall) => {
|
|
207
|
+
const returned = subscribeCall.getParent();
|
|
208
|
+
if (!returned || !Node.isReturnStatement(returned)) return false;
|
|
209
|
+
const creator = subscribeCall.getFirstAncestor(
|
|
210
|
+
(node) => Node.isArrowFunction(node) || Node.isFunctionExpression(node)
|
|
211
|
+
);
|
|
212
|
+
const observable = creator?.getParent();
|
|
213
|
+
if (!observable || !Node.isNewExpression(observable)) return false;
|
|
214
|
+
const observableConstructor = observable.getExpression();
|
|
215
|
+
if (!Node.isIdentifier(observableConstructor)) return false;
|
|
216
|
+
return observableConstructor.getSymbol()?.getDeclarations().some((declaration) => {
|
|
217
|
+
if (!Node.isImportSpecifier(declaration) || declaration.getName() !== "Observable")
|
|
218
|
+
return false;
|
|
219
|
+
return declaration.getFirstAncestor(Node.isImportDeclaration)?.getModuleSpecifierValue() === "rxjs";
|
|
220
|
+
}) ?? false;
|
|
221
|
+
};
|
|
121
222
|
var isManagedSubscription = (subscribeCall, unsubscribedNames) => {
|
|
223
|
+
if (isReturnedObservableTeardown(subscribeCall)) return true;
|
|
122
224
|
const parent = subscribeCall.getParent();
|
|
123
225
|
if (parent !== void 0 && Node.isCallExpression(parent)) {
|
|
124
226
|
const callee = parent.getExpression();
|
|
@@ -138,7 +240,7 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
138
240
|
message: "subscribe() v\xE0o stream long-lived (valueChanges/params/fromEvent/interval\u2026) kh\xF4ng h\u1EE7y \u2014 memory leak khi component hu\u1EF7.",
|
|
139
241
|
file,
|
|
140
242
|
range,
|
|
141
|
-
suggestion: "
|
|
243
|
+
suggestion: "\u0110\u1EB7t takeUntilDestroyed(this.destroyRef) sau switchMap/mergeMap \u0111\u1EC3 h\u1EE7y c\u1EA3 inner stream; inject DestroyRef khi g\u1ECDi trong ngOnInit/event handler. Ho\u1EB7c d\xF9ng async pipe / teardown r\xF5 r\xE0ng.",
|
|
142
244
|
// v5 (ADR-0065): 80→95. Đo trên hai module Angular sản xuất: 96 finding
|
|
143
245
|
// band `long-lived`, 0 bị bác. `baseConfidence` của rule này là metadata
|
|
144
246
|
// CHẾT — mọi finding đều mang confidence riêng — nên hiệu chỉnh phải sửa
|
|
@@ -147,22 +249,32 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
147
249
|
severity: "error"
|
|
148
250
|
};
|
|
149
251
|
}
|
|
252
|
+
if (kind === "member-risk") {
|
|
253
|
+
return {
|
|
254
|
+
message: "Subscription v\xE0o member stream thi\u1EBFu teardown; ch\u01B0a x\xE1c minh owner/retention n\xEAn ch\u01B0a k\u1EBFt lu\u1EADn memory leak. Ki\u1EC3m tra v\xF2ng \u0111\u1EDDi ngu\u1ED3n v\xE0 callback sau destroy.",
|
|
255
|
+
file,
|
|
256
|
+
range,
|
|
257
|
+
severity: "warning",
|
|
258
|
+
confidence: 75,
|
|
259
|
+
suggestion: "N\u1EBFu callback thu\u1ED9c component, d\xF9ng takeUntilDestroyed(this.destroyRef) sau flattening operators. FormControl/ActivatedRoute c\u1EE5c b\u1ED9 c\u1EA7n x\xE9t ownership tr\u01B0\u1EDBc khi kh\u1EB3ng \u0111\u1ECBnh leak."
|
|
260
|
+
};
|
|
261
|
+
}
|
|
150
262
|
if (kind === "one-shot") {
|
|
151
263
|
return {
|
|
152
|
-
message: "
|
|
264
|
+
message: "Subscription v\xE0o ngu\u1ED3n h\u1EEFu h\u1EA1n thi\u1EBFu teardown; c\u1EA7n x\xE1c \u0111\u1ECBnh callback thu\u1ED9c component hay t\xE1c v\u1EE5 c\u1EA7n ho\xE0n t\u1EA5t sau chuy\u1EC3n trang (kh\xF4ng kh\u1EB3ng \u0111\u1ECBnh memory leak).",
|
|
153
265
|
file,
|
|
154
266
|
range,
|
|
155
|
-
suggestion: "
|
|
267
|
+
suggestion: "Callback UI: d\xF9ng takeUntilDestroyed(this.destroyRef) sau flattening operators. T\xE1c v\u1EE5 server/theme c\u1EA7n s\u1ED1ng qua navigation: chuy\u1EC3n ownership v\u1EC1 service \u1EE9ng d\u1EE5ng v\xE0 x\xE1c minh ngu\u1ED3n h\u1EEFu h\u1EA1n; kh\xF4ng t\u1EF1 h\u1EE7y theo component. firstValueFrom kh\xF4ng t\u1EF1 h\u1EE7y khi component destroy.",
|
|
156
268
|
// v5 (ADR-0065): 70→90. Đo 430 finding band `one-shot`, 0 bị bác.
|
|
157
269
|
confidence: 90,
|
|
158
270
|
severity: "warning"
|
|
159
271
|
};
|
|
160
272
|
}
|
|
161
273
|
return {
|
|
162
|
-
message: "
|
|
274
|
+
message: "Subscription ch\u01B0a th\u1EA5y teardown v\xE0 ch\u01B0a x\xE1c minh lifetime ngu\u1ED3n; t\xEAn Service/API kh\xF4ng ch\u1EE9ng minh one-shot. Ki\u1EC3m tra ngu\u1ED3n, ownership v\xE0 callback sau destroy.",
|
|
163
275
|
file,
|
|
164
276
|
range,
|
|
165
|
-
suggestion: "
|
|
277
|
+
suggestion: "Callback thu\u1ED9c component: d\xF9ng takeUntilDestroyed(this.destroyRef) sau switchMap/mergeMap ho\u1EB7c teardown r\xF5 r\xE0ng. Command server/theme c\u1EA7n ho\xE0n t\u1EA5t qua navigation: x\xE1c minh ngu\u1ED3n h\u1EEFu h\u1EA1n v\xE0 owner \u1EE9ng d\u1EE5ng tr\u01B0\u1EDBc khi h\u1EE7y. firstValueFrom kh\xF4ng thay th\u1EBF lifecycle teardown.",
|
|
166
278
|
// v5 (ADR-0065): 60→85. Band yếu nhất (không nhận diện được nguồn), nên
|
|
167
279
|
// vẫn giữ thấp hơn hai band trên một bậc.
|
|
168
280
|
confidence: 85,
|
|
@@ -171,17 +283,16 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
171
283
|
};
|
|
172
284
|
var rule = {
|
|
173
285
|
id: "angular/no-leaky-subscription",
|
|
174
|
-
|
|
175
|
-
version: 5,
|
|
286
|
+
version: 7,
|
|
176
287
|
kind: "static-ts",
|
|
177
288
|
title: "Subscription ph\u1EA3i \u0111\u01B0\u1EE3c h\u1EE7y (takeUntil / unsubscribe / Subscription.add / async pipe)",
|
|
178
|
-
description: "
|
|
289
|
+
description: "v6: ownership-aware advice; member streams have advisory severity until retention is established. Service names and forkJoin do not prove finite lifetime. Teardown before a flattening/resubscription operator does not cover the resulting stream. Application commands are not auto-suppressed.",
|
|
179
290
|
severity: "error",
|
|
180
291
|
category: "memory-safety",
|
|
181
292
|
languages: ["typescript"],
|
|
182
293
|
scope: "angular",
|
|
183
294
|
requires: "semantic-ts",
|
|
184
|
-
//
|
|
295
|
+
// Per-finding confidence: confirmed factories 95, finite contracts 90, unknown 85, members 75.
|
|
185
296
|
baseConfidence: 85,
|
|
186
297
|
check(ctx) {
|
|
187
298
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
@@ -30,18 +30,18 @@ var hasSpread = (obj) => obj.getProperties().some((prop) => Node.isSpreadAssignm
|
|
|
30
30
|
var rule = {
|
|
31
31
|
id: "angular/onpush-required",
|
|
32
32
|
// v3 (ADR-0065 calibration): conf 70→95 (đo 122/122 TP)
|
|
33
|
-
version:
|
|
33
|
+
version: 4,
|
|
34
34
|
kind: "static-ts",
|
|
35
35
|
title: "@Component n\xEAn d\xF9ng ChangeDetectionStrategy.OnPush",
|
|
36
|
-
description: "OnPush gi\u1EA3m s\u1ED1 l\u1EA7n change detection ch\u1EA1y, perf-critical cho app l\u1EDBn. Khuy\u1EBFn ngh\u1ECB \xE1p d\u1EE5ng cho h\u1EA7u h\u1EBFt Component; m\u1ED9t s\u1ED1 Component v\u1EABn h\u1EE3p l\u1EC7 khi d\xF9ng Default \u2192 \u0111\xE2y l\xE0 khuy\u1EBFn ngh\u1ECB perf (warning
|
|
36
|
+
description: "OnPush gi\u1EA3m s\u1ED1 l\u1EA7n change detection ch\u1EA1y, perf-critical cho app l\u1EDBn. Khuy\u1EBFn ngh\u1ECB \xE1p d\u1EE5ng cho h\u1EA7u h\u1EBFt Component; m\u1ED9t s\u1ED1 Component v\u1EABn h\u1EE3p l\u1EC7 khi d\xF9ng Default \u2192 \u0111\xE2y l\xE0 khuy\u1EBFn ngh\u1ECB perf (warning; confidence 95 ch\u1EC9 x\xE1c nh\u1EADn thi\u1EBFu strategy), kh\xF4ng ph\u1EA3i bug ch\u1EAFc ch\u1EAFn. B\u1ECF qua Component c\xF3 config spread (kh\xF4ng ch\u1EE9ng minh \u0111\u01B0\u1EE3c).",
|
|
37
37
|
severity: "warning",
|
|
38
38
|
category: "performance",
|
|
39
39
|
languages: ["typescript"],
|
|
40
40
|
scope: "angular",
|
|
41
41
|
requires: "semantic-ts",
|
|
42
|
-
//
|
|
43
|
-
//
|
|
44
|
-
//
|
|
42
|
+
// Confidence 95 describes deterministic missing-strategy detection.
|
|
43
|
+
// Whether OnPush is safe or improves performance remains a separate judgment;
|
|
44
|
+
// some Default components are valid and need their render triggers reviewed.
|
|
45
45
|
baseConfidence: 95,
|
|
46
46
|
check(ctx) {
|
|
47
47
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
@@ -56,10 +56,10 @@ var rule = {
|
|
|
56
56
|
const className = cls.getName() ?? "<anonymous>";
|
|
57
57
|
const { line, column } = sf.getLineAndColumnAtPos(decorator.getStart());
|
|
58
58
|
findings.push({
|
|
59
|
-
message: `Component "${className}" ch\u01B0a khai b\xE1o \`changeDetection: ChangeDetectionStrategy.OnPush
|
|
59
|
+
message: `Component "${className}" ch\u01B0a khai b\xE1o \`changeDetection: ChangeDetectionStrategy.OnPush\`; \u0111\xE2y l\xE0 khuy\u1EBFn ngh\u1ECB convention/performance, kh\xF4ng ch\u1EE9ng minh l\u1ED7i ch\u1EE9c n\u0103ng. Ki\u1EC3m ch\u1EE9ng trigger c\u1EADp nh\u1EADt view tr\u01B0\u1EDBc khi \u0111\u1ED5i strategy.`,
|
|
60
60
|
file: ctx.file.path,
|
|
61
61
|
range: { line, column },
|
|
62
|
-
suggestion: "
|
|
62
|
+
suggestion: "Ki\u1EC3m ch\u1EE9ng input/reference, signal/async pipe, form v\xE0 callback b\u1EA5t \u0111\u1ED3ng b\u1ED9; ch\u1EC9 th\xEAm OnPush khi view c\xF3 trigger c\u1EADp nh\u1EADt \u0111\xFAng (markForCheck khi c\u1EA7n). Default c\xF3 th\u1EC3 l\xE0 l\u1EF1a ch\u1ECDn h\u1EE3p l\u1EC7."
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
65
|
return findings;
|
|
@@ -4,10 +4,9 @@ import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
|
4
4
|
var HTML_SINK_PROPS = /* @__PURE__ */ new Set(["innerhtml", "outerhtml"]);
|
|
5
5
|
var URL_SINK_TAGS = {
|
|
6
6
|
src: /* @__PURE__ */ new Set(["iframe", "script", "embed"]),
|
|
7
|
-
srcdoc: /* @__PURE__ */ new Set(["iframe"]),
|
|
8
7
|
data: /* @__PURE__ */ new Set(["object"])
|
|
9
8
|
};
|
|
10
|
-
var
|
|
9
|
+
var HAS_PIPE = /(^|[^|])\|([^|]|$)/;
|
|
11
10
|
var PURE_STRING_LITERAL = /^\s*'[^']*'\s*$|^\s*"[^"]*"\s*$/;
|
|
12
11
|
function* walk(node, type) {
|
|
13
12
|
const stack = [node];
|
|
@@ -52,14 +51,36 @@ function rootIdentifier(expr) {
|
|
|
52
51
|
const m = /[A-Za-z_$][\w$]*/.exec(expr);
|
|
53
52
|
return m ? m[0] : null;
|
|
54
53
|
}
|
|
54
|
+
function completeMethodCall(expr) {
|
|
55
|
+
const value = expr.trim();
|
|
56
|
+
const match = /^([A-Za-z_$][\w$]*)\s*\(/.exec(value);
|
|
57
|
+
if (!match?.[1]) return null;
|
|
58
|
+
let depth = 1;
|
|
59
|
+
let quote = "";
|
|
60
|
+
for (let i = match[0].length; i < value.length; i++) {
|
|
61
|
+
const c = value[i];
|
|
62
|
+
if (quote) {
|
|
63
|
+
if (c === "\\") {
|
|
64
|
+
i++;
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
if (c === quote) quote = "";
|
|
68
|
+
} else if (c === "'" || c === '"') quote = c;
|
|
69
|
+
else if (c === "`") return null;
|
|
70
|
+
else if (c === "(") depth++;
|
|
71
|
+
else if (c === ")" && --depth === 0) return i === value.length - 1 ? match[1] : null;
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
55
75
|
var rule = {
|
|
56
76
|
id: "angular/template-dom-xss",
|
|
57
|
-
//
|
|
58
|
-
version:
|
|
77
|
+
// v5 corrects native Angular HTML sanitizer semantics; old calibration is not reused as proof.
|
|
78
|
+
version: 7,
|
|
59
79
|
kind: "static-ts",
|
|
60
80
|
usesTemplateComponent: true,
|
|
81
|
+
usesProjectContext: true,
|
|
61
82
|
title: "Binding nguy hi\u1EC3m trong template Angular (DOM XSS)",
|
|
62
|
-
description: "
|
|
83
|
+
description: "Ki\u1EC3m tra bypass sanitizer v\xE0 k\u1EBFt qu\u1EA3 pipe/call ch\u01B0a x\xE1c minh trong binding HTML. Angular t\u1EF1 sanitize chu\u1ED7i \u1EDF binding HTML native; d\u1EEF li\u1EC7u route/API \u0111\u01A1n thu\u1EA7n kh\xF4ng ch\u1EE9ng minh XSS. Resource URL v\xE0 bypass t\u1EEB b\xEAn ngo\xE0i c\u1EA7n ki\u1EC3m tra ngu\u1ED3n/allowlist; kh\xF4ng tin pipe ch\u1EC9 theo t\xEAn.",
|
|
63
84
|
severity: "warning",
|
|
64
85
|
category: "security",
|
|
65
86
|
checklistIds: ["58", "98", "99"],
|
|
@@ -76,30 +97,29 @@ var rule = {
|
|
|
76
97
|
if (!nameNode) continue;
|
|
77
98
|
const { prop, isBinding } = normalizeBinding(nameNode.text);
|
|
78
99
|
if (!isBinding) continue;
|
|
79
|
-
const
|
|
80
|
-
const
|
|
100
|
+
const tag = enclosingTag(attr);
|
|
101
|
+
const isHtmlSink = HTML_SINK_PROPS.has(prop) || prop === "srcdoc" && tag === "iframe";
|
|
81
102
|
const isUrlSink = !isHtmlSink && tag !== null && (URL_SINK_TAGS[prop]?.has(tag) ?? false);
|
|
82
103
|
if (!isHtmlSink && !isUrlSink) continue;
|
|
83
104
|
const value = attributeValue(attr);
|
|
84
|
-
if (PURE_STRING_LITERAL.test(value)) continue;
|
|
85
|
-
|
|
105
|
+
if (isHtmlSink && PURE_STRING_LITERAL.test(value)) continue;
|
|
106
|
+
const hasPipe = HAS_PIPE.test(value);
|
|
107
|
+
const hasCall = /[\w$)]\s*\(/.test(value);
|
|
108
|
+
const pipeApplication = /^\s*[\w$.]+\s*\|\s*([\w$]+)(?:\s*:\s*[\w$.]+)*\s*$/.exec(value);
|
|
109
|
+
if (isHtmlSink && pipeApplication?.[1] && link?.primitiveStringPipes?.has(pipeApplication[1]))
|
|
110
|
+
continue;
|
|
86
111
|
let origin = "unknown";
|
|
87
112
|
if (link) {
|
|
88
113
|
const root = rootIdentifier(value);
|
|
89
114
|
if (root) origin = link.memberOrigins.get(root) ?? "unknown";
|
|
90
115
|
}
|
|
91
|
-
if (origin === "sanitizer-trusted") continue;
|
|
92
|
-
const confirmed = origin === "tainted-source";
|
|
93
116
|
const externalBypass = origin === "external-bypass";
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
} else {
|
|
101
|
-
message = `\u26A0 C\xF3 th\u1EC3 XSS qua template: ${where} (bi\u1EC3u th\u1EE9c \`${value}\`) \u2014 h\xE3y ch\u1EAFc ch\u1EAFn gi\xE1 tr\u1ECB \u0111\xE3 \u0111\u01B0\u1EE3c sanitize.`;
|
|
102
|
-
}
|
|
117
|
+
if (origin === "sanitizer-trusted" && !hasPipe && !hasCall) continue;
|
|
118
|
+
if (isHtmlSink && link?.sanitizedHtmlMethods?.has(completeMethodCall(value) ?? "") && !hasPipe)
|
|
119
|
+
continue;
|
|
120
|
+
if (isHtmlSink && !externalBypass && !hasPipe && !hasCall) continue;
|
|
121
|
+
const where = `\`${nameNode.text}\` (${value})`;
|
|
122
|
+
const message = externalBypass ? `\u26A0 Bypass sanitizer tr\xEAn d\u1EEF li\u1EC7u T\u1EEA B\xCAN NGO\xC0I component: ${where} trong \`${link?.componentPath}\`. Ki\u1EC3m tra ngu\u1ED3n d\u1EEF li\u1EC7u v\xE0 validation tr\u01B0\u1EDBc bypass; ch\u01B0a ch\u1EE9ng minh attacker control.` : isHtmlSink ? `\u26A0 Binding HTML d\xF9ng pipe/call ch\u01B0a x\xE1c minh: ${where}. Pipe ho\u1EB7c method c\xF3 th\u1EC3 tr\u1EA3 SafeHtml v\xE0 t\u1EAFt sanitizer; t\xEAn safe/sanitize kh\xF4ng ch\u1EE9ng minh an to\xE0n.` : `\u26A0 Binding resource URL c\u1EA7n ki\u1EC3m tra: ${where} tr\xEAn <${tag}>. Angular t\u1EEB ch\u1ED1i chu\u1ED7i kh\xF4ng trusted trong context n\xE0y; kh\xF4ng coi binding \u0111\u01A1n thu\u1EA7n l\xE0 XSS \u0111\xE3 x\xE1c nh\u1EADn.`;
|
|
103
123
|
findings.push({
|
|
104
124
|
message,
|
|
105
125
|
file: ctx.file.path,
|
|
@@ -107,25 +127,8 @@ var rule = {
|
|
|
107
127
|
line: attr.startPosition.row + 1,
|
|
108
128
|
column: attr.startPosition.column + 1
|
|
109
129
|
},
|
|
110
|
-
// Promote a CONFIRMED source→sink flow to `error`/85 (consistent with
|
|
111
|
-
// how `angular/no-dom-xss` reports confirmed flows on the `.ts` side);
|
|
112
|
-
// unresolved/unknown stays the structural `warning` @ baseConfidence 70.
|
|
113
|
-
...confirmed ? { severity: "error", confidence: 85 } : {},
|
|
114
|
-
// An external-bypass keeps the rule's `warning` severity and only lifts
|
|
115
|
-
// confidence to 80 — ADVISORY, not blocking, per [ADR-0031]'s principle
|
|
116
|
-
// that an UNCONFIRMED band inside a deterministic rule must not gate a
|
|
117
|
-
// merge ([ADR-0028]: a deterministic `error` ALWAYS gates, whatever its
|
|
118
|
-
// confidence). What is proven here is "the sanitizer was disabled on a
|
|
119
|
-
// value that crossed the component boundary" — NOT that the value is
|
|
120
|
-
// attacker-controlled, which is what `tainted-source` proves and what
|
|
121
|
-
// earns `error`. And the gate has a KNOWN unrecognised control class:
|
|
122
|
-
// a project-defined validator (`isTrustedResourceUrl(path)`, measured in
|
|
123
|
-
// [ADR-0060] §"A.3 probed") is a real defence this rule cannot yet see,
|
|
124
|
-
// so a CI-blocking verdict here would repeat the `spring/jdbc-template`
|
|
125
|
-
// mistake — an `error` that fails a build on a control the tool missed.
|
|
126
|
-
// Revisit `error` once validation-guard recognition lands.
|
|
127
130
|
...externalBypass ? { confidence: 80 } : {},
|
|
128
|
-
suggestion:
|
|
131
|
+
suggestion: isHtmlSink ? "Gi\u1EEF sanitizer m\u1EB7c \u0111\u1ECBnh cho chu\u1ED7i HTML. Ki\u1EC3m tra implementation pipe/method v\xE0 bypassSecurityTrustHtml; kh\xF4ng th\xEAm pipe safeHtml ch\u1EC9 \u0111\u1EC3 t\u1EAFt c\u1EA3nh b\xE1o." : "Ki\u1EC3m tra context resource URL v\xE0 allowlist scheme/host tr\u01B0\u1EDBc khi trust; kh\xF4ng bypass d\u1EEF li\u1EC7u b\xEAn ngo\xE0i khi ch\u01B0a validate."
|
|
129
132
|
});
|
|
130
133
|
}
|
|
131
134
|
return findings;
|
|
@@ -15,7 +15,7 @@ var cyclesForGraph = (graph) => {
|
|
|
15
15
|
var formatCycle = (paths) => paths.join(" -> ");
|
|
16
16
|
var rule = {
|
|
17
17
|
id: "general/no-circular-import",
|
|
18
|
-
version:
|
|
18
|
+
version: 5,
|
|
19
19
|
kind: "static-ts",
|
|
20
20
|
title: "Kh\xF4ng t\u1EA1o v\xF2ng import gi\u1EEFa c\xE1c file",
|
|
21
21
|
description: "V\xF2ng import l\xE0m module kh\u1EDFi t\u1EA1o kh\xF4ng \u1ED5n \u0111\u1ECBnh, d\u1EC5 sinh undefined runtime v\xE0 che gi\u1EA5u coupling gi\u1EEFa c\xE1c layer.",
|
|
@@ -36,7 +36,7 @@ var exportedNamesFor = (graph, path) => {
|
|
|
36
36
|
};
|
|
37
37
|
var rule = {
|
|
38
38
|
id: "general/no-unresolved-import-symbol",
|
|
39
|
-
version:
|
|
39
|
+
version: 9,
|
|
40
40
|
kind: "static-ts",
|
|
41
41
|
title: "Khong import/re-export symbol khong duoc export",
|
|
42
42
|
description: "Named import/re-export noi bo phai tro toi symbol ma target file that su export; rule nay bo qua default, namespace, side-effect import va wildcard re-export de tranh false positive.",
|
package/dist/index.d.ts
CHANGED
|
@@ -21,7 +21,13 @@ interface CliBuildMetadata {
|
|
|
21
21
|
readonly buildTimestamp: string;
|
|
22
22
|
readonly configSchemaRange: string;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Values are embedded by tsup, with deterministic safe defaults for source tests.
|
|
26
|
+
* In the review image (Dockerfile.cli) CS_BUILD_GIT_SHA / CS_BUILD_TIMESTAMP are set only right before the
|
|
27
|
+
* build step, so a new commit does not invalidate the cached dependency install.
|
|
28
|
+
* The same commit is the image tag on pt2 workloads (`code-sentinel-review:<sha>@sha256:…`), which is what the
|
|
29
|
+
* Argo CD Telegram notification links to. A change here rebuilds only the review image (servicePackage).
|
|
30
|
+
*/
|
|
25
31
|
declare const getCliBuildMetadata: (version: string) => CliBuildMetadata;
|
|
26
32
|
|
|
27
33
|
interface StoredCredential {
|
|
@@ -143,9 +149,9 @@ declare class LinuxSecretServiceStore implements ISecretStore {
|
|
|
143
149
|
write(service: string, account: string, value: string): Promise<void>;
|
|
144
150
|
remove(service: string, account: string): Promise<void>;
|
|
145
151
|
}
|
|
146
|
-
/** Byte-oriented API
|
|
152
|
+
/** Byte-oriented API stores credential JSON as UTF-8. */
|
|
147
153
|
interface WindowsSecretEntry {
|
|
148
|
-
getSecret(): Promise<Uint8Array | undefined>;
|
|
154
|
+
getSecret(): Promise<Uint8Array | null | undefined>;
|
|
149
155
|
setSecret(secret: Uint8Array): Promise<void>;
|
|
150
156
|
deleteCredential(): Promise<boolean>;
|
|
151
157
|
}
|