@code-sentinel-cli/code-sentinel-cli 4.0.2 → 4.0.3

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.
Files changed (31) hide show
  1. package/dist/bin.js +24115 -20069
  2. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +47 -8
  3. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -1
  4. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.prompt.md +128 -0
  5. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.rule.yaml +27 -0
  6. package/dist/builtin-rules/static/angular/sensitive-input-masking.rule.js +97 -0
  7. package/dist/builtin-rules/static/flutter/android-debug-certificate-risk.rule.js +140 -0
  8. package/dist/builtin-rules/static/flutter/android-minsdk-low.rule.js +108 -0
  9. package/dist/builtin-rules/static/general/dockerfile-dependency-confusion.rule.js +34 -0
  10. package/dist/builtin-rules/static/general/dockerfile-no-root-user.rule.js +37 -0
  11. package/dist/builtin-rules/static/general/html-password-autocomplete-off.rule.js +34 -0
  12. package/dist/builtin-rules/static/general/no-client-identity-header.rule.js +47 -0
  13. package/dist/builtin-rules/static/general/no-empty-encryption-key.rule.js +79 -0
  14. package/dist/builtin-rules/static/general/no-guessable-websql-database-name.rule.js +39 -0
  15. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +22 -3
  16. package/dist/builtin-rules/static/general/no-insecure-external-link.rule.js +52 -0
  17. package/dist/builtin-rules/static/general/no-insecure-password-submission.rule.js +75 -0
  18. package/dist/builtin-rules/static/general/no-reflective-access-override.rule.js +50 -0
  19. package/dist/builtin-rules/static/general/no-sensitive-string-materialization.rule.js +124 -0
  20. package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +65 -0
  21. package/dist/builtin-rules/static/general/sensitive-output-exposure.rule.js +30 -0
  22. package/dist/builtin-rules/static/spring-boot/mfa-enforcement-required.rule.js +110 -0
  23. package/dist/builtin-rules/static/spring-boot/no-cleartext-http-client.rule.js +53 -0
  24. package/dist/builtin-rules/static/spring-boot/no-devtools-in-production.rule.js +37 -0
  25. package/dist/builtin-rules/static/spring-boot/no-print-stack-trace.rule.js +71 -0
  26. package/dist/builtin-rules/static/spring-boot/no-sensitive-config-response.rule.js +53 -0
  27. package/dist/builtin-rules/static/spring-boot/no-weak-tls-protocol.rule.js +57 -0
  28. package/dist/builtin-rules/static/spring-boot/password-expiration-policy.rule.js +104 -0
  29. package/dist/index.js +24114 -20068
  30. package/node_modules/@code-sentinel/parsers/index.js +527 -6
  31. package/package.json +1 -1
@@ -1,25 +1,57 @@
1
1
  Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **ownership / tenant / account scope**.
2
2
 
3
+ ## DIEU KIEN TIEN QUYET — doc TRUOC moi thu khac
4
+
5
+ Rule nay chi bat **mot** thu: **luong nay LECH khoi quy uoc ma CHINH cluster nay dang ap dung o cho khac**.
6
+
7
+ Nghia la truoc khi emit bat ky finding nao, ban phai chi ra duoc **MOT ANH EM CU THE trong cluster
8
+ DANG enforce ranh gioi so huu** — va trich dan no trong `message`. Anh em hop le la mot trong:
9
+
10
+ - mot method/endpoint khac tren cung resource dung **scoped finder that su duoc GOI**
11
+ (`findByIdAndUserId(id, userId)`, `findByDirectiveIdAndUserId(...)`, `findAllByUserId(...)`);
12
+ - mot method/endpoint khac **so sanh voi principal** (`username.equals(entity.getCreatedBy())`,
13
+ `UserContextHolder`, `SecurityContextHolder`, `getCurrentUser`);
14
+ - mot endpoint anh em co **authorization theo INSTANCE** (`@VauthzCheck(..., instance = "id")`,
15
+ `@VauthzBulkCheck(..., instances = "...")`, `@PreAuthorize` co tham chieu object).
16
+
17
+ **KHONG tim duoc anh em nao dang enforce trong cluster ⇒ KHONG emit.** Khi ca resource khong he
18
+ bao ve gi, van de la **THIEU PHAN QUYEN**, va no thuoc `spring-boot/security-authorization-risk`,
19
+ khong thuoc rule nay. Hai loi do can hai cach sua khac nhau, nen bao o dung cho moi sua duoc.
20
+
21
+ Mot finder scoped **duoc KHAI ma khong noi nao GOI** (`findByIdAndCreatedBy` nam trong repository
22
+ nhung ca module khong ai dung) **KHONG phai anh em dang enforce** — no la ma chet, khong phai quy uoc
23
+ dang co hieu luc.
24
+
3
25
  ## CRITICAL RULES
4
26
 
5
27
  CRITICAL NON-VIOLATIONS:
6
28
 
7
29
  - NEVER report generic missing login/auth annotation. `spring-boot/security-authorization-risk` owns endpoint-level missing authorization.
8
30
  - NEVER report a scope gap when repository/service query already includes principal/user/account/tenant/owner/deleted scope.
31
+ - NEVER report a flow that is already protected **o tang khac cua cluster** — vi du service dung
32
+ `findById` tran nhung endpoint goi no co `@VauthzCheck(..., instance = "id")`. Neu cluster khong
33
+ cho thay controller cua luong do, ban KHONG BIET no co duoc bao ve hay khong ⇒ khong emit.
9
34
  - NEVER report a DTO validation issue, SQL concat, transaction placement, raw exception response, SSRF, or filesystem issue.
10
35
  - 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
36
  - 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
37
 
13
38
  1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan convention ngoai cluster.
14
- 2. **`line` BAT BUOC tro ve PRIMARY controller file**. Neu bug nam trong service/repository, dung dong controller goi flow do.
15
- 3. **Confidence `<50` -> KHONG emit**.
39
+ 2. **`line` BAT BUOC tro ve dong THAT trong PRIMARY, va phai la dong CO MA** — dong khai endpoint,
40
+ dong goi service, hoac dong truy cap du lieu khong scoped. **TUYET DOI khong tro vao dong trong,
41
+ dong dong ngoac, comment, hay mot so dong vuot qua do dai file.** Neu bug nam trong service/repository
42
+ ma PRIMARY la controller, dung dong controller goi flow do.
43
+ 3. **Neu PRIMARY khong phai controller va cluster khong lam ro endpoint nao dan toi luong nay** —
44
+ emit `{"violations": []}`. Bia mot toa do de thoa man dinh dang la loi nang hon bo sot.
45
+ 4. **Confidence `<50` -> KHONG emit**.
16
46
 
17
47
  ## ONLY REPORT WHEN co ownership/scope bug cu the
18
48
 
49
+ Tat ca deu phai thoa **DIEU KIEN TIEN QUYET** o tren (co anh em dang enforce, va ban trich dan duoc no).
50
+
19
51
  - Controller nhan `id`, `accountId`, `tenantId`, `ownerId`, `userId`, `documentId`, `ticketId`, `invoiceId`, `orderId`, hoac list id tu request, roi service/repository load/update/delete/approve/assign/refund chi theo id.
20
52
  - Entity/support file cho thay boundary nhu `ownerId`, `tenantId`, `accountId`, `createdBy`, `uploadedBy`, `assignee`, `approver`, `departmentId`, `deleted`, `deletedAt`, `isDeleted`.
21
53
  - Parent-child flow dung parent id tu path/body de tao child ma khong chung minh parent thuoc current user/tenant/account.
22
- - Bulk operation nhan list id va update/delete tung record ma khong scope tung id theo tenant/account/owner.
54
+ - Bulk operation nhan list id va update/delete tung record ma khong scope tung id theo tenant/account/owner — **dac biet khi endpoint don le tuong ung CO instance-scoped check con ban bulk thi khong**.
23
55
  - Delete flow goi `deleteById`/hard delete trong khi entity co owner/tenant hoac soft-delete field, khong co owner/tenant/deleted check.
24
56
 
25
57
  ## KHONG flag
@@ -29,7 +61,7 @@ CRITICAL NON-VIOLATIONS:
29
61
  - 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
62
  - Luong DTO an toan, hoac file support-only (global exception handler, mapper, config) neu khong co direct unsafe scoped data access trong PRIMARY.
31
63
  - Endpoint public-safe/doc lookup khong co sensitive domain boundary trong cluster.
32
- - Thieu auth chung chung; chi flag neu co data ownership/scope gap rieng.
64
+ - Thieu auth chung chung; chi flag neu co data ownership/scope gap rieng **va cluster co anh em dang enforce**.
33
65
  - Style/naming/refactor suggestion.
34
66
 
35
67
  ## Primary file
@@ -59,9 +91,9 @@ Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo sch
59
91
  {
60
92
  "violations": [
61
93
  {
62
- "line": <so nguyen duong, 1-based, trong PRIMARY>,
94
+ "line": <so nguyen duong, 1-based, tro vao mot dong CO MA trong PRIMARY>,
63
95
  "endLine": <so nguyen duong | null>,
64
- "message": "<≤200 ký tự, tiếng Việt có dấu, nêu luồng controller/service và phạm vi sở hữu còn thiếu>",
96
+ "message": "<≤200 ký tự, tiếng Việt có dấu. BẮT BUỘC nêu tên anh em đang enforce trong cluster (method/endpoint + cơ chế), rồi nêu luồng này thiếu gì.>",
65
97
  "suggestion": "<gợi ý sửa lỗi bằng tiếng Việt có dấu | null>",
66
98
  "confidence": <so nguyen 0-100>
67
99
  }
@@ -69,11 +101,18 @@ Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo sch
69
101
  }
70
102
  ```
71
103
 
72
- Neu khong co ownership/scope bug ro rang: `{"violations": []}`.
104
+ Vi du hinh dang `message` dung: *"`DELETE /{id}` có `@VauthzCheck(XOA, instance=\"id\")` nhưng
105
+ `DELETE /batch` nhận list id và xoá từng bản ghi không kiểm chủ sở hữu."*
106
+
107
+ Neu khong co ownership/scope bug ro rang, **hoac khong tim duoc anh em dang enforce**:
108
+ `{"violations": []}`.
73
109
 
74
110
  ## REPEAT CRITICAL RULES
75
111
 
76
- - `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
112
+ - **Khong trich dan duoc mot anh em DANG enforce trong cluster ⇒ khong emit.** Ca resource khong co bao ve nao la viec cua `security-authorization-risk`.
113
+ - **Finder scoped duoc KHAI ma khong ai GOI khong phai bang chung** — do la ma chet.
114
+ - `line` phai tro vao dong CO MA trong PRIMARY; khong bia toa do, khong tro vao dong trong hay ngoai pham vi file.
115
+ - PRIMARY khong phai controller va khong ro endpoint dan toi luong ⇒ `{"violations": []}`.
77
116
  - Khong flag generic missing auth; chi flag owner/tenant/account/deleted scope gap co evidence.
78
117
  - Khong flag list/findAll/pagination/unbounded collection; rule nay chi bat object-level owner/tenant/account scope gap.
79
118
  - Khong flag file support-only (global exception handler, DTO, luong an toan) tru khi PRIMARY co direct unsafe data access evidence.
@@ -1,5 +1,5 @@
1
1
  id: spring-boot/ownership-scope-risk
2
- version: 4
2
+ version: 5
3
3
  kind: ai
4
4
  title: "Spring Boot ownership/tenant scope flow co rui ro khong?"
5
5
  description: |
@@ -0,0 +1,128 @@
1
+ Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **guard TRANG THAI NGUON khi chuyen trang thai**.
2
+
3
+ ## DIEU KIEN TIEN QUYET — doc TRUOC moi thu khac
4
+
5
+ Rule nay bat DUNG MOT hinh dang:
6
+
7
+ > mot method **NAP** thuc the tu storage, **GHI mot trang thai HANG** len no, va **KHONG he doc
8
+ > trang thai NO DANG O**.
9
+
10
+ Truoc khi emit bat ky finding nao, ban phai chi ra duoc **CA BA** thu sau va trich dan trong `message`:
11
+
12
+ 1. **Cho NAP** — `findById` / `findAllById` / `findOne` / `getById` / `findByIdAnd…` trong chinh method do.
13
+ Khong co no thi day la GAN trang thai KHOI TAO cho object moi, khong phai chuyen trang thai.
14
+ 2. **Dich HANG** — `Status.SENT`, `"APPROVED"`, … Neu dich den tu REQUEST thi **KHONG phai rule nay**
15
+ (xem NON-VIOLATIONS).
16
+ 3. **May trang thai** — it nhat **HAI** dich khac nhau ghi qua cung kieu enum do, thay duoc trong cluster
17
+ (`NotificationStatus.DRAFT` / `.SCHEDULED` / `.SENT`). Mot enum chi co MOT dich la co truong danh dau,
18
+ khong phai may trang thai, va thieu guard o do thuong vo hai.
19
+
20
+ **Thieu bat ky thu nao trong ba ⇒ KHONG emit.**
21
+
22
+ ## VA MOT CAU HOI NUA — thieu guard KHONG dong nghia CO LOI
23
+
24
+ Day la phan can phan doan, va la ly do rule nay o tang AI thay vi mot rule tinh. Sau khi ba dieu
25
+ kien tren thoa, hoi tiep: **lap lai hoac nhay coc chuyen trang thai nay co HAU QUA NGHIEP VU khong?**
26
+
27
+ **CO hau qua — BAO** (vi du that):
28
+ - gui/phat lai cai da gui (`setStatus(SENT)` khong kiem da SENT chua ⇒ gui trung, nhay thang
29
+ `DRAFT -> SENT` bo qua `SCHEDULED`);
30
+ - duyet/tu choi lai cai da duyet, hoac duyet cai da bi HUY;
31
+ - huy/hoan cai da HOAN THANH;
32
+ - thanh toan/xuat kho/cap phat lai cai da thuc hien.
33
+
34
+ **KHONG hau qua — DUNG BAO** (vi du that):
35
+ - xoa mem cai da xoa mem (`setStatus(DELETED)`) — idempotent, ghi de cung gia tri;
36
+ - danh dau da doc / da xem lai;
37
+ - dong bo lai mot ban ghi ve dung trang thai nguon du lieu ngoai.
38
+
39
+ Neu ban khong chac hau qua la gi, **confidence phai duoi 85** va `message` phai noi ro dieu do.
40
+
41
+ ## CRITICAL RULES
42
+
43
+ CRITICAL NON-VIOLATIONS:
44
+
45
+ - NEVER report a transition whose TARGET comes from request/external input. `spring-boot/business-invariant-risk` owns that, va hai rule KHONG duoc trung nhau: dich HANG thi khong the la dich tu request.
46
+ - NEVER report missing authorization or a missing login check. `spring-boot/security-authorization-risk` owns endpoint-level authorization.
47
+ - NEVER report a missing owner/tenant check. `spring-boot/ownership-scope-risk` owns object-level ownership scope. Mot method co the thieu CA HAI — ban chi bao phan trang thai.
48
+ - NEVER report an INITIAL state on an object the method just created (`new Foo()` / `mapper.toEntity(dto)` roi `setStatus(...)`). Khong co trang thai nguon thi khong the thieu guard cho no.
49
+ - NEVER report a method that is not reachable from a request — scheduler (`@Scheduled`), message consumer (`@KafkaListener`, `@RabbitListener`), migration/sync job. Hinh dang SR 26 la endpoint, khong phai job noi bo.
50
+ - NEVER report a DTO/mapping/validation/transaction/SQL/pagination issue.
51
+
52
+ 1. **CHI report khi co bang chung trong PRIMARY hoac support files.** Khong doan convention ngoai cluster.
53
+ 2. **`line` BAT BUOC tro vao mot dong CO MA trong PRIMARY** — dong `setStatus(...)`, dong khai endpoint, hoac dong goi service. **TUYET DOI khong tro vao dong trong, dong dong ngoac, comment, hay mot so dong vuot qua do dai file.**
54
+ 3. **PRIMARY khong phai controller va cluster khong lam ro endpoint nao dan toi luong nay** ⇒ emit `{"violations": []}`. Bia mot toa do de thoa man dinh dang la loi nang hon bo sot.
55
+ 4. **Confidence `<50` -> KHONG emit**.
56
+
57
+ ## ONLY REPORT WHEN
58
+
59
+ Tat ca deu phai thoa DIEU KIEN TIEN QUYET (nap + dich hang + may trang thai) VA cau hoi hau qua o tren.
60
+
61
+ - Endpoint nhan `id` tu request, service nap thuc the roi `setStatus(<HANG>)` va luu, khong doc `getStatus()` / so sanh trang thai / `switch` tren trang thai o bat ky dau trong method.
62
+ - Bulk: nhan list id, nap nhieu ban ghi roi dat cung mot trang thai cho tat ca, khong loc theo trang thai hien tai — va lap lai co hau qua.
63
+ - Mot method anh em cung cluster **CO** kiem trang thai nguon truoc khi chuyen (vi du `if (x.getStatus() != PENDING) throw ...`) con method nay thi khong. Neu thay duoc anh em do, **NEU TEN NO** trong `message`: day la bang chung manh nhat, vi no cho thay chinh codebase coi phep kiem la can thiet.
64
+
65
+ ## KHONG flag
66
+
67
+ - Gan trang thai khoi tao cho object moi tao.
68
+ - Chuyen trang thai idempotent/khong hau qua (xem muc tren).
69
+ - Method co doc trang thai nguon o bat ky dau — `getStatus()`, `isActive()`, `status ==`, `status.equals(...)`, `switch (x.getStatus())` — ke ca khi phep kiem do o nhanh khac.
70
+ - Luong co `@Version` / optimistic locking / `UPDATE ... WHERE status = ?` lam guard o tang SQL.
71
+ - Enum trang thai chi co mot dich duy nhat trong cluster (truong danh dau, khong phai may trang thai).
72
+ - Style/naming/refactor suggestion.
73
+
74
+ ## Primary file
75
+
76
+ File: `{{file}}`
77
+ Language: `{{language}}`
78
+
79
+ ```{{language}}
80
+ {{code}}
81
+ ```
82
+
83
+ ## Support files cung cluster
84
+
85
+ Chi dung support files lam bang chung neu lien quan den PRIMARY.
86
+
87
+ ```
88
+ {{cluster_files}}
89
+ ```
90
+
91
+ {{cluster_summary}}
92
+
93
+ ## Output yeu cau
94
+
95
+ Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
96
+
97
+ ```
98
+ {
99
+ "violations": [
100
+ {
101
+ "line": <so nguyen duong, 1-based, tro vao mot dong CO MA trong PRIMARY>,
102
+ "endLine": <so nguyen duong | null>,
103
+ "message": "<≤200 ký tự, tiếng Việt có dấu. BẮT BUỘC nêu: chỗ NẠP, đích HẰNG, và ít nhất hai đích của cùng enum đó (hoặc tên method anh em có kiểm). Rồi nêu hậu quả nghiệp vụ khi lặp/nhảy cóc.>",
104
+ "suggestion": "<gợi ý sửa lỗi bằng tiếng Việt có dấu | null>",
105
+ "confidence": <so nguyen 0-100>
106
+ }
107
+ ]
108
+ }
109
+ ```
110
+
111
+ Vi du hinh dang `message` dung: *"`sendNotification` nạp bằng `findById(id)` rồi
112
+ `setStatus(NotificationStatus.SENT)` mà không đọc trạng thái hiện tại; enum có `DRAFT`/`SCHEDULED`/`SENT`,
113
+ nên bản đã `SENT` gửi lại được và bản `DRAFT` nhảy thẳng qua `SCHEDULED`."*
114
+
115
+ Neu khong co vi pham ro rang, **hoac khong trich dan du ba bang chung**, hoac lap lai chuyen trang thai
116
+ do la vo hai: `{"violations": []}`.
117
+
118
+ ## REPEAT CRITICAL RULES
119
+
120
+ - **Khong trich dan du chỗ NẠP + đích HẰNG + hai đích của cùng enum ⇒ khong emit.**
121
+ - **Dich den tu REQUEST khong phai viec cua rule nay** — do la `business-invariant-risk`.
122
+ - **Thieu phan quyen / thieu kiem chu so huu khong phai viec cua rule nay** — do la `security-authorization-risk` / `ownership-scope-risk`.
123
+ - Gan trang thai KHOI TAO cho object moi khong phai chuyen trang thai.
124
+ - Lap lai ma khong co hau qua nghiep vu (xoa mem, danh dau da doc) ⇒ khong emit.
125
+ - `line` phai tro vao dong CO MA trong PRIMARY; khong bia toa do.
126
+ - Confidence `<50` -> KHONG emit.
127
+
128
+ Khong giai thich. JSON thuan.
@@ -0,0 +1,27 @@
1
+ id: spring-boot/state-transition-guard-risk
2
+ version: 1
3
+ kind: ai
4
+ title: "Spring Boot chuyen trang thai co thieu guard trang thai NGUON khong?"
5
+ description: |
6
+ Per-cluster AI rule for the shape `business-invariant-risk` v3 excludes on
7
+ purpose ([ADR-0077]): a method LOADS an entity from storage, writes a
8
+ CONSTANT state onto it, and never reads the state it is coming FROM. That is
9
+ the defect that failed SR 26 - the transition target is server-driven, so v3
10
+ is silent, while re-firing or skipping a state has a real business effect
11
+ (re-send, re-approve, cancel after completion).
12
+ severity: warning
13
+ category: backend-invariant
14
+ languages: [java]
15
+ scope: spring-boot
16
+ baseConfidence: 60
17
+ prompt: ./state-transition-guard-risk.prompt.md
18
+ contextScope: per-cluster
19
+ aiConfig:
20
+ tier: regular
21
+ prRouting:
22
+ group: spring-data-consistency-group
23
+ targetLayers: [controller, service, repository]
24
+ triggers:
25
+ ["setStatus", "setState", "status", "approve", "reject", "cancel", "send", "confirm", "complete"]
26
+ riskWeight: 5
27
+ requiresContext: [diff, primaryFile, relatedController, relatedService, relatedRepository]
@@ -0,0 +1,97 @@
1
+ import { asTreeSitterTree } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/angular/sensitive-input-masking.rule.ts
4
+ var SENSITIVE_IDENTITY_ATTRS = /* @__PURE__ */ new Set(["name", "id", "formcontrolname"]);
5
+ var VISIBLE_TEXT_TYPES = /* @__PURE__ */ new Set(["text", "search", "email", "url", "tel"]);
6
+ var PASSWORD_NAME_RE = /(?:password|passwd|pwd|matkhau)/i;
7
+ var NON_SECRET_NAME_RE = /(?:passwordhash|passwordencoded|passwordpolicy|passwordchange(?:d)?|passwordreset(?:token)?|passwordstrength|passwordhint|passwordencoder)/i;
8
+ function* walk(node) {
9
+ const stack = [node];
10
+ while (stack.length > 0) {
11
+ const current = stack.pop();
12
+ if (!current) continue;
13
+ yield current;
14
+ for (let index = current.namedChildCount - 1; index >= 0; index--) {
15
+ const child = current.namedChild(index);
16
+ if (child) stack.push(child);
17
+ }
18
+ }
19
+ }
20
+ var childOfType = (node, type) => {
21
+ for (let index = 0; index < node.namedChildCount; index++) {
22
+ const child = node.namedChild(index);
23
+ if (child?.type === type) return child;
24
+ }
25
+ return null;
26
+ };
27
+ var normalizeAttrName = (name) => {
28
+ let normalized = name;
29
+ const bracket = /^\[(.+)\]$/.exec(normalized);
30
+ if (bracket?.[1]) normalized = bracket[1];
31
+ else if (normalized.startsWith("bind-")) normalized = normalized.slice("bind-".length);
32
+ return normalized.replace(/^attr\./i, "").toLowerCase();
33
+ };
34
+ var attributeValue = (attribute) => {
35
+ const quoted = childOfType(attribute, "quoted_attribute_value");
36
+ return childOfType(quoted ?? attribute, "attribute_value")?.text ?? "";
37
+ };
38
+ var staticValue = (value) => {
39
+ const trimmed = value.trim();
40
+ const quoted = /^(?:'([^']*)'|"([^"]*)")$/.exec(trimmed);
41
+ if (quoted) return (quoted[1] ?? quoted[2] ?? "").toLowerCase();
42
+ return /^[A-Za-z][A-Za-z0-9-]*$/.test(trimmed) ? trimmed.toLowerCase() : null;
43
+ };
44
+ var inputAttributes = (tag) => {
45
+ let type = null;
46
+ let sensitiveIdentity = null;
47
+ for (let index = 0; index < tag.namedChildCount; index++) {
48
+ const child = tag.namedChild(index);
49
+ if (child?.type !== "attribute") continue;
50
+ const name = childOfType(child, "attribute_name");
51
+ if (!name) continue;
52
+ const attributeName = normalizeAttrName(name.text);
53
+ const value = staticValue(attributeValue(child));
54
+ if (attributeName === "type") type = value;
55
+ if (value && SENSITIVE_IDENTITY_ATTRS.has(attributeName) && PASSWORD_NAME_RE.test(value) && !NON_SECRET_NAME_RE.test(value)) {
56
+ sensitiveIdentity = value;
57
+ }
58
+ }
59
+ return { type, sensitiveIdentity };
60
+ };
61
+ var isInputTag = (tag) => childOfType(tag, "tag_name")?.text.toLowerCase() === "input";
62
+ var rule = {
63
+ id: "angular/sensitive-input-masking",
64
+ version: 1,
65
+ kind: "static-ts",
66
+ title: '\xD4 nh\u1EADp m\u1EADt kh\u1EA9u ph\u1EA3i d\xF9ng type="password"',
67
+ description: "Ph\xE1t hi\u1EC7n input c\xF3 name/id/formControlName mang ngh\u0129a m\u1EADt kh\u1EA9u nh\u01B0ng d\xF9ng type text/visible ho\u1EB7c b\u1ECF type (m\u1EB7c \u0111\u1ECBnh l\xE0 text), khi\u1EBFn m\u1EADt kh\u1EA9u b\u1ECB l\u1ED9 tr\xEAn m\xE0n h\xECnh (Fortify Privacy Violation: Shoulder Surfing).",
68
+ severity: "warning",
69
+ category: "security",
70
+ languages: ["html"],
71
+ scope: "angular",
72
+ requires: "syntactic",
73
+ baseConfidence: 90,
74
+ check(ctx) {
75
+ const tree = asTreeSitterTree(ctx.parsed);
76
+ const findings = [];
77
+ for (const tag of walk(tree.rootNode)) {
78
+ if (tag.type !== "start_tag" && tag.type !== "self_closing_tag") continue;
79
+ if (!isInputTag(tag)) continue;
80
+ const { type, sensitiveIdentity } = inputAttributes(tag);
81
+ if (!sensitiveIdentity) continue;
82
+ if (type !== null && !VISIBLE_TEXT_TYPES.has(type)) continue;
83
+ findings.push({
84
+ file: ctx.file.path,
85
+ range: { line: tag.startPosition.row + 1, column: tag.startPosition.column + 1 },
86
+ confidence: 90,
87
+ message: "\xD4 nh\u1EADp m\u1EADt kh\u1EA9u \u0111ang hi\u1EC3n th\u1ECB d\u1EA1ng text \u2014 ng\u01B0\u1EDDi \u0111\u1EE9ng g\u1EA7n c\xF3 th\u1EC3 nh\xECn th\u1EA5y gi\xE1 tr\u1ECB (Privacy Violation: Shoulder Surfing).",
88
+ suggestion: '\u0110\u1EB7t `type="password"` (ho\u1EB7c binding c\u1ED1 \u0111\u1ECBnh `[type]="\'password\'"`) cho \xF4 m\u1EADt kh\u1EA9u; kh\xF4ng d\xF9ng type text ho\u1EB7c b\u1ECF thu\u1ED9c t\xEDnh type.'
89
+ });
90
+ }
91
+ return findings;
92
+ }
93
+ };
94
+
95
+ export { rule };
96
+ //# sourceMappingURL=sensitive-input-masking.rule.js.map
97
+ //# sourceMappingURL=sensitive-input-masking.rule.js.map
@@ -0,0 +1,140 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var isPath = (file, suffix) => file.path.replace(/\\/g, "/").toLowerCase().endsWith(suffix.toLowerCase());
24
+
25
+ // builtin-rules/static/flutter/android-debug-certificate-risk.rule.ts
26
+ var rule = {
27
+ id: "flutter/android-debug-certificate-risk",
28
+ version: 1,
29
+ kind: "static-ts",
30
+ title: "C\u1EA5u h\xECnh k\xFD \u1EE9ng d\u1EE5ng release b\u1EB1ng ch\u1EE9ng th\u01B0 debug",
31
+ description: "Ph\xE1t hi\u1EC7n c\u1EA5u h\xECnh release build s\u1EED d\u1EE5ng debug certificate ho\u1EB7c keystore debug (signingConfigs.debug, debug.keystore, androiddebugkey).",
32
+ severity: "error",
33
+ category: "mobile-security",
34
+ languages: ["text", "kotlin"],
35
+ scope: "flutter",
36
+ requires: "text",
37
+ baseConfidence: 92,
38
+ check(ctx) {
39
+ const file = ctx.file;
40
+ const content = file.content;
41
+ const out = [];
42
+ if (!isPath(file, "build.gradle") && !isPath(file, "build.gradle.kts") && !isPath(file, "app/build.gradle") && !isPath(file, "app/build.gradle.kts")) {
43
+ return out;
44
+ }
45
+ const lines = content.split(/\r?\n/);
46
+ let inReleaseBlock = false;
47
+ let blockBraceCount = 0;
48
+ let inBuildTypes = false;
49
+ let inSigningConfigs = false;
50
+ let releaseBlockType = null;
51
+ let hasReportedCurrentBlock = false;
52
+ let offset = 0;
53
+ for (let i = 0; i < lines.length; i += 1) {
54
+ const line = lines[i] ?? "";
55
+ const trimmed = line.trim();
56
+ if (/(?:buildTypes\.(?:release|getByName\(["']release["']\))\.signingConfig\s*=?\s*signingConfigs\.(?:debug|getByName\(["']debug["']\)))/i.test(
57
+ trimmed
58
+ )) {
59
+ out.push(
60
+ finding(
61
+ file,
62
+ offset,
63
+ "C\u1EA5u h\xECnh release build \u0111ang s\u1EED d\u1EE5ng debug signing config (`signingConfigs.debug`).",
64
+ "Khai b\xE1o signingConfig ri\xEAng cho release v\u1EDBi ch\u1EE9ng th\u01B0 b\u1EA3o m\u1EADt ch\xEDnh th\u1EE9c, kh\xF4ng d\xF9ng debug signing cho b\u1EA3n release.",
65
+ {
66
+ severity: "error",
67
+ confidence: 95,
68
+ snippet: trimmed
69
+ }
70
+ )
71
+ );
72
+ }
73
+ if (/\bbuildTypes\s*\{/.test(trimmed)) {
74
+ inBuildTypes = true;
75
+ }
76
+ if (/\bsigningConfigs\s*\{/.test(trimmed)) {
77
+ inSigningConfigs = true;
78
+ }
79
+ if (/\b(?:release|(?:create|getByName|named|register)\(["']release["']\))\s*\{/.test(trimmed)) {
80
+ inReleaseBlock = true;
81
+ hasReportedCurrentBlock = false;
82
+ blockBraceCount = 0;
83
+ releaseBlockType = inBuildTypes ? "buildType" : inSigningConfigs ? "signingConfig" : "buildType";
84
+ }
85
+ if (inReleaseBlock) {
86
+ const openBraces = (line.match(/\{/g) || []).length;
87
+ const closeBraces = (line.match(/\}/g) || []).length;
88
+ blockBraceCount += openBraces - closeBraces;
89
+ if (releaseBlockType === "buildType" && !hasReportedCurrentBlock) {
90
+ if (/signingConfig\s*=?\s*signingConfigs\.(?:debug|getByName\(["']debug["']\))/i.test(
91
+ trimmed
92
+ )) {
93
+ hasReportedCurrentBlock = true;
94
+ out.push(
95
+ finding(
96
+ file,
97
+ offset,
98
+ "C\u1EA5u h\xECnh release build \u0111ang s\u1EED d\u1EE5ng debug signing config (`signingConfigs.debug`).",
99
+ "Khai b\xE1o signingConfig ri\xEAng cho release v\u1EDBi ch\u1EE9ng th\u01B0 b\u1EA3o m\u1EADt ch\xEDnh th\u1EE9c, kh\xF4ng d\xF9ng debug signing cho b\u1EA3n release.",
100
+ {
101
+ severity: "error",
102
+ confidence: 95,
103
+ snippet: trimmed
104
+ }
105
+ )
106
+ );
107
+ }
108
+ }
109
+ if (releaseBlockType === "signingConfig" && !hasReportedCurrentBlock) {
110
+ if (/storeFile\s*=?\s*file\([^)]*debug\.keystore[^)]*\)/i.test(trimmed) || /keyAlias\s*=?\s*["']androiddebugkey["']/i.test(trimmed) || /(?:storePassword|keyPassword)\s*=?\s*["']android["']/i.test(trimmed)) {
111
+ hasReportedCurrentBlock = true;
112
+ out.push(
113
+ finding(
114
+ file,
115
+ offset,
116
+ `Khai b\xE1o release signing config s\u1EED d\u1EE5ng th\xF4ng tin debug keystore: \`${trimmed}\`.`,
117
+ "S\u1EED d\u1EE5ng ch\u1EE9ng th\u01B0 k\xFD release \u0111\u1ED9c l\u1EADp v\xE0 n\u1EA1p th\xF4ng tin m\u1EADt qua bi\u1EBFn m\xF4i tr\u01B0\u1EDDng ho\u1EB7c file thu\u1ED9c t\xEDnh b\u1EA3o m\u1EADt.",
118
+ {
119
+ severity: "error",
120
+ confidence: 92,
121
+ snippet: trimmed
122
+ }
123
+ )
124
+ );
125
+ }
126
+ }
127
+ if (blockBraceCount <= 0 && (openBraces > 0 || closeBraces > 0)) {
128
+ inReleaseBlock = false;
129
+ releaseBlockType = null;
130
+ }
131
+ }
132
+ offset += line.length + 1;
133
+ }
134
+ return out;
135
+ }
136
+ };
137
+
138
+ export { rule };
139
+ //# sourceMappingURL=android-debug-certificate-risk.rule.js.map
140
+ //# sourceMappingURL=android-debug-certificate-risk.rule.js.map
@@ -0,0 +1,108 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var attrValue = (xml, attr) => {
24
+ const escaped = attr.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
25
+ return new RegExp(`${escaped}\\s*=\\s*["']([^"']+)["']`).exec(xml)?.[1] ?? null;
26
+ };
27
+ var isPath = (file, suffix) => file.path.replace(/\\/g, "/").toLowerCase().endsWith(suffix.toLowerCase());
28
+
29
+ // builtin-rules/static/flutter/android-minsdk-low.rule.ts
30
+ var DEFAULT_MIN_SDK_THRESHOLD = 26;
31
+ var rule = {
32
+ id: "flutter/android-minsdk-low",
33
+ version: 1,
34
+ kind: "static-ts",
35
+ title: "Android minSdkVersion qu\xE1 th\u1EA5p so v\u1EDBi ng\u01B0\u1EE1ng b\u1EA3o m\u1EADt",
36
+ description: "Ph\xE1t hi\u1EC7n minSdkVersion < 26 trong build.gradle ho\u1EB7c AndroidManifest, cho ph\xE9p \u1EE9ng d\u1EE5ng c\xE0i \u0111\u1EB7t tr\xEAn c\xE1c phi\xEAn b\u1EA3n Android c\u0169 ch\u01B0a \u0111\u01B0\u1EE3c v\xE1 b\u1EA3o m\u1EADt.",
37
+ severity: "warning",
38
+ category: "mobile-security",
39
+ languages: ["text", "kotlin", "xml"],
40
+ scope: "flutter",
41
+ requires: "text",
42
+ baseConfidence: 88,
43
+ defaultOptions: {
44
+ minSdkThreshold: DEFAULT_MIN_SDK_THRESHOLD
45
+ },
46
+ check(ctx) {
47
+ const file = ctx.file;
48
+ const content = file.content;
49
+ const threshold = Number(ctx.options.minSdkThreshold ?? DEFAULT_MIN_SDK_THRESHOLD);
50
+ const out = [];
51
+ if (isPath(file, "build.gradle") || isPath(file, "build.gradle.kts") || isPath(file, "app/build.gradle") || isPath(file, "app/build.gradle.kts")) {
52
+ const regex = /\b(?:minSdkVersion|minSdk)\s*(?:=|\s)\s*([0-9]+)\b/g;
53
+ let match = regex.exec(content);
54
+ while (match !== null) {
55
+ const valStr = match[1];
56
+ if (valStr) {
57
+ const val = Number.parseInt(valStr, 10);
58
+ if (val < threshold) {
59
+ out.push(
60
+ finding(
61
+ file,
62
+ match.index,
63
+ `Android \`${match[0].trim()}\` th\u1EA5p h\u01A1n ng\u01B0\u1EE1ng an to\xE0n khuy\u1EBFn ngh\u1ECB (${threshold}).`,
64
+ `N\xE2ng \`minSdkVersion\` l\xEAn t\u1ED1i thi\u1EC3u ${threshold} (Android 8.0 Oreo+) \u0111\u1EC3 \u0111\u1EA3m b\u1EA3o thi\u1EBFt b\u1ECB nh\u1EADn \u0111\u01B0\u1EE3c c\xE1c b\u1EA3n v\xE1 b\u1EA3o m\u1EADt h\u1EC7 \u0111i\u1EC1u h\xE0nh.`,
65
+ {
66
+ severity: val < 24 ? "error" : "warning",
67
+ confidence: 90,
68
+ snippet: match[0].trim()
69
+ }
70
+ )
71
+ );
72
+ }
73
+ }
74
+ match = regex.exec(content);
75
+ }
76
+ }
77
+ if (isPath(file, "androidmanifest.xml")) {
78
+ const usesSdkMatch = /<uses-sdk\b[\s\S]*?>/i.exec(content);
79
+ if (usesSdkMatch) {
80
+ const tag = usesSdkMatch[0];
81
+ const minSdkVal = attrValue(tag, "android:minSdkVersion");
82
+ if (minSdkVal && /^[0-9]+$/.test(minSdkVal)) {
83
+ const val = Number.parseInt(minSdkVal, 10);
84
+ if (val < threshold) {
85
+ out.push(
86
+ finding(
87
+ file,
88
+ usesSdkMatch.index,
89
+ `AndroidManifest khai b\xE1o \`android:minSdkVersion="${minSdkVal}"\` th\u1EA5p h\u01A1n ng\u01B0\u1EE1ng an to\xE0n (${threshold}).`,
90
+ `N\xE2ng \`android:minSdkVersion\` l\xEAn t\u1ED1i thi\u1EC3u ${threshold} trong AndroidManifest ho\u1EB7c c\u1EA5u h\xECnh \`defaultConfig\` c\u1EE7a Gradle.`,
91
+ {
92
+ severity: val < 24 ? "error" : "warning",
93
+ confidence: 90,
94
+ snippet: tag.trim()
95
+ }
96
+ )
97
+ );
98
+ }
99
+ }
100
+ }
101
+ }
102
+ return out;
103
+ }
104
+ };
105
+
106
+ export { rule };
107
+ //# sourceMappingURL=android-minsdk-low.rule.js.map
108
+ //# sourceMappingURL=android-minsdk-low.rule.js.map
@@ -0,0 +1,34 @@
1
+ import { DOCKERFILE_RE, auditDockerfileDependencyConfusion } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/dockerfile-dependency-confusion.rule.ts
4
+ var rule = {
5
+ id: "general/dockerfile-dependency-confusion",
6
+ version: 2,
7
+ kind: "static-ts",
8
+ title: "Ng\u0103n ch\u1EB7n Dependency Confusion & Insecure Package Registry trong Dockerfile (CWE-427/CWE-829)",
9
+ description: "Ph\xE1t hi\u1EC7n c\u1EA5u h\xECnh package manager kh\xF4ng an to\xE0n trong Dockerfile (nh\u01B0 `pip install --extra-index-url`, `--trusted-host`, ho\u1EB7c c\u1EA5u h\xECnh registry qua HTTP cleartext) d\u1EABn \u0111\u1EBFn nguy c\u01A1 Dependency Confusion, Package Squatting ho\u1EB7c Man-in-the-Middle.",
10
+ severity: "error",
11
+ category: "security",
12
+ languages: ["text"],
13
+ scope: "general",
14
+ requires: "text",
15
+ usesParser: false,
16
+ baseConfidence: 90,
17
+ check(ctx) {
18
+ const file = ctx.file;
19
+ if (!DOCKERFILE_RE.test(file.path)) return [];
20
+ const hits = auditDockerfileDependencyConfusion(file.content, file.path);
21
+ return hits.map((h) => ({
22
+ message: h.reason,
23
+ file: file.path,
24
+ range: { line: h.line, column: 1 },
25
+ severity: "error",
26
+ confidence: 90,
27
+ suggestion: h.reason.includes("--extra-index-url") ? "Ch\u1EC9 s\u1EED d\u1EE5ng `--index-url` tr\u1ECF t\u1EDBi kho n\u1ED9i b\u1ED9 (artifact proxy) \u0111\xE3 \u0111\u01B0\u1EE3c b\u1EA3o v\u1EC7, ho\u1EB7c s\u1EED d\u1EE5ng c\u01A1 ch\u1EBF hash-pinning (`--require-hashes`)." : h.reason.includes("--trusted-host") ? "Cung c\u1EA5p ch\u1EE9ng ch\u1EC9 CA n\u1ED9i b\u1ED9 h\u1EE3p l\u1EC7 cho h\u1EC7 \u0111i\u1EC1u h\xE0nh/container thay v\xEC b\u1ECF qua ki\u1EC3m tra an to\xE0n v\u1EDBi `--trusted-host`." : "S\u1EED d\u1EE5ng HTTPS k\xE8m ch\u1EE9ng ch\u1EC9 SSL h\u1EE3p l\u1EC7 cho kho l\u01B0u tr\u1EEF g\xF3i (registry)."
28
+ }));
29
+ }
30
+ };
31
+
32
+ export { rule };
33
+ //# sourceMappingURL=dockerfile-dependency-confusion.rule.js.map
34
+ //# sourceMappingURL=dockerfile-dependency-confusion.rule.js.map