@code-sentinel-cli/code-sentinel-cli 3.0.8 → 3.0.10
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 +34364 -18689
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +10 -8
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +10 -5
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +26 -3
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +7 -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 +1 -1
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +30 -4
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +1 -1
- package/dist/index.d.ts +284 -32
- package/dist/index.js +34582 -18907
- 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/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md
CHANGED
|
@@ -7,13 +7,14 @@ Bạn là senior Spring Boot reviewer. Đánh giá **một module Spring Boot**
|
|
|
7
7
|
- **NHIỀU method cùng CHUNG một kiểu drift = MỘT finding.** Vd. nếu nhiều method trong cùng một service đều "gọi nhiều mutation mà không có `@Transactional`" → đó là **MỘT** pattern duy nhất. Liệt kê các method trong `message`, **KHÔNG** tách mỗi method thành một finding riêng.
|
|
8
8
|
3. **`line` BẮT BUỘC là số nguyên dương** (≥ 1), trỏ vào một dòng cụ thể trong file đã chọn nơi pattern lộ rõ nhất (vd. dòng khai báo method mutation thiếu `@Transactional`, dòng `@Transactional(readOnly = true)` lệch chuẩn, dòng controller gọi thẳng repository.save). Nếu không chắc dòng nào → dùng `line: 1`. KHÔNG để trống, KHÔNG dùng `null`, KHÔNG dùng `0`.
|
|
9
9
|
4. **`file` phải là posix path** xuất hiện trong `Module summary` bên dưới — KHÔNG fabricate path mới.
|
|
10
|
-
5. **
|
|
10
|
+
5. **Transaction programmatic cũng là transaction hợp lệ.** `TransactionTemplate.execute(...)`, `executeWithoutResult(...)` và `TransactionOperations.execute(...)` bao phủ method/callback được ghi trong boundary facts; KHÔNG được coi write path đó là thiếu transaction chỉ vì không có annotation.
|
|
11
|
+
6. **Confidence `<50` → KHÔNG emit.** Ngưỡng noise thấp (`numMaxFindings: 5`).
|
|
11
12
|
|
|
12
13
|
## Chỉ flag khi có pattern lặp lại ≥ 2 feature (cùng resource)
|
|
13
14
|
|
|
14
15
|
Suy ra "cùng resource" từ base path `@RequestMapping("/api/<resource>")`, tên domain trong tên controller/service (vd. `OrderService` + `OrderImportService` → resource `order`), hoặc cùng entity/repository. Chỉ flag khi:
|
|
15
16
|
|
|
16
|
-
- **Coverage drift**: một feature bọc chuỗi mutation nhiều bước (≥ 2 `save`/`delete`/`update` repository hoặc ghi nhiều entity liên quan) trong `@Transactional
|
|
17
|
+
- **Coverage drift**: một feature bọc chuỗi mutation nhiều bước (≥ 2 `save`/`delete`/`update` repository hoặc ghi nhiều entity liên quan) trong transaction declarative (`@Transactional`) hoặc programmatic (`TransactionTemplate`/`TransactionOperations`), feature kia phục vụ cùng resource thực hiện chuỗi mutation tương đương mà KHÔNG có transaction boundary nào → một bên atomic, bên kia partial-write được.
|
|
17
18
|
- **readOnly drift**: cùng một loại thao tác đọc (query/list) trên cùng resource được đánh `@Transactional(readOnly = true)` ở feature này nhưng `@Transactional` thường (write tx) hoặc không có ở feature khác → khoá/tối ưu DB không đồng nhất cho cùng kiểu truy cập.
|
|
18
19
|
- **Boundary-placement drift**: feature A đặt transaction ở tầng service (`@Transactional` trên service method), feature B cùng resource gọi nhiều `repository.save()`/mutation TRỰC TIẾP từ controller hoặc từ một component không `@Transactional` → ranh giới transaction đặt ở chỗ khác nhau cho cùng nghiệp vụ.
|
|
19
20
|
- **Propagation/rollback drift**: cùng một bước nghiệp vụ trên cùng resource dùng `propagation` khác nhau (vd. `REQUIRES_NEW` ở feature này vs mặc định ở feature kia), hoặc một feature khai báo `rollbackFor = Exception.class`/`noRollbackFor` còn feature kia dùng mặc định → hành vi commit/rollback không đồng nhất.
|
|
@@ -22,7 +23,7 @@ Suy ra "cùng resource" từ base path `@RequestMapping("/api/<resource>")`, tê
|
|
|
22
23
|
## KHÔNG flag
|
|
23
24
|
|
|
24
25
|
- Bug chỉ xuất hiện trong 1 feature (đã thuộc per-cluster rule `transaction-loop-risk`).
|
|
25
|
-
- Tất cả feature cùng resource
|
|
26
|
+
- Tất cả feature cùng resource đều có transaction boundary bao phủ write path (`@Transactional` hoặc programmatic), dù cơ chế biểu diễn khác nhau nhưng semantics tương đương → không phải coverage drift.
|
|
26
27
|
- Endpoint/feature chỉ đọc (query, list, get) hợp lý KHÔNG cần `@Transactional`, hoặc thiếu `@Transactional` ở thao tác single-statement (một `save` duy nhất, JPA tự flush) — đó KHÔNG phải drift, đừng so với một feature mutation nhiều bước.
|
|
27
28
|
- Các feature thao tác trên resource KHÁC NHAU — ranh giới transaction khác nhau là hợp lý.
|
|
28
29
|
- `@Transactional(readOnly = true)` chỉ ở read feature và write tx ở write feature là ĐÚNG thiết kế — chỉ flag khi CÙNG loại thao tác mà readOnly/propagation lệch.
|
|
@@ -41,11 +42,11 @@ Suy ra "cùng resource" từ base path `@RequestMapping("/api/<resource>")`, tê
|
|
|
41
42
|
|
|
42
43
|
{{module_findings}}
|
|
43
44
|
|
|
44
|
-
##
|
|
45
|
+
## Transaction boundaries (scan trực tiếp từ source của members — ĐÂY LÀ BẰNG CHỨNG CHÍNH)
|
|
45
46
|
|
|
46
|
-
Mỗi dòng = một
|
|
47
|
+
Mỗi dòng = một transaction boundary tìm thấy trong module. Mechanism có thể là `@Transactional`, `TransactionTemplate.execute`, `TransactionTemplate.executeWithoutResult`, `TransactionOperations.execute` hoặc `TransactionOperations.executeWithoutResult`. Fact kèm vị trí (`file:line`), phạm vi (`class`/`method`) + tên target, helper được callback gọi trực tiếp (`target() -> helper()`), `readOnly`, `rollbackFor`, `propagation`, `isolation`, và `writes≈N`. `readOnly=unknown` nghĩa là template được inject và cấu hình không thể suy ra tĩnh — không dùng giá trị đó để kết luận readOnly drift.
|
|
47
48
|
|
|
48
|
-
**Dùng các fact này để so sánh trực tiếp giữa các feature cùng resource** — đây là nguồn chính xác hơn pass-1 findings cho 4 loại drift bên dưới.
|
|
49
|
+
**Dùng các fact này để so sánh trực tiếp giữa các feature cùng resource** — đây là nguồn chính xác hơn pass-1 findings cho 4 loại drift bên dưới. Programmatic fact trên `split() -> doSplit()` nghĩa là cả callback/helper `doSplit()` chạy trong transaction; mutation nằm trong helper đó KHÔNG phải write ngoài transaction. Chỉ kết luận coverage drift khi một write path không được bất kỳ declarative hoặc programmatic fact nào bao phủ.
|
|
49
50
|
|
|
50
51
|
{{module_transaction_boundaries}}
|
|
51
52
|
|
|
@@ -72,14 +73,15 @@ Nếu không có drift rõ ràng: `{"violations": []}`.
|
|
|
72
73
|
|
|
73
74
|
## REPEAT CRITICAL RULES
|
|
74
75
|
|
|
75
|
-
- Ưu tiên đối chiếu danh sách
|
|
76
|
+
- Ưu tiên đối chiếu danh sách **Transaction boundaries** ở trên để xác định drift — pass-1 findings chỉ là signal phụ.
|
|
76
77
|
- Pattern phải xuất hiện trong ≥ 2 feature của module và CÙNG resource.
|
|
77
78
|
- **MỖI pattern = MỘT finding.** Gộp cùng pattern ngang nhiều file/method thành một finding; liệt kê tên service/controller trong `message`. KHÔNG lặp một pattern theo từng file/method.
|
|
78
79
|
- `file` phải nằm trong `members[]` của module summary trên.
|
|
79
80
|
- `line` phải là số nguyên ≥ 1 trỏ vào file đã chọn — KHÔNG để trống / `null` / `0`.
|
|
80
81
|
- KHÔNG duplicate findings đã có ở pass-1 (chúng đã được report ở leaf rule).
|
|
81
82
|
- Read-only / single-statement feature không có `@Transactional` KHÔNG phải drift — đừng so với feature mutation nhiều bước.
|
|
82
|
-
-
|
|
83
|
+
- Transaction programmatic bao phủ method/helper là transaction hợp lệ; KHÔNG flag thiếu transaction chỉ vì write method không có `@Transactional` trực tiếp.
|
|
84
|
+
- Mọi feature cùng resource đặt transaction nhất quán hoặc có semantics tương đương → KHÔNG phải drift, đừng flag.
|
|
83
85
|
- Confidence `<50` → KHÔNG emit.
|
|
84
86
|
|
|
85
87
|
Đừng giải thích. JSON thuần.
|
package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml
CHANGED
|
@@ -22,9 +22,13 @@ id: spring-boot/cross-feature-transaction-boundary-drift
|
|
|
22
22
|
# new `{{module_transaction_boundaries}}` prompt var. Prompt now compares
|
|
23
23
|
# those facts directly across features. Version bump cache-busts the v1
|
|
24
24
|
# rows that ran without the boundary evidence.
|
|
25
|
-
|
|
25
|
+
# v3: recognize programmatic Spring transaction boundaries
|
|
26
|
+
# (`TransactionTemplate` / `TransactionOperations`) and their directly
|
|
27
|
+
# delegated helper so annotation absence is no longer treated as proof that a
|
|
28
|
+
# write path is non-transactional. Version bump invalidates cached v2 findings.
|
|
29
|
+
version: 3
|
|
26
30
|
kind: ai
|
|
27
|
-
title: "Các feature trong cùng module quản lý ranh giới
|
|
31
|
+
title: "Các feature trong cùng module quản lý ranh giới transaction không nhất quán?"
|
|
28
32
|
description: |
|
|
29
33
|
Per-module AI rule (Phase 15.5.3, ADR-0016) — phát hiện **drift trong
|
|
30
34
|
ranh giới transaction** giữa nhiều feature (controller + service) CỦA
|
|
@@ -32,9 +36,10 @@ description: |
|
|
|
32
36
|
**synthesis** chỉ lộ ra khi nhìn ngang nhiều feature, không phải vấn đề
|
|
33
37
|
trong 1 cluster:
|
|
34
38
|
- Một feature bọc chuỗi mutation nhiều bước (nhiều `repository.save()` /
|
|
35
|
-
nhiều bảng) trong `@Transactional
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
nhiều bảng) trong transaction declarative (`@Transactional`) hoặc
|
|
40
|
+
programmatic (`TransactionTemplate` / `TransactionOperations`), feature
|
|
41
|
+
khác cùng resource thực hiện thao tác tương đương nhưng KHÔNG có
|
|
42
|
+
transaction → một bên atomic, bên kia có nguy cơ ghi dở (partial write).
|
|
38
43
|
- Cùng một loại thao tác đọc được đánh `@Transactional(readOnly = true)`
|
|
39
44
|
ở feature này nhưng `@Transactional` thường (hoặc không có) ở feature
|
|
40
45
|
khác cùng module → tối ưu / khoá DB không đồng nhất.
|
|
@@ -54,7 +54,7 @@ function rootIdentifier(expr) {
|
|
|
54
54
|
}
|
|
55
55
|
var rule = {
|
|
56
56
|
id: "angular/template-dom-xss",
|
|
57
|
-
version:
|
|
57
|
+
version: 3,
|
|
58
58
|
kind: "static-ts",
|
|
59
59
|
usesTemplateComponent: true,
|
|
60
60
|
title: "Binding nguy hi\u1EC3m trong template Angular (DOM XSS)",
|
|
@@ -88,9 +88,18 @@ var rule = {
|
|
|
88
88
|
}
|
|
89
89
|
if (origin === "sanitizer-trusted") continue;
|
|
90
90
|
const confirmed = origin === "tainted-source";
|
|
91
|
+
const externalBypass = origin === "external-bypass";
|
|
91
92
|
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`;
|
|
93
|
+
let message;
|
|
94
|
+
if (confirmed) {
|
|
95
|
+
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.`;
|
|
96
|
+
} else if (externalBypass) {
|
|
97
|
+
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.`;
|
|
98
|
+
} else {
|
|
99
|
+
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.`;
|
|
100
|
+
}
|
|
92
101
|
findings.push({
|
|
93
|
-
message
|
|
102
|
+
message,
|
|
94
103
|
file: ctx.file.path,
|
|
95
104
|
range: {
|
|
96
105
|
line: attr.startPosition.row + 1,
|
|
@@ -100,7 +109,21 @@ var rule = {
|
|
|
100
109
|
// how `angular/no-dom-xss` reports confirmed flows on the `.ts` side);
|
|
101
110
|
// unresolved/unknown stays the structural `warning` @ baseConfidence 70.
|
|
102
111
|
...confirmed ? { severity: "error", confidence: 85 } : {},
|
|
103
|
-
|
|
112
|
+
// An external-bypass keeps the rule's `warning` severity and only lifts
|
|
113
|
+
// confidence to 80 — ADVISORY, not blocking, per [ADR-0031]'s principle
|
|
114
|
+
// that an UNCONFIRMED band inside a deterministic rule must not gate a
|
|
115
|
+
// merge ([ADR-0028]: a deterministic `error` ALWAYS gates, whatever its
|
|
116
|
+
// confidence). What is proven here is "the sanitizer was disabled on a
|
|
117
|
+
// value that crossed the component boundary" — NOT that the value is
|
|
118
|
+
// attacker-controlled, which is what `tainted-source` proves and what
|
|
119
|
+
// earns `error`. And the gate has a KNOWN unrecognised control class:
|
|
120
|
+
// a project-defined validator (`isTrustedResourceUrl(path)`, measured in
|
|
121
|
+
// [ADR-0060] §"A.3 probed") is a real defence this rule cannot yet see,
|
|
122
|
+
// so a CI-blocking verdict here would repeat the `spring/jdbc-template`
|
|
123
|
+
// mistake — an `error` that fails a build on a control the tool missed.
|
|
124
|
+
// Revisit `error` once validation-guard recognition lands.
|
|
125
|
+
...externalBypass ? { confidence: 80 } : {},
|
|
126
|
+
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
127
|
});
|
|
105
128
|
}
|
|
106
129
|
return findings;
|
|
@@ -11,7 +11,13 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "spring-boot/no-command-injection",
|
|
14
|
-
|
|
14
|
+
// v4 (Pentest Coverage Layer P3 #4): the Java analyzer now folds a tainted
|
|
15
|
+
// collection element (`argList.add("echo " + param)`) into the collection so
|
|
16
|
+
// the whole list reaching `pb.command(argList)` / `new ProcessBuilder(argList)`
|
|
17
|
+
// is detected — the dominant OWASP-Benchmark command-injection List shape. The
|
|
18
|
+
// rule's projection logic is unchanged; the bump invalidates findings cached on
|
|
19
|
+
// unchanged file content before the broader analyzer coverage.
|
|
20
|
+
version: 4,
|
|
15
21
|
kind: "static-ts",
|
|
16
22
|
title: "Kh\xF4ng ch\u1EA1y l\u1EC7nh h\u1EC7 th\u1ED1ng t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (OS Command Injection)",
|
|
17
23
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o l\u1EC7nh h\u1EC7 \u0111i\u1EC1u h\xE0nh (`Runtime.getRuntime().exec(...)` ho\u1EB7c `ProcessBuilder.command(...)`) l\xE0 l\u1ED7 h\u1ED5ng OS Command Injection (CWE-78) \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n \u0111\u01B0\u1EE3c l\u1EC7nh shell t\xF9y \xFD ch\u1EA1y tr\xEAn server (RCE). Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: tr\xE1nh g\u1ECDi shell; n\u1EBFu b\u1EAFt bu\u1ED9c, d\xF9ng allowlist l\u1EC7nh/tham s\u1ED1 c\u1ED1 \u0111\u1ECBnh v\xE0 truy\u1EC1n d\u1EA1ng m\u1EA3ng tham s\u1ED1 (kh\xF4ng n\u1ED1i chu\u1ED7i v\xE0o `sh -c`), kh\xF4ng bao gi\u1EDD d\u1EF1ng l\u1EC7nh t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp.",
|
|
@@ -11,7 +11,7 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "spring-boot/no-path-traversal",
|
|
14
|
-
version:
|
|
14
|
+
version: 3,
|
|
15
15
|
kind: "static-ts",
|
|
16
16
|
title: "Kh\xF4ng m\u1EDF file theo \u0111\u01B0\u1EDDng d\u1EABn t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (Path Traversal)",
|
|
17
17
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, @RequestPart, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o \u0111\u01B0\u1EDDng d\u1EABn filesystem (`new File(...)`, `new FileInputStream(...)`, `getResource(...)`) ho\u1EB7c kh\xF3a object-store MinIO (`.object(...)`) l\xE0 l\u1ED7 h\u1ED5ng Path Traversal (CWE-22) \u2014 k\u1EBB t\u1EA5n c\xF4ng d\xF9ng `../../../../etc/passwd` \u0111\u1EC3 \u0111\u1ECDc/ghi file ngo\xE0i th\u01B0 m\u1EE5c d\u1EF1 ki\u1EBFn. Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: chu\u1EA9n h\xF3a \u0111\u01B0\u1EDDng d\u1EABn (`getCanonicalPath()`) r\u1ED3i ki\u1EC3m tra n\u1EB1m trong th\u01B0 m\u1EE5c g\u1ED1c cho ph\xE9p (allowlist); kh\xF4ng bao gi\u1EDD gh\xE9p \u0111\u01B0\u1EDDng d\u1EABn tr\u1EF1c ti\u1EBFp t\u1EEB input ng\u01B0\u1EDDi d\xF9ng.",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// builtin-rules/static/spring-boot/no-servlet-xss.rule.ts
|
|
2
|
+
var SERVLET_XSS_SINK_IDS = /* @__PURE__ */ new Set(["spring/servlet-writer"]);
|
|
3
|
+
var SINK_LABEL = {
|
|
4
|
+
"spring/servlet-writer": "response.getWriter().write/print(...)"
|
|
5
|
+
};
|
|
6
|
+
var rule = {
|
|
7
|
+
id: "spring-boot/no-servlet-xss",
|
|
8
|
+
version: 1,
|
|
9
|
+
kind: "static-ts",
|
|
10
|
+
title: "Kh\xF4ng ghi d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t v\xE0o response HTML (Reflected XSS)",
|
|
11
|
+
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, Cookie, \u2026) ghi th\u1EB3ng v\xE0o body response qua `response.getWriter().write/print/println/printf/format(...)` m\xE0 kh\xF4ng encode l\xE0 l\u1ED7 h\u1ED5ng Reflected Cross-Site Scripting (CWE-79) \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n `<script>` ch\u1EA1y trong phi\xEAn \u0111\u0103ng nh\u1EADp c\u1EE7a n\u1EA1n nh\xE2n (\u0111\xE1nh c\u1EAFp session, thao t\xE1c thay ng\u01B0\u1EDDi d\xF9ng). Rule d\xF9ng taint analysis (Tier-1 trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u; sink \u0111\u01B0\u1EE3c gate theo receiver `getWriter()` n\xEAn kh\xF4ng nh\u1EA7m v\u1EDBi `System.out.println` / `String.format`. Kh\u1EAFc ph\u1EE5c: HTML-encode gi\xE1 tr\u1ECB tr\u01B0\u1EDBc khi ghi (OWASP Java Encoder `Encode.forHtml(...)`), ho\u1EB7c tr\u1EA3 JSON qua `@ResponseBody` \u0111\u1EC3 Spring t\u1EF1 serialize thay v\xEC ghi tay ra writer.",
|
|
12
|
+
severity: "error",
|
|
13
|
+
category: "security",
|
|
14
|
+
languages: ["java"],
|
|
15
|
+
scope: "spring-boot",
|
|
16
|
+
requires: "syntactic",
|
|
17
|
+
usesTaint: true,
|
|
18
|
+
baseConfidence: 80,
|
|
19
|
+
check(ctx) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
for (const tf of ctx.taintFindings ?? []) {
|
|
22
|
+
if (!SERVLET_XSS_SINK_IDS.has(tf.sinkId)) continue;
|
|
23
|
+
const sources = [...new Set(tf.sourceIds)].join(", ");
|
|
24
|
+
const laundered = (tf.path?.length ?? 0) > 0;
|
|
25
|
+
const sinkLabel = SINK_LABEL[tf.sinkId] ?? tf.sinkId;
|
|
26
|
+
const trace = laundered ? " (truy v\u1EBFt li\xEAn th\u1EE7 t\u1EE5c)" : "";
|
|
27
|
+
findings.push({
|
|
28
|
+
message: `\u26A0 Reflected XSS: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ghi v\xE0o ${sinkLabel} kh\xF4ng encode \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n \u0111\u01B0\u1EE3c m\xE3 script ch\u1EA1y trong tr\xECnh duy\u1EC7t n\u1EA1n nh\xE2n.${trace}`,
|
|
29
|
+
file: ctx.file.path,
|
|
30
|
+
range: { line: tf.line, column: tf.column ?? 1 },
|
|
31
|
+
confidence: laundered ? 75 : 85,
|
|
32
|
+
suggestion: "HTML-encode gi\xE1 tr\u1ECB tr\u01B0\u1EDBc khi ghi ra response (vd OWASP Java Encoder `Encode.forHtml(value)`), ho\u1EB7c tr\u1EA3 d\u1EEF li\u1EC7u d\u1EA1ng JSON qua `@ResponseBody` / `ResponseEntity` \u0111\u1EC3 framework t\u1EF1 serialize + set content-type an to\xE0n, thay v\xEC ghi HTML tay ra `getWriter()`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng echo input ng\u01B0\u1EDDi d\xF9ng v\xE0o HTML m\xE0 kh\xF4ng escape."
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return findings;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { rule };
|
|
40
|
+
//# sourceMappingURL=no-servlet-xss.rule.js.map
|
|
41
|
+
//# sourceMappingURL=no-servlet-xss.rule.js.map
|
|
@@ -5,7 +5,7 @@ var SINK_LABEL = {
|
|
|
5
5
|
};
|
|
6
6
|
var rule = {
|
|
7
7
|
id: "spring-boot/no-spel-injection",
|
|
8
|
-
version:
|
|
8
|
+
version: 2,
|
|
9
9
|
kind: "static-ts",
|
|
10
10
|
title: "Kh\xF4ng parse SpEL t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (Expression Language Injection)",
|
|
11
11
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o `ExpressionParser.parseExpression(...)` l\xE0 l\u1ED7 h\u1ED5ng Expression Language (SpEL) Injection (CWE-917) \u2014 bi\u1EC3u th\u1EE9c SpEL do k\u1EBB t\u1EA5n c\xF4ng ki\u1EC3m so\xE1t c\xF3 th\u1EC3 g\u1ECDi method t\xF9y \xFD (`T(java.lang.Runtime).getRuntime().exec(...)`) \u2192 RCE. Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: kh\xF4ng bao gi\u1EDD parse SpEL t\u1EEB input ng\u01B0\u1EDDi d\xF9ng; n\u1EBFu c\u1EA7n bi\u1EC3u th\u1EE9c \u0111\u1ED9ng, d\xF9ng allowlist bi\u1EC3u th\u1EE9c c\u1ED1 \u0111\u1ECBnh, ho\u1EB7c `SimpleEvaluationContext` (ch\u1EB7n type reference / method call nguy hi\u1EC3m) thay cho `StandardEvaluationContext`.",
|
|
@@ -12,7 +12,16 @@ var SQL_SINK_CALLEES = /* @__PURE__ */ new Set([
|
|
|
12
12
|
"queryForRowSet",
|
|
13
13
|
"update",
|
|
14
14
|
"execute",
|
|
15
|
-
"batchUpdate"
|
|
15
|
+
"batchUpdate",
|
|
16
|
+
// v6 (P3 #2): raw JDBC Statement/PreparedStatement sinks — mirrors the new
|
|
17
|
+
// `spring/jdbc-raw` taint sink so a taint-confirmed raw-JDBC concat upgrades
|
|
18
|
+
// to CONFIRMED (error/90) instead of the UNKNOWN advisory band.
|
|
19
|
+
"prepareStatement",
|
|
20
|
+
"prepareCall",
|
|
21
|
+
"executeQuery",
|
|
22
|
+
"executeUpdate",
|
|
23
|
+
"executeLargeUpdate",
|
|
24
|
+
"addBatch"
|
|
16
25
|
]);
|
|
17
26
|
var SANITIZER_CALLEES = /* @__PURE__ */ new Set([
|
|
18
27
|
"parseLong",
|
|
@@ -113,6 +122,18 @@ var isDynamicOperand = (op, staticFinals) => {
|
|
|
113
122
|
}
|
|
114
123
|
return true;
|
|
115
124
|
};
|
|
125
|
+
var isInsideAnnotationArg = (node) => {
|
|
126
|
+
let cur = node.parent;
|
|
127
|
+
while (cur) {
|
|
128
|
+
const t = cur.type;
|
|
129
|
+
if (t === "annotation_argument_list" || t === "annotation") return true;
|
|
130
|
+
if (t === "block" || t === "constructor_body" || t === "class_body" || t === "program") {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
cur = cur.parent;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
};
|
|
116
137
|
var enclosingSqlSinkLine = (node) => {
|
|
117
138
|
let cur = node.parent;
|
|
118
139
|
while (cur) {
|
|
@@ -131,7 +152,7 @@ var isConcatRoot = (node) => {
|
|
|
131
152
|
};
|
|
132
153
|
var rule = {
|
|
133
154
|
id: "spring-boot/no-sql-string-concat",
|
|
134
|
-
version:
|
|
155
|
+
version: 6,
|
|
135
156
|
kind: "static-ts",
|
|
136
157
|
title: "Kh\xF4ng n\u1ED1i SQL b\u1EB1ng `+` \u2014 d\xF9ng prepared statement / named parameter",
|
|
137
158
|
description: "N\u1ED1i chu\u1ED7i SQL b\u1EB1ng `+` l\xE0 pattern \u0111i\u1EC3n h\xECnh c\u1EE7a SQL Injection. v2 d\xF9ng taint analysis: n\u1ED1i c\xF3 gi\xE1 tr\u1ECB t\u1EEB request (taint-confirmed) \u2192 error tin c\u1EADy cao; n\u1ED1i to\xE0n h\u1EB1ng s\u1ED1 (literal / `static final`) \u2192 b\u1ECF qua; c\xF2n l\u1EA1i gi\u1EEF c\u1EA3nh b\xE1o nh\u01B0 v1. D\xF9ng JdbcTemplate `?` + args, JPQL `:param` + `setParameter(...)`, ho\u1EB7c Spring Data query methods.",
|
|
@@ -141,7 +162,9 @@ var rule = {
|
|
|
141
162
|
scope: "spring-boot",
|
|
142
163
|
requires: "syntactic",
|
|
143
164
|
usesTaint: true,
|
|
144
|
-
|
|
165
|
+
// Declared default `severity: error` applies to the CONFIRMED band only; the
|
|
166
|
+
// UNKNOWN band overrides to `warning`/55 per-finding (v5, ADR-0031).
|
|
167
|
+
baseConfidence: 55,
|
|
145
168
|
check(ctx) {
|
|
146
169
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
147
170
|
const root = tree.rootNode;
|
|
@@ -155,6 +178,7 @@ var rule = {
|
|
|
155
178
|
(op) => op.type === "string_literal" && SQL_KEYWORD.test(op.text)
|
|
156
179
|
);
|
|
157
180
|
if (!hasSqlKeyword) continue;
|
|
181
|
+
if (isInsideAnnotationArg(concat)) continue;
|
|
158
182
|
const dynamicOperands = operands.filter((op) => isDynamicOperand(op, staticFinals));
|
|
159
183
|
if (dynamicOperands.length === 0) continue;
|
|
160
184
|
const range = {
|
|
@@ -178,9 +202,11 @@ var rule = {
|
|
|
178
202
|
});
|
|
179
203
|
} else {
|
|
180
204
|
findings.push({
|
|
181
|
-
message: "
|
|
205
|
+
message: "N\u1ED1i chu\u1ED7i SQL \u0111\u1ED9ng \u2014 taint kh\xF4ng x\xE1c nh\u1EADn \u0111\u01B0\u1EE3c ngu\u1ED3n t\u1EEB request, ch\u01B0a r\xF5 \u0111\xE3 tham s\u1ED1 ho\xE1 hay ch\u01B0a. Review th\u1EE7 c\xF4ng (advisory, KH\xD4NG ch\u1EB7n merge): n\u1EBFu m\u1ECDi gi\xE1 tr\u1ECB \u0111\xE3 bind qua `?` / `:param` th\xEC b\u1ECF qua.",
|
|
182
206
|
file: ctx.file.path,
|
|
183
207
|
range,
|
|
208
|
+
severity: "warning",
|
|
209
|
+
confidence: 55,
|
|
184
210
|
suggestion: "JdbcTemplate `?` placeholders + args, ho\u1EB7c JPQL `:param` + `setParameter(...)`, ho\u1EB7c Spring Data query methods."
|
|
185
211
|
});
|
|
186
212
|
}
|
|
@@ -13,7 +13,7 @@ var SINK_LABEL = {
|
|
|
13
13
|
};
|
|
14
14
|
var rule = {
|
|
15
15
|
id: "spring-boot/no-ssrf",
|
|
16
|
-
version:
|
|
16
|
+
version: 4,
|
|
17
17
|
kind: "static-ts",
|
|
18
18
|
title: "Kh\xF4ng g\u1ECDi HTTP ra ngo\xE0i b\u1EB1ng URL t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (SSRF)",
|
|
19
19
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o URL c\u1EE7a m\u1ED9t l\u1EDDi g\u1ECDi HTTP ra ngo\xE0i (RestTemplate `getForObject`/`exchange`/\u2026, WebClient `.uri(...)`, ho\u1EB7c OkHttp `Request.Builder.url(...)`) l\xE0 l\u1ED7 h\u1ED5ng Server-Side Request Forgery (CWE-918) \u2014 k\u1EBB t\u1EA5n c\xF4ng \u0111i\u1EC1u khi\u1EC3n server g\u1ECDi t\u1EDBi \u0111\u1ECBa ch\u1EC9 n\u1ED9i b\u1ED9 / metadata cloud (vd. 169.254.169.254) ho\u1EB7c d\u1ECBch v\u1EE5 n\u1ED9i b\u1ED9 kh\xF4ng \u0111\u01B0\u1EE3c ph\xE9p truy c\u1EADp t\u1EEB b\xEAn ngo\xE0i. Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: validate URL b\u1EB1ng allowlist host/scheme c\u1ED1 \u0111\u1ECBnh; kh\xF4ng bao gi\u1EDD gh\xE9p URL \u0111\xEDch tr\u1EF1c ti\u1EBFp t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp.",
|