@code-sentinel-cli/code-sentinel-cli 3.0.9 → 3.0.11
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 +38961 -19863
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +3 -6
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +4 -8
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +0 -2
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +19 -2
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +8 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +3 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +4 -10
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +9 -8
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +12 -14
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +4 -4
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +3 -3
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +1 -2
- package/dist/builtin-rules/static/angular/button-accessible-name.rule.js +143 -0
- package/dist/builtin-rules/static/angular/component-prefix.rule.js +6 -2
- package/dist/builtin-rules/static/angular/img-alt-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/inject-pattern.rule.js +3 -2
- package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +14 -5
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +28 -4
- package/dist/builtin-rules/static/angular/trackby-required.rule.js +3 -2
- package/dist/builtin-rules/static/flutter/no-undisposed-resource.rule.js +143 -0
- package/dist/builtin-rules/static/general/file-too-long.rule.js +5 -4
- package/dist/builtin-rules/static/general/function-too-long.rule.js +46 -27
- package/dist/builtin-rules/static/general/no-code-injection.rule.js +8 -1
- package/dist/builtin-rules/static/general/no-console-log.rule.js +3 -2
- package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +14 -8
- package/dist/builtin-rules/static/general/no-hardcoded-vietnamese.rule.js +58 -0
- package/dist/builtin-rules/static/general/no-magic-number.rule.js +151 -8
- package/dist/builtin-rules/static/general/no-todo-comment.rule.js +88 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +53 -6
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +14 -1
- package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +1 -1
- package/dist/builtin-rules/static/spring-boot/no-servlet-xss.rule.js +41 -0
- package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +8 -1
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +35 -4
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +1 -1
- package/dist/builtin-rules/static/spring-boot/no-unzoned-datetime.rule.js +96 -0
- package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +4 -2
- package/dist/index.d.ts +316 -132
- package/dist/index.js +38952 -19854
- package/package.json +1 -1
- package/templates/ci/github-actions.yml +60 -2
- package/templates/ci/gitlab-ci.yml +51 -2
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +0 -30
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/io-boundary-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 2
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot filesystem/HTTP/queue boundary co rui ro khong?"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./io-boundary-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1800
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -7,7 +7,7 @@ CRITICAL NON-VIOLATIONS:
|
|
|
7
7
|
- NEVER report generic missing login/auth annotation. `spring-boot/security-authorization-risk` owns endpoint-level missing authorization.
|
|
8
8
|
- NEVER report a scope gap when repository/service query already includes principal/user/account/tenant/owner/deleted scope.
|
|
9
9
|
- NEVER report a DTO validation issue, SQL concat, transaction placement, raw exception response, SSRF, or filesystem issue.
|
|
10
|
-
- NEVER report
|
|
10
|
+
- NEVER report a file that only plays a supporting/evidence role (a global exception handler, a DTO, a class the cluster shows as the safe path) unless PRIMARY shows direct, unscoped data access evidence in the unsafe method itself.
|
|
11
11
|
- NEVER report pure list/pagination/findAll/unbounded-result problems here. `spring-boot/pagination-risk` owns pagination/result-window gaps, even when entities have tenant/account fields.
|
|
12
12
|
|
|
13
13
|
1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan convention ngoai cluster.
|
|
@@ -27,7 +27,7 @@ CRITICAL NON-VIOLATIONS:
|
|
|
27
27
|
- `list()`, `findAll()`, fallback list, pagination/limit gaps, hoac endpoint tra ve collection ma khong nhan object id cu the tu request. De `pagination-risk` xu ly.
|
|
28
28
|
- Entity/service khong co bang chung ownership/tenant/account boundary.
|
|
29
29
|
- Flow co `Principal`, `Authentication`, current user/tenant, scoped query (`findByIdAndOwnerId`, `findByTenantIdAndId`, `deleted=false`), ownership validator, policy service, hoac method security voi object-scope ro rang.
|
|
30
|
-
-
|
|
30
|
+
- Luong DTO an toan, hoac file support-only (global exception handler, mapper, config) neu khong co direct unsafe scoped data access trong PRIMARY.
|
|
31
31
|
- Endpoint public-safe/doc lookup khong co sensitive domain boundary trong cluster.
|
|
32
32
|
- Thieu auth chung chung; chi flag neu co data ownership/scope gap rieng.
|
|
33
33
|
- Style/naming/refactor suggestion.
|
|
@@ -76,7 +76,7 @@ Neu khong co ownership/scope bug ro rang: `{"violations": []}`.
|
|
|
76
76
|
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
77
77
|
- Khong flag generic missing auth; chi flag owner/tenant/account/deleted scope gap co evidence.
|
|
78
78
|
- Khong flag list/findAll/pagination/unbounded collection; rule nay chi bat object-level owner/tenant/account scope gap.
|
|
79
|
-
- Khong flag
|
|
79
|
+
- Khong flag file support-only (global exception handler, DTO, luong an toan) tru khi PRIMARY co direct unsafe data access evidence.
|
|
80
80
|
- Khong duplicate static rules hoac cac rule `io-boundary-risk`, `transaction-loop-risk`, `pagination-risk`, `business-invariant-risk`, `error-handling-completeness`.
|
|
81
81
|
- Confidence `<50` -> KHONG emit.
|
|
82
82
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/ownership-scope-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 4
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot ownership/tenant scope flow co rui ro khong?"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./ownership-scope-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1800
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/pagination-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 2
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Pagination Risk"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./pagination-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1800
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
id: spring-boot/security-authorization-risk
|
|
2
|
-
|
|
2
|
+
# v2 (ADR-0065 calibration): conf 60→75 (đo 19/19 TP gộp với mass-assignment; 15/15 ở --min-confidence 85)
|
|
3
|
+
version: 2
|
|
3
4
|
kind: ai
|
|
4
5
|
title: "Spring Boot endpoint authorization gap?"
|
|
5
6
|
description: |
|
|
@@ -12,10 +13,9 @@ severity: warning
|
|
|
12
13
|
category: security
|
|
13
14
|
languages: [java]
|
|
14
15
|
scope: spring-boot
|
|
15
|
-
baseConfidence:
|
|
16
|
+
baseConfidence: 75
|
|
16
17
|
prompt: ./security-authorization-risk.prompt.md
|
|
17
18
|
contextScope: per-cluster
|
|
18
|
-
maxTokens: 1200
|
|
19
19
|
aiConfig:
|
|
20
20
|
tier: regular
|
|
21
21
|
prRouting:
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
id: spring-boot/security-mass-assignment-risk
|
|
2
|
-
|
|
2
|
+
# v2 (ADR-0065 calibration): conf 60→75 (đo cùng lô 19/19 TP)
|
|
3
|
+
version: 2
|
|
3
4
|
kind: ai
|
|
4
5
|
title: "Spring Boot mass assignment or security-state input?"
|
|
5
6
|
description: |
|
|
@@ -10,10 +11,9 @@ severity: warning
|
|
|
10
11
|
category: security
|
|
11
12
|
languages: [java]
|
|
12
13
|
scope: spring-boot
|
|
13
|
-
baseConfidence:
|
|
14
|
+
baseConfidence: 75
|
|
14
15
|
prompt: ./security-mass-assignment-risk.prompt.md
|
|
15
16
|
contextScope: per-cluster
|
|
16
|
-
maxTokens: 1200
|
|
17
17
|
aiConfig:
|
|
18
18
|
tier: regular
|
|
19
19
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/security-redirect-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 2
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot open redirect or unsafe forward?"
|
|
5
5
|
description: |
|
|
@@ -13,7 +13,6 @@ scope: spring-boot
|
|
|
13
13
|
baseConfidence: 60
|
|
14
14
|
prompt: ./security-redirect-risk.prompt.md
|
|
15
15
|
contextScope: per-cluster
|
|
16
|
-
maxTokens: 1000
|
|
17
16
|
aiConfig:
|
|
18
17
|
tier: regular
|
|
19
18
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/security-sensitive-data-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 2
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot sensitive data exposure?"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./security-sensitive-data-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1200
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
id: spring-boot/transaction-loop-risk
|
|
2
|
-
version:
|
|
2
|
+
version: 3
|
|
3
3
|
kind: ai
|
|
4
4
|
title: "Spring Boot transaction/loop flow co rui ro khong?"
|
|
5
5
|
description: |
|
|
@@ -14,7 +14,6 @@ scope: spring-boot
|
|
|
14
14
|
baseConfidence: 60
|
|
15
15
|
prompt: ./transaction-loop-risk.prompt.md
|
|
16
16
|
contextScope: per-cluster
|
|
17
|
-
maxTokens: 1800
|
|
18
17
|
aiConfig:
|
|
19
18
|
tier: regular
|
|
20
19
|
prRouting:
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/static/angular/button-accessible-name.rule.ts
|
|
4
|
+
var ACCESSIBLE_NAME_ATTRS = /* @__PURE__ */ new Set([
|
|
5
|
+
"aria-label",
|
|
6
|
+
"aria-labelledby",
|
|
7
|
+
"title"
|
|
8
|
+
]);
|
|
9
|
+
var DECORATIVE_ROLES = /* @__PURE__ */ new Set(["presentation", "none"]);
|
|
10
|
+
function* walkNodes(node) {
|
|
11
|
+
const stack = [node];
|
|
12
|
+
while (stack.length > 0) {
|
|
13
|
+
const cur = stack.pop();
|
|
14
|
+
if (!cur) break;
|
|
15
|
+
yield cur;
|
|
16
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
17
|
+
const child = cur.namedChild(i);
|
|
18
|
+
if (child) stack.push(child);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
function namedChildOfType(node, type) {
|
|
23
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
24
|
+
const child = node.namedChild(i);
|
|
25
|
+
if (child?.type === type) return child;
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
function normalizeAttrName(name) {
|
|
30
|
+
let inner = name;
|
|
31
|
+
const bracket = /^\[(.+)\]$/.exec(inner);
|
|
32
|
+
if (bracket?.[1]) inner = bracket[1];
|
|
33
|
+
else if (inner.startsWith("bind-")) inner = inner.slice("bind-".length);
|
|
34
|
+
return inner.replace(/^attr\./i, "").toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
function attributeValue(attr) {
|
|
37
|
+
const quoted = namedChildOfType(attr, "quoted_attribute_value");
|
|
38
|
+
const value = quoted ? namedChildOfType(quoted, "attribute_value") : null;
|
|
39
|
+
return value?.text ?? "";
|
|
40
|
+
}
|
|
41
|
+
function hasAccessibleAttr(tagNode) {
|
|
42
|
+
for (let i = 0; i < tagNode.namedChildCount; i++) {
|
|
43
|
+
const child = tagNode.namedChild(i);
|
|
44
|
+
if (child?.type !== "attribute") continue;
|
|
45
|
+
const nameNode = namedChildOfType(child, "attribute_name");
|
|
46
|
+
if (!nameNode) continue;
|
|
47
|
+
const prop = normalizeAttrName(nameNode.text);
|
|
48
|
+
if (ACCESSIBLE_NAME_ATTRS.has(prop)) return true;
|
|
49
|
+
if (prop === "aria-hidden" && attributeValue(child).trim().toLowerCase() === "true") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
if (prop === "role" && DECORATIVE_ROLES.has(attributeValue(child).trim().toLowerCase())) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
function hasInteractiveLinkAttr(tagNode) {
|
|
59
|
+
for (let i = 0; i < tagNode.namedChildCount; i++) {
|
|
60
|
+
const child = tagNode.namedChild(i);
|
|
61
|
+
if (child?.type !== "attribute") continue;
|
|
62
|
+
const nameNode = namedChildOfType(child, "attribute_name");
|
|
63
|
+
if (!nameNode) continue;
|
|
64
|
+
const prop = normalizeAttrName(nameNode.text);
|
|
65
|
+
if (prop === "href" || prop === "routerlink") return true;
|
|
66
|
+
}
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
function isInsideIconTag(node, rootElement) {
|
|
70
|
+
let cur = node.parent;
|
|
71
|
+
while (cur && cur !== rootElement) {
|
|
72
|
+
if (cur.type === "element") {
|
|
73
|
+
const startTag = namedChildOfType(cur, "start_tag") ?? namedChildOfType(cur, "self_closing_tag");
|
|
74
|
+
const tag = startTag ? namedChildOfType(startTag, "tag_name")?.text.toLowerCase() : null;
|
|
75
|
+
if (tag === "mat-icon" || tag === "svg" || tag === "i") {
|
|
76
|
+
return true;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
cur = cur.parent;
|
|
80
|
+
}
|
|
81
|
+
return false;
|
|
82
|
+
}
|
|
83
|
+
function hasMeaningfulTextOrDirective(elementNode) {
|
|
84
|
+
for (const node of walkNodes(elementNode)) {
|
|
85
|
+
if (node.type === "text") {
|
|
86
|
+
const text = node.text.trim();
|
|
87
|
+
if (text.length > 0 && !isInsideIconTag(node, elementNode)) return true;
|
|
88
|
+
}
|
|
89
|
+
if (node.type === "attribute") {
|
|
90
|
+
const nameNode = namedChildOfType(node, "attribute_name");
|
|
91
|
+
if (nameNode) {
|
|
92
|
+
const prop = normalizeAttrName(nameNode.text);
|
|
93
|
+
if (prop === "translate" || prop === "i18n" || ACCESSIBLE_NAME_ATTRS.has(prop)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
var rule = {
|
|
102
|
+
id: "angular/button-accessible-name",
|
|
103
|
+
version: 1,
|
|
104
|
+
kind: "static-ts",
|
|
105
|
+
title: "`<button>` v\xE0 `<a>` ph\u1EA3i c\xF3 accessible name (text ho\u1EB7c `aria-label`)",
|
|
106
|
+
description: "N\xFAt b\u1EA5m (`<button>`) v\xE0 li\xEAn k\u1EBFt (`<a>`) thi\u1EBFu accessible name vi ph\u1EA1m WCAG 4.1.2 / 2.4.4. N\u1EBFu n\xFAt ch\u1EC9 ch\u1EE9a icon (nh\u01B0 `<mat-icon>`, `<i>`, `<svg>`), h\xE3y th\xEAm thu\u1ED9c t\xEDnh `aria-label` ho\u1EB7c text \u1EA9n (`cdk-visually-hidden`) \u0111\u1EC3 ng\u01B0\u1EDDi d\xF9ng screen-reader hi\u1EC3u \u0111\u01B0\u1EE3c ch\u1EE9c n\u0103ng.",
|
|
107
|
+
severity: "warning",
|
|
108
|
+
category: "accessibility",
|
|
109
|
+
languages: ["html"],
|
|
110
|
+
scope: "angular",
|
|
111
|
+
requires: "syntactic",
|
|
112
|
+
baseConfidence: 85,
|
|
113
|
+
check(ctx) {
|
|
114
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
115
|
+
const findings = [];
|
|
116
|
+
for (const node of walkNodes(tree.rootNode)) {
|
|
117
|
+
if (node.type !== "element") continue;
|
|
118
|
+
const startTag = namedChildOfType(node, "start_tag") ?? namedChildOfType(node, "self_closing_tag");
|
|
119
|
+
if (!startTag) continue;
|
|
120
|
+
const tagNameNode = namedChildOfType(startTag, "tag_name");
|
|
121
|
+
if (!tagNameNode) continue;
|
|
122
|
+
const tag = tagNameNode.text.toLowerCase();
|
|
123
|
+
if (tag !== "button" && tag !== "a") continue;
|
|
124
|
+
if (tag === "a" && !hasInteractiveLinkAttr(startTag)) continue;
|
|
125
|
+
if (hasAccessibleAttr(startTag)) continue;
|
|
126
|
+
if (hasMeaningfulTextOrDirective(node)) continue;
|
|
127
|
+
findings.push({
|
|
128
|
+
message: `<${tag}> thi\u1EBFu accessible name \u2014 screen-reader kh\xF4ng \u0111\u1ECDc \u0111\u01B0\u1EE3c m\xF4 t\u1EA3 h\xE0nh \u0111\u1ED9ng (l\u1ED7i WCAG 4.1.2). Th\xEAm text b\xEAn trong n\xFAt ho\u1EB7c khai b\xE1o thu\u1ED9c t\xEDnh \`aria-label="m\xF4 t\u1EA3"\`.`,
|
|
129
|
+
file: ctx.file.path,
|
|
130
|
+
range: {
|
|
131
|
+
line: startTag.startPosition.row + 1,
|
|
132
|
+
column: startTag.startPosition.column + 1
|
|
133
|
+
},
|
|
134
|
+
suggestion: 'Th\xEAm `aria-label="T\xEAn h\xE0nh \u0111\u1ED9ng"` ho\u1EB7c th\xEAm text n\u1ED9i dung v\xE0o b\xEAn trong th\u1EBB.'
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return findings;
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
export { rule };
|
|
142
|
+
//# sourceMappingURL=button-accessible-name.rule.js.map
|
|
143
|
+
//# sourceMappingURL=button-accessible-name.rule.js.map
|
|
@@ -39,11 +39,15 @@ var hasAllowedPrefix = (selector, prefixes) => {
|
|
|
39
39
|
};
|
|
40
40
|
var rule = {
|
|
41
41
|
id: "angular/component-prefix",
|
|
42
|
-
|
|
42
|
+
// v3 (ADR-0065 calibration): severity warning→info (quy ước đặt tên)
|
|
43
|
+
version: 3,
|
|
43
44
|
kind: "static-ts",
|
|
44
45
|
title: "Component selector ph\u1EA3i c\xF3 prefix d\u1EF1 \xE1n",
|
|
45
46
|
description: '@Component selector n\xEAn b\u1EAFt \u0111\u1EA7u b\u1EB1ng prefix do d\u1EF1 \xE1n quy \u0111\u1ECBnh. Default prefix l\xE0 `app-` (Angular CLI). Tune cho d\u1EF1 \xE1n Viettel qua `options.prefixes: ["vts", "v"]` trong `.codereviewrc.yaml`.',
|
|
46
|
-
|
|
47
|
+
// ADR-0065: quy ước đặt tên thuần tuý → `info`. Trước bản này rule này ở
|
|
48
|
+
// `warning`/100, tức xếp CAO HƠN `angular/template-dom-xss` (XSS, warning/70)
|
|
49
|
+
// — một quy ước selector không thể nghiêm trọng hơn một lỗ hổng XSS.
|
|
50
|
+
severity: "info",
|
|
47
51
|
category: "angular-best-practice",
|
|
48
52
|
languages: ["typescript"],
|
|
49
53
|
scope: "angular",
|
|
@@ -61,7 +61,8 @@ function hasTextAlternative(tag) {
|
|
|
61
61
|
}
|
|
62
62
|
var rule = {
|
|
63
63
|
id: "angular/img-alt-required",
|
|
64
|
-
|
|
64
|
+
// v2 (ADR-0065 calibration): conf 80→90 (đo 32/32 TP)
|
|
65
|
+
version: 2,
|
|
65
66
|
kind: "static-ts",
|
|
66
67
|
title: "`<img>` ph\u1EA3i c\xF3 text alternative (`alt`) \u0111\u1EC3 \u0111\u1EA3m b\u1EA3o accessibility",
|
|
67
68
|
description: 'Th\u1EBB `<img>` thi\u1EBFu text alternative l\xE0 l\u1ED7i WCAG 1.1.1 (Level A): ng\u01B0\u1EDDi d\xF9ng screen-reader kh\xF4ng nh\u1EADn \u0111\u01B0\u1EE3c th\xF4ng tin g\xEC, nhi\u1EC1u tr\xECnh duy\u1EC7t \u0111\u1ECDc lu\xF4n t\xEAn file trong `src`. Th\xEAm `alt` m\xF4 t\u1EA3 n\u1ED9i dung \u1EA3nh; n\u1EBFu \u1EA3nh ch\u1EC9 trang tr\xED th\xEC d\xF9ng `alt=""` (khai b\xE1o r\xF5 l\xE0 decorative). \u1EA2nh \u0111\u1ED9ng c\u0169ng c\xF3 th\u1EC3 d\xF9ng `[alt]="\u2026"`. Rule b\u1ECF qua khi `<img>` \u0111\xE3 c\xF3 `alt`/`aria-label`/`aria-labelledby`/`title`/`aria-hidden` ho\u1EB7c `role="presentation"|"none"`.',
|
|
@@ -70,7 +71,7 @@ var rule = {
|
|
|
70
71
|
languages: ["html"],
|
|
71
72
|
scope: "angular",
|
|
72
73
|
requires: "syntactic",
|
|
73
|
-
baseConfidence:
|
|
74
|
+
baseConfidence: 90,
|
|
74
75
|
check(ctx) {
|
|
75
76
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
76
77
|
const findings = [];
|
|
@@ -10,7 +10,8 @@ var hasAngularDecorator = (cls) => {
|
|
|
10
10
|
};
|
|
11
11
|
var rule = {
|
|
12
12
|
id: "angular/inject-pattern",
|
|
13
|
-
|
|
13
|
+
// v2 (ADR-0065 calibration): conf 75→95 (đo 193/193 TP; đếm tham số không thể sai)
|
|
14
|
+
version: 2,
|
|
14
15
|
kind: "static-ts",
|
|
15
16
|
title: "D\xF9ng inject() thay v\xEC constructor DI (Angular 14+)",
|
|
16
17
|
description: "inject() ch\u1EA1y \u0111\u01B0\u1EE3c trong field initializer, g\u1ECDn h\u01A1n constructor params. C\u0169ng l\xE0 pattern b\u1EAFt bu\u1ED9c cho m\u1ED9t s\u1ED1 functional guards / interceptors. Flag m\u1ECDi constructor c\xF3 param trong class Angular (Component/Directive/Injectable/Pipe).",
|
|
@@ -19,7 +20,7 @@ var rule = {
|
|
|
19
20
|
languages: ["typescript"],
|
|
20
21
|
scope: "angular",
|
|
21
22
|
requires: "semantic-ts",
|
|
22
|
-
baseConfidence:
|
|
23
|
+
baseConfidence: 95,
|
|
23
24
|
check(ctx) {
|
|
24
25
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
25
26
|
const findings = [];
|
|
@@ -21,7 +21,8 @@ var getImplementedInterfaceNames = (cls) => {
|
|
|
21
21
|
};
|
|
22
22
|
var rule = {
|
|
23
23
|
id: "angular/lifecycle-method-required",
|
|
24
|
-
|
|
24
|
+
// v2 (ADR-0065 calibration): conf 85→95 (đo 71/71 TP)
|
|
25
|
+
version: 2,
|
|
25
26
|
kind: "static-ts",
|
|
26
27
|
title: "Class c\xF3 lifecycle method ph\u1EA3i `implements` interface t\u01B0\u01A1ng \u1EE9ng",
|
|
27
28
|
description: "Khi class c\xF3 ngOnInit/ngOnDestroy/... ph\u1EA3i khai b\xE1o `implements OnInit`/etc. Compiler s\u1EBD verify signature; typo (vd `ngOninit`) s\u1EBD b\u1ECB compiler b\u1EAFt thay v\xEC silent fail.",
|
|
@@ -30,7 +31,7 @@ var rule = {
|
|
|
30
31
|
languages: ["typescript"],
|
|
31
32
|
scope: "angular",
|
|
32
33
|
requires: "semantic-ts",
|
|
33
|
-
baseConfidence:
|
|
34
|
+
baseConfidence: 95,
|
|
34
35
|
check(ctx) {
|
|
35
36
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
36
37
|
const findings = [];
|
|
@@ -139,7 +139,11 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
139
139
|
file,
|
|
140
140
|
range,
|
|
141
141
|
suggestion: "B\u1ECDc `.pipe(takeUntilDestroyed())` / `.pipe(takeUntil(this.destroy$))`, ho\u1EB7c d\xF9ng `async` pipe trong template.",
|
|
142
|
-
|
|
142
|
+
// v5 (ADR-0065): 80→95. Đo trên hai module Angular sản xuất: 96 finding
|
|
143
|
+
// band `long-lived`, 0 bị bác. `baseConfidence` của rule này là metadata
|
|
144
|
+
// CHẾT — mọi finding đều mang confidence riêng — nên hiệu chỉnh phải sửa
|
|
145
|
+
// ở đây, không phải ở khai báo rule.
|
|
146
|
+
confidence: 95,
|
|
143
147
|
severity: "error"
|
|
144
148
|
};
|
|
145
149
|
}
|
|
@@ -149,7 +153,8 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
149
153
|
file,
|
|
150
154
|
range,
|
|
151
155
|
suggestion: "Th\xEAm `.pipe(takeUntilDestroyed())` ho\u1EB7c d\xF9ng `async` pipe / `firstValueFrom`.",
|
|
152
|
-
|
|
156
|
+
// v5 (ADR-0065): 70→90. Đo 430 finding band `one-shot`, 0 bị bác.
|
|
157
|
+
confidence: 90,
|
|
153
158
|
severity: "warning"
|
|
154
159
|
};
|
|
155
160
|
}
|
|
@@ -158,13 +163,16 @@ var findingFor = (nameNode, file, kind) => {
|
|
|
158
163
|
file,
|
|
159
164
|
range,
|
|
160
165
|
suggestion: "L\u01B0u subscription r\u1ED3i `unsubscribe()` trong ngOnDestroy, gom v\xE0o m\u1ED9t `Subscription`, ho\u1EB7c d\xF9ng `takeUntilDestroyed()` / `async` pipe.",
|
|
161
|
-
|
|
166
|
+
// v5 (ADR-0065): 60→85. Band yếu nhất (không nhận diện được nguồn), nên
|
|
167
|
+
// vẫn giữ thấp hơn hai band trên một bậc.
|
|
168
|
+
confidence: 85,
|
|
162
169
|
severity: "warning"
|
|
163
170
|
};
|
|
164
171
|
};
|
|
165
172
|
var rule = {
|
|
166
173
|
id: "angular/no-leaky-subscription",
|
|
167
|
-
|
|
174
|
+
// v5 (ADR-0065 calibration): conf 80→95 (đo 526/526 TP trên 2 module Angular sản xuất)
|
|
175
|
+
version: 5,
|
|
168
176
|
kind: "static-ts",
|
|
169
177
|
title: "Subscription ph\u1EA3i \u0111\u01B0\u1EE3c h\u1EE7y (takeUntil / unsubscribe / Subscription.add / async pipe)",
|
|
170
178
|
description: "Flags bare .subscribe() calls WITHOUT visible teardown. v4 (precision-first): SUPPRESSES managed subscriptions (stored + unsubscribe(), or added to a Subscription collection via .add()) and terminating pipes (takeUntil/take/first/\u2026). Severity is per-subscription: long-lived streams (valueChanges/params/fromEvent/interval) stay `error` (genuine leak); one-shot sources (HTTP call/afterClosed/forkJoin) and unclassified streams are `warning`.",
|
|
@@ -173,7 +181,8 @@ var rule = {
|
|
|
173
181
|
languages: ["typescript"],
|
|
174
182
|
scope: "angular",
|
|
175
183
|
requires: "semantic-ts",
|
|
176
|
-
|
|
184
|
+
// Fallback thôi: mọi finding của rule này đều tự khai confidence (95/90/85).
|
|
185
|
+
baseConfidence: 85,
|
|
177
186
|
check(ctx) {
|
|
178
187
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
179
188
|
const findings = [];
|
|
@@ -29,7 +29,8 @@ var usesOnPush = (obj) => {
|
|
|
29
29
|
var hasSpread = (obj) => obj.getProperties().some((prop) => Node.isSpreadAssignment(prop));
|
|
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: 3,
|
|
33
34
|
kind: "static-ts",
|
|
34
35
|
title: "@Component n\xEAn d\xF9ng ChangeDetectionStrategy.OnPush",
|
|
35
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 conf 70), 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).",
|
|
@@ -41,7 +42,7 @@ var rule = {
|
|
|
41
42
|
// A4 calibration: 85→70. Detection is deterministic, but "should be OnPush"
|
|
42
43
|
// is a judgment — some Default components are intentional. 70 = "worth a look,
|
|
43
44
|
// not certain", so `--min-confidence` can filter it out of a strict gate.
|
|
44
|
-
baseConfidence:
|
|
45
|
+
baseConfidence: 95,
|
|
45
46
|
check(ctx) {
|
|
46
47
|
const sf = asTsMorphSourceFile(ctx.parsed);
|
|
47
48
|
const findings = [];
|
|
@@ -54,7 +54,8 @@ function rootIdentifier(expr) {
|
|
|
54
54
|
}
|
|
55
55
|
var rule = {
|
|
56
56
|
id: "angular/template-dom-xss",
|
|
57
|
-
|
|
57
|
+
// v4 (ADR-0065 calibration): conf 70→90 (đo 76/76 TP)
|
|
58
|
+
version: 4,
|
|
58
59
|
kind: "static-ts",
|
|
59
60
|
usesTemplateComponent: true,
|
|
60
61
|
title: "Binding nguy hi\u1EC3m trong template Angular (DOM XSS)",
|
|
@@ -64,7 +65,7 @@ var rule = {
|
|
|
64
65
|
languages: ["html"],
|
|
65
66
|
scope: "angular",
|
|
66
67
|
requires: "syntactic",
|
|
67
|
-
baseConfidence:
|
|
68
|
+
baseConfidence: 90,
|
|
68
69
|
check(ctx) {
|
|
69
70
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
70
71
|
const findings = [];
|
|
@@ -88,9 +89,18 @@ var rule = {
|
|
|
88
89
|
}
|
|
89
90
|
if (origin === "sanitizer-trusted") continue;
|
|
90
91
|
const confirmed = origin === "tainted-source";
|
|
92
|
+
const externalBypass = origin === "external-bypass";
|
|
91
93
|
const where = isHtmlSink ? `\`${nameNode.text}\` ch\xE8n HTML ch\u01B0a ki\u1EC3m so\xE1t v\xE0o DOM` : `\`${nameNode.text}\` tr\xEAn \`<${tag}>\` n\u1EA1p t\xE0i nguy\xEAn/URL c\xF3 th\u1EC3 ch\u1EE9a m\xE3`;
|
|
94
|
+
let message;
|
|
95
|
+
if (confirmed) {
|
|
96
|
+
message = `\u26D4 XSS qua template (\u0110\xC3 X\xC1C NH\u1EACN): ${where} \u2014 bi\u1EC3u th\u1EE9c \`${value}\` l\u1EA5y t\u1EEB input ng\u01B0\u1EDDi d\xF9ng trong component \`${link?.componentPath}\` m\xE0 ch\u01B0a sanitize.`;
|
|
97
|
+
} else if (externalBypass) {
|
|
98
|
+
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.`;
|
|
99
|
+
} else {
|
|
100
|
+
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.`;
|
|
101
|
+
}
|
|
92
102
|
findings.push({
|
|
93
|
-
message
|
|
103
|
+
message,
|
|
94
104
|
file: ctx.file.path,
|
|
95
105
|
range: {
|
|
96
106
|
line: attr.startPosition.row + 1,
|
|
@@ -100,7 +110,21 @@ var rule = {
|
|
|
100
110
|
// how `angular/no-dom-xss` reports confirmed flows on the `.ts` side);
|
|
101
111
|
// unresolved/unknown stays the structural `warning` @ baseConfidence 70.
|
|
102
112
|
...confirmed ? { severity: "error", confidence: 85 } : {},
|
|
103
|
-
|
|
113
|
+
// An external-bypass keeps the rule's `warning` severity and only lifts
|
|
114
|
+
// confidence to 80 — ADVISORY, not blocking, per [ADR-0031]'s principle
|
|
115
|
+
// that an UNCONFIRMED band inside a deterministic rule must not gate a
|
|
116
|
+
// merge ([ADR-0028]: a deterministic `error` ALWAYS gates, whatever its
|
|
117
|
+
// confidence). What is proven here is "the sanitizer was disabled on a
|
|
118
|
+
// value that crossed the component boundary" — NOT that the value is
|
|
119
|
+
// attacker-controlled, which is what `tainted-source` proves and what
|
|
120
|
+
// earns `error`. And the gate has a KNOWN unrecognised control class:
|
|
121
|
+
// a project-defined validator (`isTrustedResourceUrl(path)`, measured in
|
|
122
|
+
// [ADR-0060] §"A.3 probed") is a real defence this rule cannot yet see,
|
|
123
|
+
// so a CI-blocking verdict here would repeat the `spring/jdbc-template`
|
|
124
|
+
// mistake — an `error` that fails a build on a control the tool missed.
|
|
125
|
+
// Revisit `error` once validation-guard recognition lands.
|
|
126
|
+
...externalBypass ? { confidence: 80 } : {},
|
|
127
|
+
suggestion: externalBypass ? "\u0110\u1EEBng bypass gi\xE1 tr\u1ECB do n\u01A1i kh\xE1c truy\u1EC1n v\xE0o: d\xF9ng `DomSanitizer.sanitize(SecurityContext.HTML, x)`, ho\u1EB7c n\u1EBFu l\xE0 URL th\xEC ki\u1EC3m prefix/host b\u1EB1ng allowlist c\u1ED1 \u0111\u1ECBnh r\u1ED3i m\u1EDBi `bypassSecurityTrustResourceUrl` (ch\xEDnh codebase n\xE0y \u0111\xE3 l\xE0m \u0111\xFAng nh\u01B0 v\u1EADy trong c\xE1c pipe d\xF9ng chung)." : isHtmlSink ? "Sanitize tr\u01B0\u1EDBc khi bind (`DomSanitizer.sanitize(SecurityContext.HTML, x)` ho\u1EB7c pipe `| safeHtml`), ho\u1EB7c d\xF9ng text-binding `{{ }}` \u0111\u1EC3 Angular t\u1EF1 escape." : "Validate URL b\u1EB1ng allowlist host/scheme c\u1ED1 \u0111\u1ECBnh tr\u01B0\u1EDBc khi bind; tr\xE1nh n\u1EA1p `<iframe>`/`<script>` t\u1EEB gi\xE1 tr\u1ECB ng\u01B0\u1EDDi d\xF9ng nh\u1EADp."
|
|
104
128
|
});
|
|
105
129
|
}
|
|
106
130
|
return findings;
|
|
@@ -29,7 +29,8 @@ function attributeValue(attr) {
|
|
|
29
29
|
}
|
|
30
30
|
var rule = {
|
|
31
31
|
id: "angular/trackby-required",
|
|
32
|
-
|
|
32
|
+
// v2 (ADR-0065 calibration): conf 70→95 (đo 166/166 TP)
|
|
33
|
+
version: 2,
|
|
33
34
|
kind: "static-ts",
|
|
34
35
|
title: "`*ngFor` n\xEAn khai b\xE1o `trackBy` \u0111\u1EC3 tr\xE1nh re-render to\xE0n b\u1ED9 list",
|
|
35
36
|
description: "V\xF2ng l\u1EB7p `*ngFor` kh\xF4ng c\xF3 `trackBy` khi\u1EBFn Angular d\u1EF1ng l\u1EA1i to\xE0n b\u1ED9 DOM c\u1EE7a list m\u1ED7i khi array \u0111\u1ED5i tham chi\u1EBFu (r\u1EA5t ph\u1ED5 bi\u1EBFn v\u1EDBi `| async`, immutable state, refetch HTTP) thay v\xEC gi\u1EEF l\u1EA1i node c\u0169 \u2014 m\u1ED9t trong c\xE1c v\u1EA5n \u0111\u1EC1 perf th\u01B0\u1EDDng g\u1EB7p nh\u1EA5t. Th\xEAm `; trackBy: trackFn` (tr\u1EA3 v\u1EC1 id \u1ED5n \u0111\u1ECBnh c\u1EE7a item), ho\u1EB7c chuy\u1EC3n sang control-flow `@for (x of items; track x.id)` c\u1EE7a Angular 17+.",
|
|
@@ -38,7 +39,7 @@ var rule = {
|
|
|
38
39
|
languages: ["html"],
|
|
39
40
|
scope: "angular",
|
|
40
41
|
requires: "syntactic",
|
|
41
|
-
baseConfidence:
|
|
42
|
+
baseConfidence: 95,
|
|
42
43
|
check(ctx) {
|
|
43
44
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
44
45
|
const findings = [];
|