@code-sentinel-cli/code-sentinel-cli 4.0.13-avtest.1 → 4.0.14
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 +401 -75
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +7 -0
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.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/static/angular/no-leaky-subscription.rule.js +124 -30
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +14 -38
- package/dist/index.d.ts +1 -1
- package/dist/index.js +401 -75
- package/package.json +2 -2
|
@@ -21,6 +21,13 @@ Bạn là senior Angular reviewer. Đánh giá Angular review unit dưới đây
|
|
|
21
21
|
- Deprecated API được dùng trong wrapper chính với compatibility comment, nhưng caller bên ngoài không bypass contract.
|
|
22
22
|
- Không đủ evidence về service/wrapper/caller contract trong cluster.
|
|
23
23
|
|
|
24
|
+
## Kiểm chứng contract trước khi kết luận
|
|
25
|
+
|
|
26
|
+
- Raw HttpClient vẫn đi qua interceptor đã đăng ký. Raw trả envelope `{detail}`, wrapper có thể unwrap detail; caller đọc res.detail từ raw response là nhất quán. Không đổi wrapper rồi giữ caller gây double unwrap.
|
|
27
|
+
- `%26` là encoding hợp lệ của `&`; backend decode query value. `.join("&")` sai danh sách khi có contract List/string[] hoặc repeated params; nếu backend nhận scalar tự tách thì có thể đúng. Thiếu backend contract thì không đoán delimiter.
|
|
28
|
+
- List<String> và encoder hỗ trợ array: truyền array để sinh `paths=a&paths=b`, giữ ký tự đặc biệt trong mỗi phần tử.
|
|
29
|
+
- Reset-password token khác OAuth accessToken/refreshToken. Field thiếu trong interface là typing gap cần xác minh; không thay reset token bằng accessToken chỉ vì field chưa khai báo.
|
|
30
|
+
|
|
24
31
|
## Primary file
|
|
25
32
|
|
|
26
33
|
Additional non-violations:
|
|
@@ -5,7 +5,7 @@ Bạn là senior Angular/RxJS reviewer. Đánh giá Angular review unit dưới
|
|
|
5
5
|
CRITICAL NON-VIOLATIONS:
|
|
6
6
|
|
|
7
7
|
- NEVER report a component call to an injected signal store / NgRx signal-store `rxMethod` as a direct Observable subscription.
|
|
8
|
-
-
|
|
8
|
+
- Do not require duplicate component-level error/loading handling when support evidence proves that the invoked store/service owns that exact state (e.g. `tapResponse` / `withCallState`). A `catchError` that rethrows, a `finalize` that resets a different flag, or a global toast alone does NOT prove the component state is safe.
|
|
9
9
|
- NEVER report `ngOnDestroy()` containing only `form.reset()` as an RxJS leak or cancellation issue.
|
|
10
10
|
- NEVER report plain component calls like `this.articleStore.getArticle(...)` / `this.articleStore.getComments(...)` as missing unsubscribe when support evidence shows those methods are NgRx signal-store `rxMethod` pipelines.
|
|
11
11
|
|
|
@@ -17,7 +17,7 @@ CRITICAL NON-VIOLATIONS:
|
|
|
17
17
|
|
|
18
18
|
- Nested `subscribe` hoặc subscribe bên trong callback async tạo race/duplicate side effects/khó cancel.
|
|
19
19
|
- Search/filter/autocomplete/load-latest flow dùng `mergeMap`, subscribe thủ công, hoặc Promise mà không cancel request cũ; nên dùng `switchMap`, `takeUntilDestroyed`, hoặc stream composition.
|
|
20
|
-
- Loading/saving flag được set `true` nhưng không reset trong error/cancel path
|
|
20
|
+
- Loading/saving flag được set `true` nhưng không reset trong error/cancel/empty-completion path. Kiểm tra hành vi mọi nhánh; không yêu cầu `finalize` nếu cleanup tương đương đã đủ.
|
|
21
21
|
- Error bị swallow trong Observable/Promise chain khiến UI giữ trạng thái success/loading sai.
|
|
22
22
|
- Side effect phụ thuộc order response nhưng code không bảo vệ out-of-order response.
|
|
23
23
|
- Component gọi service Observable/Subject theo flow làm mất cancellation/error propagation/loading consistency.
|
|
@@ -25,16 +25,29 @@ CRITICAL NON-VIOLATIONS:
|
|
|
25
25
|
## KHÔNG flag
|
|
26
26
|
|
|
27
27
|
- `.subscribe()` chỉ vì thiếu unsubscribe nếu static `angular/no-leaky-subscription` đã bắt và không có bug flow khác.
|
|
28
|
-
- Stream đơn giản
|
|
28
|
+
- Stream đơn giản an toàn qua `async` pipe, hoặc composition có cancellation/error-state phù hợp. `take(1)` và `firstValueFrom` + `try/catch` KHÔNG tự bảo vệ thứ tự response của nhiều lần gọi.
|
|
29
29
|
- Vấn đề naming/style thuần túy.
|
|
30
30
|
- Test/spec/generated files.
|
|
31
31
|
|
|
32
|
+
## Kiểm chứng theo owner và timeline
|
|
33
|
+
|
|
34
|
+
- `takeUntilDestroyed` chỉ hủy khi owner bị destroy; nó KHÔNG hủy request cũ khi search/tab/blur được gọi lại. Ngược lại, `takeUntil` với notifier phát trước mỗi lần đọc, explicit `unsubscribe`, hoặc request-id/selection guard bảo vệ đúng response là cancellation/latest-response hợp lệ, không bắt buộc `switchMap`.
|
|
35
|
+
- Nested subscription không tự chứng minh lỗi. Nếu inner request là tác vụ application-owned, phải hoàn tất qua navigation, không cập nhật component và xử lý lỗi/fallback riêng, KHÔNG đề xuất gắn teardown của component chỉ để loại bỏ nesting. Vẫn bắt nếu có bằng chứng stale component update, thứ tự bị đảo hoặc duplicate command.
|
|
36
|
+
- Guard chống submit/load-more phải được kiểm tra TRƯỚC khi phát request và reset cả khi lỗi/hủy. Nút disabled là hỗ trợ UX; chỉ đổi disabled mà handler vẫn gửi trùng chưa chứng minh an toàn.
|
|
37
|
+
- Promise `await` bị reject sẽ dừng các statement tiếp theo: KHÔNG nói refresh/success vẫn chạy nếu không có recovery/finally tiếp tục flow. SDK trả `{ data, error }` đã resolve là trường hợp khác: phải kiểm tra contract và `result.error` trước success/refresh. Không đoán kiểu trả về khi thiếu bằng chứng SDK.
|
|
38
|
+
- Những response của các tab KHÁC NHAU ghi đúng key riêng không tự tạo race. Chỉ bắt khi cùng key/state có thể bị ghi đè bởi request cũ hoặc callback đọc selection/filter đã thay đổi sau await.
|
|
39
|
+
- Cleanup phụ thất bại sau khi bản ghi đã được lưu là partial success. Cảnh báo riêng, không báo hoàn tất toàn bộ, không gợi ý retry lại create đã thành công. Nếu đã thông báo đúng partial success thì không bắt lỗi swallow.
|
|
40
|
+
- Một subscribe chỉ thiếu teardown và không có flow bug riêng thuộc `angular/no-leaky-subscription`. Không lặp lại finding đó, kể cả static result không được cung cấp.
|
|
41
|
+
|
|
42
|
+
Ví dụ an toàn: mỗi lần search gọi `cancel$.next()` rồi `api.search(q).pipe(takeUntil(cancel$), takeUntilDestroyed(ref))`; callback Promise capture title/filter/request-id trước await và chỉ apply khi còn khớp; pagination khóa request đang chạy và chỉ tăng page trong success.
|
|
43
|
+
Ví dụ lỗi thật gần giống: chỉ có `takeUntilDestroyed(ref)` trong search; callback await ghi `this.selectedTab` hiện tại; page++ trước API rồi không rollback khi lỗi; cờ saving chỉ reset trong next.
|
|
44
|
+
|
|
32
45
|
## Code cần review
|
|
33
46
|
|
|
34
47
|
Additional non-violations:
|
|
35
48
|
|
|
36
49
|
- Calling an injected signal store method / NgRx signal-store `rxMethod` from a component is NOT a direct Observable subscription. Do not flag missing `catchError`, `finalize`, or unsubscribe in the component when the support store method owns the Observable pipeline.
|
|
37
|
-
-
|
|
50
|
+
- Inspect the exact invoked support method and the state it owns. `catchError(() => throwError(...))` still propagates failure; a global error toast does not reset a component saving flag.
|
|
38
51
|
- `ngOnDestroy()` with only `form.reset()` or other Reactive Form cleanup is NOT an RxJS subscription leak.
|
|
39
52
|
- A resolver or component that triggers a store load method is not a race/cancellation bug unless there are multiple competing requests or stale response ordering shown in the cluster.
|
|
40
53
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
id: angular/rxjs-flow-risk
|
|
2
|
-
# v5
|
|
3
|
-
|
|
2
|
+
# v5 calibration retained; v6 adds ownership/timeline/error-contract guidance.
|
|
3
|
+
# Prompt regression tests do not measure live-model precision.
|
|
4
|
+
version: 6
|
|
4
5
|
kind: ai
|
|
5
6
|
title: "Angular RxJS async flow có rủi ro không?"
|
|
6
7
|
description: |
|
|
@@ -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())) {
|
|
@@ -138,7 +223,7 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
138
223
|
message: "subscribe() v\xE0o stream long-lived (valueChanges/params/fromEvent/interval\u2026) kh\xF4ng h\u1EE7y \u2014 memory leak khi component hu\u1EF7.",
|
|
139
224
|
file,
|
|
140
225
|
range,
|
|
141
|
-
suggestion: "
|
|
226
|
+
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
227
|
// v5 (ADR-0065): 80→95. Đo trên hai module Angular sản xuất: 96 finding
|
|
143
228
|
// band `long-lived`, 0 bị bác. `baseConfidence` của rule này là metadata
|
|
144
229
|
// CHẾT — mọi finding đều mang confidence riêng — nên hiệu chỉnh phải sửa
|
|
@@ -147,22 +232,32 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
147
232
|
severity: "error"
|
|
148
233
|
};
|
|
149
234
|
}
|
|
235
|
+
if (kind === "member-risk") {
|
|
236
|
+
return {
|
|
237
|
+
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.",
|
|
238
|
+
file,
|
|
239
|
+
range,
|
|
240
|
+
severity: "warning",
|
|
241
|
+
confidence: 75,
|
|
242
|
+
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."
|
|
243
|
+
};
|
|
244
|
+
}
|
|
150
245
|
if (kind === "one-shot") {
|
|
151
246
|
return {
|
|
152
|
-
message: "
|
|
247
|
+
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
248
|
file,
|
|
154
249
|
range,
|
|
155
|
-
suggestion: "
|
|
250
|
+
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
251
|
// v5 (ADR-0065): 70→90. Đo 430 finding band `one-shot`, 0 bị bác.
|
|
157
252
|
confidence: 90,
|
|
158
253
|
severity: "warning"
|
|
159
254
|
};
|
|
160
255
|
}
|
|
161
256
|
return {
|
|
162
|
-
message: "
|
|
257
|
+
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
258
|
file,
|
|
164
259
|
range,
|
|
165
|
-
suggestion: "
|
|
260
|
+
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
261
|
// v5 (ADR-0065): 60→85. Band yếu nhất (không nhận diện được nguồn), nên
|
|
167
262
|
// vẫn giữ thấp hơn hai band trên một bậc.
|
|
168
263
|
confidence: 85,
|
|
@@ -171,17 +266,16 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
171
266
|
};
|
|
172
267
|
var rule = {
|
|
173
268
|
id: "angular/no-leaky-subscription",
|
|
174
|
-
|
|
175
|
-
version: 5,
|
|
269
|
+
version: 6,
|
|
176
270
|
kind: "static-ts",
|
|
177
271
|
title: "Subscription ph\u1EA3i \u0111\u01B0\u1EE3c h\u1EE7y (takeUntil / unsubscribe / Subscription.add / async pipe)",
|
|
178
|
-
description: "
|
|
272
|
+
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
273
|
severity: "error",
|
|
180
274
|
category: "memory-safety",
|
|
181
275
|
languages: ["typescript"],
|
|
182
276
|
scope: "angular",
|
|
183
277
|
requires: "semantic-ts",
|
|
184
|
-
//
|
|
278
|
+
// Per-finding confidence: confirmed factories 95, finite contracts 90, unknown 85, members 75.
|
|
185
279
|
baseConfidence: 85,
|
|
186
280
|
check(ctx) {
|
|
187
281
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
@@ -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];
|
|
@@ -54,12 +53,12 @@ function rootIdentifier(expr) {
|
|
|
54
53
|
}
|
|
55
54
|
var rule = {
|
|
56
55
|
id: "angular/template-dom-xss",
|
|
57
|
-
//
|
|
58
|
-
version:
|
|
56
|
+
// v5 corrects native Angular HTML sanitizer semantics; old calibration is not reused as proof.
|
|
57
|
+
version: 5,
|
|
59
58
|
kind: "static-ts",
|
|
60
59
|
usesTemplateComponent: true,
|
|
61
60
|
title: "Binding nguy hi\u1EC3m trong template Angular (DOM XSS)",
|
|
62
|
-
description: "
|
|
61
|
+
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
62
|
severity: "warning",
|
|
64
63
|
category: "security",
|
|
65
64
|
checklistIds: ["58", "98", "99"],
|
|
@@ -76,30 +75,24 @@ var rule = {
|
|
|
76
75
|
if (!nameNode) continue;
|
|
77
76
|
const { prop, isBinding } = normalizeBinding(nameNode.text);
|
|
78
77
|
if (!isBinding) continue;
|
|
79
|
-
const
|
|
80
|
-
const
|
|
78
|
+
const tag = enclosingTag(attr);
|
|
79
|
+
const isHtmlSink = HTML_SINK_PROPS.has(prop) || prop === "srcdoc" && tag === "iframe";
|
|
81
80
|
const isUrlSink = !isHtmlSink && tag !== null && (URL_SINK_TAGS[prop]?.has(tag) ?? false);
|
|
82
81
|
if (!isHtmlSink && !isUrlSink) continue;
|
|
83
82
|
const value = attributeValue(attr);
|
|
84
|
-
if (PURE_STRING_LITERAL.test(value)) continue;
|
|
85
|
-
|
|
83
|
+
if (isHtmlSink && PURE_STRING_LITERAL.test(value)) continue;
|
|
84
|
+
const hasPipe = HAS_PIPE.test(value);
|
|
85
|
+
const hasCall = /[\w$)]\s*\(/.test(value);
|
|
86
86
|
let origin = "unknown";
|
|
87
87
|
if (link) {
|
|
88
88
|
const root = rootIdentifier(value);
|
|
89
89
|
if (root) origin = link.memberOrigins.get(root) ?? "unknown";
|
|
90
90
|
}
|
|
91
|
-
if (origin === "sanitizer-trusted") continue;
|
|
92
|
-
const confirmed = origin === "tainted-source";
|
|
93
91
|
const externalBypass = origin === "external-bypass";
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
} else if (externalBypass) {
|
|
99
|
-
message = `\u26D4 Bypass sanitizer tr\xEAn d\u1EEF li\u1EC7u T\u1EEA B\xCAN NGO\xC0I component: ${where} \u2014 \`${value}\` \u0111\u01B0\u1EE3c g\xE1n qua \`bypassSecurityTrust*\` trong \`${link?.componentPath}\`, v\xE0 gi\xE1 tr\u1ECB \u0111\xF3 \u0111\u1EBFn t\u1EEB \`@Input()\`/tham s\u1ED1 method (component n\xE0y KH\xD4NG t\u1EF1 sinh ra n\xF3). Angular \u0111\xE3 b\u1ECB t\u1EAFt sanitizer cho m\u1ED9t gi\xE1 tr\u1ECB m\xE0 n\u01A1i kh\xE1c quy\u1EBFt \u0111\u1ECBnh \u2014 n\u1EBFu ngu\u1ED3n cu\u1ED1i l\xE0 d\u1EEF li\u1EC7u server l\u01B0u, \u0111\xE2y l\xE0 stored XSS.`;
|
|
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
|
-
}
|
|
92
|
+
if (origin === "sanitizer-trusted" && !hasPipe && !hasCall) continue;
|
|
93
|
+
if (isHtmlSink && !externalBypass && !hasPipe && !hasCall) continue;
|
|
94
|
+
const where = `\`${nameNode.text}\` (${value})`;
|
|
95
|
+
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
96
|
findings.push({
|
|
104
97
|
message,
|
|
105
98
|
file: ctx.file.path,
|
|
@@ -107,25 +100,8 @@ var rule = {
|
|
|
107
100
|
line: attr.startPosition.row + 1,
|
|
108
101
|
column: attr.startPosition.column + 1
|
|
109
102
|
},
|
|
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
103
|
...externalBypass ? { confidence: 80 } : {},
|
|
128
|
-
suggestion:
|
|
104
|
+
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
105
|
});
|
|
130
106
|
}
|
|
131
107
|
return findings;
|
package/dist/index.d.ts
CHANGED
|
@@ -143,7 +143,7 @@ declare class LinuxSecretServiceStore implements ISecretStore {
|
|
|
143
143
|
write(service: string, account: string, value: string): Promise<void>;
|
|
144
144
|
remove(service: string, account: string): Promise<void>;
|
|
145
145
|
}
|
|
146
|
-
/** Byte-oriented API
|
|
146
|
+
/** Byte-oriented API stores credential JSON as UTF-8. */
|
|
147
147
|
interface WindowsSecretEntry {
|
|
148
148
|
getSecret(): Promise<Uint8Array | undefined>;
|
|
149
149
|
setSecret(secret: Uint8Array): Promise<void>;
|