@code-sentinel-cli/code-sentinel-cli 3.0.3 → 3.0.4
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/README.md +1 -1
- package/dist/bin.js +1184 -809
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
- package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
- package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
- package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
- package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
- package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
- package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
- package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
- package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
- package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
- package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
- package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
- package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
- package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
- package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
- package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
- package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
- package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
- package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
- package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
- package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
- package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
- package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
- package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
- package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
- package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
- package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
- package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
- package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
- package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
- package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
- package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
- package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
- package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
- package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
- package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
- package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
- package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
- package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
- package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
- package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
- package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
- package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
- package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
- package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
- package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
- package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
- package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
- package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
- package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
- package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
- package/dist/index.d.ts +224 -47
- package/dist/index.js +1183 -808
- package/package.json +3 -2
- package/src/migrations/0000_initial.sql +62 -0
- package/src/migrations/0001_add_confidence.sql +7 -0
- package/src/migrations/0002_add_ai_stats.sql +21 -0
- package/src/migrations/0003_add_fix_recipe.sql +29 -0
- package/src/migrations/0004_add_ast_graph.sql +61 -0
- package/src/migrations/0005_add_project_id.sql +1 -0
- package/src/migrations/0006_add_ai_model.sql +5 -0
- package/src/migrations/0006_add_rule_results.sql +1 -0
- package/src/migrations/0007_add_finding_metadata.sql +4 -0
- package/src/migrations/0008_add_coverage.sql +2 -0
- package/src/migrations/0009_run_provenance.sql +5 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# ERROR HANDLING REVIEW — Spring Boot cluster
|
|
2
|
+
|
|
3
|
+
Bạn là **senior Spring Boot reviewer**. Đánh giá **error handling flow** của một cluster gồm 1 controller PRIMARY + các file support (service, repository, exception handler nếu có).
|
|
4
|
+
|
|
5
|
+
## 🚨 CRITICAL RULES (đọc trước, áp dụng nghiêm)
|
|
6
|
+
|
|
7
|
+
1. **CHỈ flag khi RÕ RÀNG có vấn đề** trong cluster bạn nhìn thấy. Không đoán.
|
|
8
|
+
2. **`line` BẮT BUỘC** trỏ vào dòng trong FILE PRIMARY (controller). Không dùng line từ support files.
|
|
9
|
+
3. **Mỗi finding distinct** — không emit cùng message cho nhiều dòng.
|
|
10
|
+
4. **SKIP intentional crash / demo / test endpoints** — class javadoc/comment chứa `showcase` / `demo` / `example` / `intentional` / `crash test` / `for testing`, hoặc filename matching `*Crash*.java` / `*Demo*.java` / `*Example*.java`. Code này CỐ Ý ném exception để minh họa → KHÔNG phải bug, KHÔNG flag.
|
|
11
|
+
5. **Thymeleaf MVC implicit handler exists** — nếu PRIMARY là `@Controller` (NOT `@RestController`) thì Spring Boot tự fallback render `templates/error.html` cho uncaught exception. Đây LÀ implicit handler. KHÔNG flag "missing @ControllerAdvice" cho `@Controller`-based apps; chỉ flag nếu controller code rõ ràng leak/swallow exception ngay tại method body.
|
|
12
|
+
6. **High-signal only** — rule này KHÔNG phải catch-all cho mọi uncaught service exception. Chỉ emit các pattern trong mục "Tiêu chí flag" bên dưới.
|
|
13
|
+
7. **Không overlap với security/backend-flow** — nếu symptom chính là thiếu authorization, IDOR, unsafe outbound/file flow, transaction multi-write, hoặc invariant nghiệp vụ, để rule tương ứng xử lý. Error-handling chỉ flag cách lỗi bị catch/leak/swallow/map sai.
|
|
14
|
+
8. **Không duplicate raw-error security leak trừ khi có error-handling bug riêng** — `e.getMessage()` / `e.toString()` chỉ là finding rule này khi catch cũng map sai lỗi nghiệp vụ/user-correctable, swallow failure, hoặc làm client hiểu sai kết quả.
|
|
15
|
+
9. **Benchmark negative controls** — KHÔNG report `SafeOperationsController`, `SafeOperationsService`, DTO safe flow, hoặc `ApiExceptionAdvice` support-only file nếu không có evidence trực tiếp trong PRIMARY. `ApiExceptionAdvice` chỉ là evidence xử lý lỗi khi annotation/assignable target áp dụng cho PRIMARY.
|
|
16
|
+
10. **Scan đủ cluster trước khi emit** — đọc PRIMARY, service support, repository support, và advice/handler support. Nếu service/advice body cần thiết không có trong cluster thì skip thay vì đoán.
|
|
17
|
+
11. **Global `@ControllerAdvice` / `@RestControllerAdvice` được TIÊM vào MỌI cluster** (kể cả khi nó ở package khác như `exception/`, `web/rest/errors/`). Nếu support files có một advice class với `@ExceptionHandler` cho một exception type (vd. `NotFoundException` → 404, `Exception` → 500), thì exception đó ĐÃ được handle app-wide cho PRIMARY (trừ khi advice khai báo `assignableTypes`/`basePackages` loại trừ PRIMARY). KHÔNG flag "missing handler" cho exception mà advice trong cluster đã cover.
|
|
18
|
+
12. **Confidence `<50` → KHÔNG emit**.
|
|
19
|
+
|
|
20
|
+
## Tiêu chí flag (chỉ flag khi RÕ RÀNG là bug-logic gap)
|
|
21
|
+
|
|
22
|
+
1. **Swallowed exception** — `catch (Exception e) { /* empty */ }` hoặc `catch { log.error(...); }` không re-throw, không trả error response.
|
|
23
|
+
2. **Generic catch có tác động API rõ ràng** — `catch (Exception e)` ở controller layer thay vì specific type (`DataAccessException`, `IllegalArgumentException`, …) VÀ catch đó trả sai status/shape, leak raw exception, hoặc biến lỗi nghiệp vụ thành 500.
|
|
24
|
+
3. **Missing exception handler cho state-changing approval flow** — service ném `RuntimeException` subclass (vd. `IllegalStateException`) trong flow approve/submit/create quan trọng nhưng:
|
|
25
|
+
- Controller không có `try/catch`
|
|
26
|
+
- Không có `@ExceptionHandler` method trong cluster
|
|
27
|
+
- Không có `@ControllerAdvice` / `@RestControllerAdvice` được reference
|
|
28
|
+
- **AND** PRIMARY là `@RestController` (NOT `@Controller` — xem CRITICAL RULE 5)
|
|
29
|
+
|
|
30
|
+
Chỉ flag high-signal state-changing method như approve/submit/create/pay/release/refund/cancel/assign/close/bulk-update khi service body rõ ràng throw `IllegalStateException`/custom runtime exception và không có handler. KHÔNG flag normal read/not-found/list/download/helper flow chỉ vì service có `.get()`/`orElseThrow()`.
|
|
31
|
+
|
|
32
|
+
4. **Raw/inconsistent error response ngay tại controller catch** — controller trả `ResponseEntity<String>` với `e.getMessage()` / `e.toString()` hoặc `ResponseEntity.status(500).body(...)` với body trần, **và** support service cho thấy có lỗi user-correctable/domain/business-state có thể bị collapse thành 500 hoặc response shape không ổn định.
|
|
33
|
+
5. **Transaction rollback gap** — `@Transactional` method bắt exception rồi swallow → rollback không trigger (Spring rollback default chỉ trên RuntimeException không bị catch).
|
|
34
|
+
|
|
35
|
+
Nếu cùng một catch block vừa `catch (Exception)` vừa trả `e.getMessage()` / `e.toString()` trong response, emit MỘT finding gộp, không tách thành generic-catch finding và raw-response finding riêng.
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
6. **Wrong success status after failure** — catch exception rồi vẫn trả `200 OK`, `"success"`, `"cancelled"`, `null` hoặc object stale khiến client tưởng operation thành công.
|
|
39
|
+
7. **Async / future failure lost** — controller fire-and-forget `CompletableFuture`, `@Async`, scheduler/job publish hoặc webhook retry mà không observe exception, không timeout, không error response/correlation id.
|
|
40
|
+
8. **Domain exception collapsed to 500** — controller catch mọi `Exception` rồi trả 500 cho lỗi user-correctable như validation/business state (`IllegalArgumentException`, `IllegalStateException`) thay vì 400/409 với response shape ổn định.
|
|
41
|
+
|
|
42
|
+
## KHÔNG flag
|
|
43
|
+
|
|
44
|
+
- Controller `throws Exception` được handle ở `@ControllerAdvice` HIỆN diện trong cluster (kể cả file `*ExceptionHandler.java` / `*Advice.java`).
|
|
45
|
+
- `ApiExceptionAdvice` neu no chi apply cho controller khac (`assignableTypes`, package/path mismatch) va khong phai handler cua PRIMARY; dung no de skip false-positive cho safe flow, khong report chinh advice file.
|
|
46
|
+
- `SafeOperationsController`, `SafeOperationsService`, DTO safe flow, hoac negative-control support files tru khi PRIMARY co catch/leak/swallow/missing-handler evidence truc tiep.
|
|
47
|
+
- Service throw nhưng controller method gọi nó được wrap trong helper với try/catch xử lý đúng.
|
|
48
|
+
- Test files, generated files, DTO/Entity thuần.
|
|
49
|
+
- Intentional crash / demo / test endpoints (xem CRITICAL RULE 4).
|
|
50
|
+
- Thymeleaf `@Controller` apps (xem CRITICAL RULE 5).
|
|
51
|
+
- Normal read/not-found flow (`get`, `profile`, `list`, `download`) thiếu handler. Những case này thuộc API contract/backend-flow review, không phải finding của rule này.
|
|
52
|
+
- `repository.findById(id).get()` trong support service nếu controller không catch/leak/swallow trực tiếp. Đừng flag Optional usage riêng ở rule này.
|
|
53
|
+
- Catch raw exception quanh create/update endpoint chỉ gọi repository `save` đơn giản hoặc external sink không có visible domain/business exception: để security/backend-flow xử lý nếu có leak/SSRF/transaction; rule này skip để tránh duplicate.
|
|
54
|
+
- Missing handler cho method thay đổi trạng thái nhưng service chỉ `orElseThrow()` not-found hoặc repository exception chung, không có explicit business-state exception visible.
|
|
55
|
+
|
|
56
|
+
## Cluster context
|
|
57
|
+
|
|
58
|
+
PRIMARY (controller / entry layer):
|
|
59
|
+
File: `{{file}}`
|
|
60
|
+
Language: `{{language}}`
|
|
61
|
+
|
|
62
|
+
```{{language}}
|
|
63
|
+
{{code}}
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
SUPPORT FILES (services, repositories, advice classes — đọc để hiểu flow):
|
|
67
|
+
|
|
68
|
+
```
|
|
69
|
+
{{cluster_files}}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
{{cluster_summary}}
|
|
73
|
+
|
|
74
|
+
## Output yêu cầu
|
|
75
|
+
|
|
76
|
+
Trả về **JSON HỢP LỆ DUY NHẤT** (không markdown fence, không text khác) theo schema:
|
|
77
|
+
|
|
78
|
+
```
|
|
79
|
+
{
|
|
80
|
+
"violations": [
|
|
81
|
+
{
|
|
82
|
+
"line": <số nguyên 1-based, ÁNH XẠ VỀ FILE PRIMARY>,
|
|
83
|
+
"endLine": <số nguyên | null>,
|
|
84
|
+
"message": "<≤200 ký tự, tiếng Việt, nêu rõ FILE + behavior + tác động>",
|
|
85
|
+
"suggestion": "<gợi ý fix | null>",
|
|
86
|
+
"confidence": <số nguyên 0-100>
|
|
87
|
+
}
|
|
88
|
+
]
|
|
89
|
+
}
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
**Quan trọng**:
|
|
93
|
+
- `line` phải trỏ về dòng trong FILE PRIMARY (controller). Nếu vấn đề ở service nhưng symptom expose qua controller, dùng dòng controller gọi service đó.
|
|
94
|
+
- Mention rõ file support liên quan trong `message` (vd. "Controller `OwnerController.findOwner` gọi `OwnerService.find` ném `DataAccessException` không được catch").
|
|
95
|
+
|
|
96
|
+
## ⚠️ REPEAT CRITICAL RULES (đọc lại trước khi emit)
|
|
97
|
+
|
|
98
|
+
- **`line` BẮT BUỘC** trỏ về PRIMARY file (controller). KHÔNG dùng line từ support files.
|
|
99
|
+
- **SKIP intentional crash / demo / test endpoints** — class javadoc chứa `showcase`/`demo`/`example`/`intentional`/`crash test`, hoặc filename `*Crash*.java`/`*Demo*.java`/`*Example*.java`. Đây là code CỐ Ý crash, KHÔNG phải bug.
|
|
100
|
+
- **Thymeleaf `@Controller` (NOT `@RestController`)** có implicit handler là `templates/error.html` → KHÔNG flag "missing @ControllerAdvice" cho các app này.
|
|
101
|
+
- **High-signal only** — không flag normal read/not-found flow hoặc Optional `.get()` chỉ vì thiếu handler.
|
|
102
|
+
- **Scan đủ cluster** — trước khi emit missing-handler, xác nhận service method được PRIMARY gọi throw explicit domain/runtime exception và không có applicable `@ExceptionHandler`/`@ControllerAdvice`/`@RestControllerAdvice` trong support files. Global advice giờ được TIÊM vào mọi cluster → nếu thấy advice cover exception đó (kể cả ở package khác), KHÔNG flag missing-handler.
|
|
103
|
+
- Không hard-code theo tên controller/method; quyết định dựa trên flow lỗi thực tế trong cluster và ranh giới rule ở trên.
|
|
104
|
+
- Không report `SafeOperationsController`, `SafeOperationsService`, DTO safe flow, hoac `ApiExceptionAdvice` support-only file neu khong co direct evidence trong PRIMARY.
|
|
105
|
+
- Raw `e.getMessage()`/`e.toString()` chỉ vào rule này khi có map sai lỗi nghiệp vụ/user-correctable, swallow failure, hoặc wrong success semantics; nếu chỉ là security leak, để security rule.
|
|
106
|
+
- Nếu một catch block vừa generic catch vừa trả raw exception string, gộp thành 1 finding.
|
|
107
|
+
- **Mỗi finding distinct** — không duplicate message cho nhiều dòng.
|
|
108
|
+
- **Confidence `<50` → KHÔNG emit**.
|
|
109
|
+
|
|
110
|
+
### Hướng dẫn `confidence`
|
|
111
|
+
|
|
112
|
+
- **90-100**: gần như chắc chắn (empty catch block, generic `Exception` catch với log-only, controller gọi `repository.get()` không check Optional).
|
|
113
|
+
- **70-89**: pattern smell rõ nhưng cluster có thể thiếu file (vd. `@ControllerAdvice` ở module khác không thấy được trong cluster).
|
|
114
|
+
- **50-69**: borderline — flow nhìn risky nhưng có thể intentional.
|
|
115
|
+
- **<50**: KHÔNG emit.
|
|
116
|
+
|
|
117
|
+
KHÔNG inflate confidence. Nếu cluster không có đủ context (chỉ thấy controller, không thấy service body) → skip thay vì đoán.
|
|
118
|
+
|
|
119
|
+
Nếu cluster đã handle error đúng pattern: `{"violations": []}`.
|
|
120
|
+
|
|
121
|
+
Đừng giải thích. JSON thuần.
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
id: spring-boot/error-handling-completeness
|
|
2
|
+
# version history:
|
|
3
|
+
# v1 (Phase 13.2) — baseline prompt, 85.7% precision on spring-petclinic.
|
|
4
|
+
# v2 (Phase 13.3, 1.3.1) — FAILED experiment with mid-body FP-suppression
|
|
5
|
+
# rules. LLM ignored buried instructions (0/4 suppression rate). Reverted
|
|
6
|
+
# content to v1 but kept version bump as cache-buster.
|
|
7
|
+
# v3 (Phase 13.4, 1.4.1) — sandwich-prompt redesign applying the pattern
|
|
8
|
+
# validated by the original security flow rule (87.5% precision, Phase 13.3).
|
|
9
|
+
# CRITICAL RULES block at TOP (6 framing rules including the 2 FP
|
|
10
|
+
# carve-outs from v2 that failed buried) + REPEAT CRITICAL RULES block
|
|
11
|
+
# right before the OUTPUT schema. Per DEVELOPMENT.md Phase 13.3 lesson
|
|
12
|
+
# "sandwich-prompt pattern survives transformer attention falloff
|
|
13
|
+
# better than middle-of-body rules".
|
|
14
|
+
#
|
|
15
|
+
# Sandwich-pattern carve-outs in v3 (these are what v2 tried to add mid-body):
|
|
16
|
+
# (a) intentional crash / demo endpoints — javadoc keyword
|
|
17
|
+
# `showcase`/`demo`/`example`/`intentional`/`crash test` or filename
|
|
18
|
+
# `*Crash*.java`/`*Demo*.java`/`*Example*.java`. PetClinic
|
|
19
|
+
# CrashController is the canonical FP that v2 missed.
|
|
20
|
+
# (b) Thymeleaf MVC apps — `@Controller` (NOT `@RestController`) +
|
|
21
|
+
# project has `templates/error.html` → Spring Boot's implicit
|
|
22
|
+
# handler IS the handler. PetClinic VetController is the canonical
|
|
23
|
+
# FP class that v2 missed.
|
|
24
|
+
#
|
|
25
|
+
# Cache-buster: rule.version IS monotonic (Phase 13.3 lesson) — v3 bump
|
|
26
|
+
# invalidates v1+v2 cache entries on user installs upgrading from 1.3.0
|
|
27
|
+
# / 1.3.1 / 1.4.0 → fresh calls on first run after upgrade.
|
|
28
|
+
# v10 (Phase 15.5.3 hotfix, ADR-0017) — global @ControllerAdvice /
|
|
29
|
+
# @RestControllerAdvice is now INJECTED into every cluster by the
|
|
30
|
+
# assembler (it shares no import/domain-token edge with feature
|
|
31
|
+
# controllers, so it was previously invisible → false "missing handler"
|
|
32
|
+
# findings on well-handled JHipster/layered apps). Prompt gains a
|
|
33
|
+
# CRITICAL RULE: don't flag missing-handler for an exception a
|
|
34
|
+
# cluster-visible advice already covers. Version bump invalidates the
|
|
35
|
+
# stale findings cached against the pre-injection (smaller) clusters.
|
|
36
|
+
version: 10
|
|
37
|
+
kind: ai
|
|
38
|
+
title: "Error handling có đầy đủ và đúng pattern không?"
|
|
39
|
+
description: |
|
|
40
|
+
Per-cluster AI rule. The reviewer reads a Spring controller + its support
|
|
41
|
+
files (service, repository, exception handler if any) AS A UNIT and flags
|
|
42
|
+
bug-logic gaps that single-file rules can't see:
|
|
43
|
+
|
|
44
|
+
- Controller method has `try/catch` swallowing exceptions (empty catch, log-and-ignore).
|
|
45
|
+
- Service throws checked/unchecked exceptions không được handle ở controller layer
|
|
46
|
+
(không try/catch, không @ExceptionHandler, không @ControllerAdvice global).
|
|
47
|
+
- Error response không có wrapper / consistent shape (trả raw Exception.getMessage()
|
|
48
|
+
hoặc ResponseEntity với body trần).
|
|
49
|
+
- Catch block bắt `Exception` chung chung thay vì specific type.
|
|
50
|
+
- Repository / service ném exception nhưng caller controller assume happy-path
|
|
51
|
+
(không kiểm tra Optional empty, không catch DataIntegrityViolationException).
|
|
52
|
+
|
|
53
|
+
Là **bug-logic rule** (severity = warning) — không thay thế cho static rule
|
|
54
|
+
`transaction-on-service` / `validate-input`, mà bổ sung khía cạnh "flow đúng chưa".
|
|
55
|
+
|
|
56
|
+
Cần per-cluster context vì error-flow chỉ kiểm được khi đọc controller + service
|
|
57
|
+
+ (optional) exception handler cùng lúc. Single-file scope mặc định sẽ miss
|
|
58
|
+
case "controller gọi service không khai báo throws nhưng service throw runtime".
|
|
59
|
+
|
|
60
|
+
v3 prompt addresses two FP classes via sandwich-pattern carve-outs
|
|
61
|
+
(CRITICAL RULES block at top + REPEAT block at bottom):
|
|
62
|
+
(a) intentional crash/demo endpoints (PetClinic CrashController etc.);
|
|
63
|
+
(b) Thymeleaf `@Controller` apps with implicit `templates/error.html`.
|
|
64
|
+
|
|
65
|
+
If you still hit FPs on edge cases, use `rules.pathOverrides[]` as
|
|
66
|
+
escape hatch (Phase 12.5 feature) — see [REFERENCE §5 catalog](../../../docs/REFERENCE.md)
|
|
67
|
+
for example config.
|
|
68
|
+
|
|
69
|
+
severity: warning
|
|
70
|
+
category: error-handling
|
|
71
|
+
languages: [java]
|
|
72
|
+
scope: spring-boot
|
|
73
|
+
baseConfidence: 65
|
|
74
|
+
prompt: ./error-handling-completeness.prompt.md
|
|
75
|
+
contextScope: per-cluster
|
|
76
|
+
maxTokens: 1400
|
|
77
|
+
aiConfig:
|
|
78
|
+
tier: regular
|
|
79
|
+
prRouting:
|
|
80
|
+
group: spring-boundary-reliability-group
|
|
81
|
+
targetLayers: [controller, service]
|
|
82
|
+
triggers: ["try", "catch", "throw", "Exception", "rollback", "compensat", "retry", "timeout"]
|
|
83
|
+
riskWeight: 3
|
|
84
|
+
requiresContext: [diff, primaryFile, relatedController, relatedService]
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **event publishing / outbox consistency**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report "should publish an event" unless the cluster shows an existing event/outbox/publisher contract for this domain flow, or the visible method already publishes/sends an event incorrectly.
|
|
8
|
+
- NEVER report request-selected topic/queue/destination security boundary by itself; `io-boundary-risk` owns unsafe request-controlled destinations.
|
|
9
|
+
- NEVER report missing authorization/tenant scope, business invariant, cache stale, pagination, or raw exception handling here.
|
|
10
|
+
- NEVER report generic async exception/lost future by itself; `error-handling-completeness` owns async failure observation unless the main impact is DB/event consistency.
|
|
11
|
+
|
|
12
|
+
1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan architecture convention ngoai cluster.
|
|
13
|
+
2. **`line` BAT BUOC tro ve PRIMARY controller file**. Neu event gap nam trong service, dung dong controller goi flow do.
|
|
14
|
+
3. **Confidence `<50` -> KHONG emit**.
|
|
15
|
+
|
|
16
|
+
## ONLY REPORT WHEN co event/outbox consistency bug cu the
|
|
17
|
+
|
|
18
|
+
- Service mutates/persists domain state roi publish `ApplicationEventPublisher`, `KafkaTemplate`, `RabbitTemplate`, `StreamBridge`, webhook, hoac custom publisher **before transaction commit** without outbox, `@TransactionalEventListener(phase = AFTER_COMMIT)`, transactional producer, or after-commit hook.
|
|
19
|
+
- Visible multi-step mutation can rollback/fail after event publish/send, so consumers may observe state that DB never committed.
|
|
20
|
+
- Existing outbox/event contract is visible (outbox repository, `DomainEvent`, sibling helper, publisher method) but this state-changing flow persists the same domain object and skips the outbox/event step.
|
|
21
|
+
- Event payload is built from request DTO/transient object before persisted id/version/final status is known, while support files show consumers expect committed entity id/status.
|
|
22
|
+
- Direct publish/send is wrapped in catch/log-and-continue or ignored result so controller returns success even though the required event/outbox write failed, causing DB state and downstream state to diverge.
|
|
23
|
+
|
|
24
|
+
## KHONG flag
|
|
25
|
+
|
|
26
|
+
- Khong co event/outbox/publisher convention visible and method khong publish/send event.
|
|
27
|
+
- Publish is via outbox row saved in the same transaction, `@TransactionalEventListener(phase = AFTER_COMMIT)`, transaction synchronization after-commit hook, transactional Kafka producer, or clearly after successful commit.
|
|
28
|
+
- Event is purely in-process notification that does not represent durable downstream state and failure does not affect business consistency.
|
|
29
|
+
- Missing idempotency/duplicate retry without event ordering evidence: de `business-invariant-risk` xu ly neu side effect duplicate la business invariant.
|
|
30
|
+
- Request-selected topic/queue/cache key: de `io-boundary-risk` xu ly.
|
|
31
|
+
- Generic exception mapping/leak/swallow without DB/event consistency impact: de `error-handling-completeness` xu ly.
|
|
32
|
+
- Style/naming/refactor suggestion.
|
|
33
|
+
|
|
34
|
+
## Primary file
|
|
35
|
+
|
|
36
|
+
File: `{{file}}`
|
|
37
|
+
Language: `{{language}}`
|
|
38
|
+
|
|
39
|
+
```{{language}}
|
|
40
|
+
{{code}}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Support files cung cluster
|
|
44
|
+
|
|
45
|
+
Chi dung support files lam bang chung neu lien quan den controller PRIMARY.
|
|
46
|
+
|
|
47
|
+
```
|
|
48
|
+
{{cluster_files}}
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
{{cluster_summary}}
|
|
52
|
+
|
|
53
|
+
## Output yeu cau
|
|
54
|
+
|
|
55
|
+
Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
{
|
|
59
|
+
"violations": [
|
|
60
|
+
{
|
|
61
|
+
"line": <so nguyen duong, 1-based, trong PRIMARY>,
|
|
62
|
+
"endLine": <so nguyen duong | null>,
|
|
63
|
+
"message": "<<=200 ky tu, tieng Viet, neu event/outbox consistency gap>",
|
|
64
|
+
"suggestion": "<goi y fix | null>",
|
|
65
|
+
"confidence": <so nguyen 0-100>
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Neu khong co event/outbox consistency bug ro rang: `{"violations": []}`.
|
|
72
|
+
|
|
73
|
+
## REPEAT CRITICAL RULES
|
|
74
|
+
|
|
75
|
+
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
76
|
+
- Chi report khi co event/outbox/publisher evidence va DB/event consistency gap cu the.
|
|
77
|
+
- Khong duplicate `io-boundary-risk`, `business-invariant-risk`, `cache-consistency-risk`, `transaction-loop-risk`, `error-handling-completeness`, hoac static rules.
|
|
78
|
+
- Confidence `<50` -> KHONG emit.
|
|
79
|
+
|
|
80
|
+
Khong giai thich. JSON thuan.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: spring-boot/event-publishing-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Event Publishing Risk"
|
|
5
|
+
description: |
|
|
6
|
+
Per-cluster AI rule for domain-event and outbox consistency bugs:
|
|
7
|
+
events/messages published before DB commit, mutations that persist state but
|
|
8
|
+
skip the visible event/outbox contract, and publish/send flows that can leave
|
|
9
|
+
DB state and downstream consumers out of sync.
|
|
10
|
+
severity: warning
|
|
11
|
+
category: backend-eventing
|
|
12
|
+
languages: [java]
|
|
13
|
+
scope: spring-boot
|
|
14
|
+
baseConfidence: 60
|
|
15
|
+
prompt: ./event-publishing-risk.prompt.md
|
|
16
|
+
contextScope: per-cluster
|
|
17
|
+
maxTokens: 1800
|
|
18
|
+
aiConfig:
|
|
19
|
+
tier: regular
|
|
20
|
+
prRouting:
|
|
21
|
+
group: spring-boundary-reliability-group
|
|
22
|
+
targetLayers: [service, repository, config]
|
|
23
|
+
triggers: ["ApplicationEventPublisher", "publishEvent", "KafkaTemplate", "RabbitTemplate", "StreamBridge", "outbox", "DomainEvent", "@TransactionalEventListener", "send(", "publish"]
|
|
24
|
+
riskWeight: 4
|
|
25
|
+
requiresContext: [diff, primaryFile, relatedService, relatedRepository, relatedConfig]
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **filesystem / HTTP / queue boundary**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report generic SSRF/file risk unless request-controlled or request-selected data reaches an I/O sink in the visible cluster.
|
|
8
|
+
- NEVER report credential forwarding unless the credential itself is forwarded to an untrusted destination; `security-sensitive-data-risk` owns credential forwarding.
|
|
9
|
+
- NEVER report IDOR/tenant scope by itself; `ownership-scope-risk` owns pure scope gaps.
|
|
10
|
+
- NEVER report repository-loop or transaction issues; `transaction-loop-risk` owns those.
|
|
11
|
+
|
|
12
|
+
1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan convention ngoai cluster.
|
|
13
|
+
2. **`line` BAT BUOC tro ve PRIMARY controller file**. Neu sink nam trong service, dung dong controller goi flow do.
|
|
14
|
+
3. **Confidence `<50` -> KHONG emit**.
|
|
15
|
+
|
|
16
|
+
## Chi flag khi co I/O boundary bug cu the
|
|
17
|
+
|
|
18
|
+
- Request param/header/body/path variable (`file`, `filename`, `path`, `url`, `callback`, `webhook`, `destination`, `topic`, `queue`) di toi filesystem API: `Path.of`, `Paths.get`, `resolve`, `new File`, `Files.*`, `Resource`, upload/download/export/delete file ma khong normalize + base-dir containment + reject traversal.
|
|
19
|
+
- `Content-Disposition` dung filename/path tu request hoac DB record selected by request ma khong sanitize/escape.
|
|
20
|
+
- Request-controlled URL/host/path di toi `RestTemplate`, `WebClient`, `HttpClient`, Feign/dynamic URL, webhook sender ma khong scheme/host allowlist, internal-IP block, timeout, hoac destination policy.
|
|
21
|
+
- Request-selected id/list id load DB record chua URL/path/topic/queue/cache key, roi goi HTTP/file/queue/cache theo field stored do ma khong owner/tenant check va allowlist.
|
|
22
|
+
- Request-controlled cache key/topic/queue/destination dung de publish/enqueue/invalidate/read/write ma khong namespace theo tenant/user hoac allowlist.
|
|
23
|
+
|
|
24
|
+
## KHONG flag
|
|
25
|
+
|
|
26
|
+
- URL/path/filename constant hoac config-only khong den tu request/record selected by request.
|
|
27
|
+
- Da co normalize + baseDir containment (`normalize`, `startsWith(baseDir)`), filename sanitizer, host/scheme allowlist, internal-IP block, signed callback verification, hoac destination policy ro rang.
|
|
28
|
+
- Stored destination da duoc validate khi ghi va cluster hien ro allowlist/policy tai read/send path.
|
|
29
|
+
- Pure authorization/IDOR issue khong co I/O sink.
|
|
30
|
+
- Style/naming/refactor suggestion.
|
|
31
|
+
|
|
32
|
+
## Primary file
|
|
33
|
+
|
|
34
|
+
File: `{{file}}`
|
|
35
|
+
Language: `{{language}}`
|
|
36
|
+
|
|
37
|
+
```{{language}}
|
|
38
|
+
{{code}}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Support files cung cluster
|
|
42
|
+
|
|
43
|
+
Chi dung support files lam bang chung neu lien quan den controller PRIMARY.
|
|
44
|
+
|
|
45
|
+
```
|
|
46
|
+
{{cluster_files}}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
{{cluster_summary}}
|
|
50
|
+
|
|
51
|
+
## Output yeu cau
|
|
52
|
+
|
|
53
|
+
Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
|
|
54
|
+
|
|
55
|
+
```
|
|
56
|
+
{
|
|
57
|
+
"violations": [
|
|
58
|
+
{
|
|
59
|
+
"line": <so nguyen duong, 1-based, trong PRIMARY>,
|
|
60
|
+
"endLine": <so nguyen duong | null>,
|
|
61
|
+
"message": "<<=200 ky tu, tieng Viet, neu source -> sink + missing guard>",
|
|
62
|
+
"suggestion": "<goi y fix | null>",
|
|
63
|
+
"confidence": <so nguyen 0-100>
|
|
64
|
+
}
|
|
65
|
+
]
|
|
66
|
+
}
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Neu khong co I/O boundary bug ro rang: `{"violations": []}`.
|
|
70
|
+
|
|
71
|
+
## REPEAT CRITICAL RULES
|
|
72
|
+
|
|
73
|
+
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
74
|
+
- Chi report khi thay request-controlled/request-selected data va I/O sink cu the.
|
|
75
|
+
- Khong duplicate `ownership-scope-risk`, `transaction-loop-risk`, `business-invariant-risk`, `security-sensitive-data-risk`, `security-redirect-risk`, hoac static rules.
|
|
76
|
+
- Confidence `<50` -> KHONG emit.
|
|
77
|
+
|
|
78
|
+
Khong giai thich. JSON thuan.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: spring-boot/io-boundary-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Spring Boot filesystem/HTTP/queue boundary co rui ro khong?"
|
|
5
|
+
description: |
|
|
6
|
+
Per-cluster AI rule for request-controlled I/O boundaries in Spring Boot:
|
|
7
|
+
filesystem path traversal, unsafe Content-Disposition, direct or stored
|
|
8
|
+
outbound HTTP/SSRF destinations, and request-selected queue/cache/file
|
|
9
|
+
destinations without allowlist or tenant ownership checks.
|
|
10
|
+
severity: warning
|
|
11
|
+
category: backend-io
|
|
12
|
+
languages: [java]
|
|
13
|
+
scope: spring-boot
|
|
14
|
+
baseConfidence: 60
|
|
15
|
+
prompt: ./io-boundary-risk.prompt.md
|
|
16
|
+
contextScope: per-cluster
|
|
17
|
+
maxTokens: 1800
|
|
18
|
+
aiConfig:
|
|
19
|
+
tier: regular
|
|
20
|
+
prRouting:
|
|
21
|
+
group: spring-boundary-reliability-group
|
|
22
|
+
targetLayers: [controller, service, config]
|
|
23
|
+
triggers: ["RestTemplate", "WebClient", "FeignClient", "Kafka", "Rabbit", "S3", "MinIO", "HttpClient", "upload", "download"]
|
|
24
|
+
riskWeight: 4
|
|
25
|
+
requiresContext: [diff, primaryFile, relatedController, relatedService]
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **ownership / tenant / account scope**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report generic missing login/auth annotation. `spring-boot/security-authorization-risk` owns endpoint-level missing authorization.
|
|
8
|
+
- NEVER report a scope gap when repository/service query already includes principal/user/account/tenant/owner/deleted scope.
|
|
9
|
+
- NEVER report a DTO validation issue, SQL concat, transaction placement, raw exception response, SSRF, or filesystem issue.
|
|
10
|
+
- NEVER report benchmark negative controls (`SafeOperationsController`, `SafeOperationsService`, `ApiExceptionAdvice`, DTOs under `com.benchmark.badmvc.dto`) unless PRIMARY shows direct, unscoped data access evidence in the unsafe method itself.
|
|
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
|
+
|
|
13
|
+
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**.
|
|
16
|
+
|
|
17
|
+
## ONLY REPORT WHEN co ownership/scope bug cu the
|
|
18
|
+
|
|
19
|
+
- 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
|
+
- Entity/support file cho thay boundary nhu `ownerId`, `tenantId`, `accountId`, `createdBy`, `uploadedBy`, `assignee`, `approver`, `departmentId`, `deleted`, `deletedAt`, `isDeleted`.
|
|
21
|
+
- 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.
|
|
23
|
+
- Delete flow goi `deleteById`/hard delete trong khi entity co owner/tenant hoac soft-delete field, khong co owner/tenant/deleted check.
|
|
24
|
+
|
|
25
|
+
## KHONG flag
|
|
26
|
+
|
|
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
|
+
- Entity/service khong co bang chung ownership/tenant/account boundary.
|
|
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
|
+
- Safe DTO flow, `SafeOperations*`, hoac `ApiExceptionAdvice` support-only file neu khong co direct unsafe scoped data access trong PRIMARY.
|
|
31
|
+
- 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.
|
|
33
|
+
- Style/naming/refactor suggestion.
|
|
34
|
+
|
|
35
|
+
## Primary file
|
|
36
|
+
|
|
37
|
+
File: `{{file}}`
|
|
38
|
+
Language: `{{language}}`
|
|
39
|
+
|
|
40
|
+
```{{language}}
|
|
41
|
+
{{code}}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Support files cung cluster
|
|
45
|
+
|
|
46
|
+
Chi dung support files lam bang chung neu lien quan den controller PRIMARY.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
{{cluster_files}}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
{{cluster_summary}}
|
|
53
|
+
|
|
54
|
+
## Output yeu cau
|
|
55
|
+
|
|
56
|
+
Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
{
|
|
60
|
+
"violations": [
|
|
61
|
+
{
|
|
62
|
+
"line": <so nguyen duong, 1-based, trong PRIMARY>,
|
|
63
|
+
"endLine": <so nguyen duong | null>,
|
|
64
|
+
"message": "<<=200 ky tu, tieng Viet, neu controller/service flow + scope bi thieu>",
|
|
65
|
+
"suggestion": "<goi y fix | null>",
|
|
66
|
+
"confidence": <so nguyen 0-100>
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Neu khong co ownership/scope bug ro rang: `{"violations": []}`.
|
|
73
|
+
|
|
74
|
+
## REPEAT CRITICAL RULES
|
|
75
|
+
|
|
76
|
+
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
77
|
+
- Khong flag generic missing auth; chi flag owner/tenant/account/deleted scope gap co evidence.
|
|
78
|
+
- Khong flag list/findAll/pagination/unbounded collection; rule nay chi bat object-level owner/tenant/account scope gap.
|
|
79
|
+
- Khong flag benchmark negative controls: `SafeOperationsController`, `SafeOperationsService`, `ApiExceptionAdvice`, DTO safe flow, tru khi PRIMARY co direct unsafe data access evidence.
|
|
80
|
+
- Khong duplicate static rules hoac cac rule `io-boundary-risk`, `transaction-loop-risk`, `pagination-risk`, `business-invariant-risk`, `error-handling-completeness`.
|
|
81
|
+
- Confidence `<50` -> KHONG emit.
|
|
82
|
+
|
|
83
|
+
Khong giai thich. JSON thuan.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: spring-boot/ownership-scope-risk
|
|
2
|
+
version: 3
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Spring Boot ownership/tenant scope flow co rui ro khong?"
|
|
5
|
+
description: |
|
|
6
|
+
Per-cluster AI rule for owner/account/tenant scope gaps in Spring Boot
|
|
7
|
+
controller -> service -> repository flow. It flags IDOR, tenant/account
|
|
8
|
+
bypass, parent-child scope gaps, bulk scope gaps, and hard-delete
|
|
9
|
+
bypasses of visible soft-delete or ownership semantics.
|
|
10
|
+
severity: warning
|
|
11
|
+
category: backend-ownership
|
|
12
|
+
languages: [java]
|
|
13
|
+
scope: spring-boot
|
|
14
|
+
baseConfidence: 60
|
|
15
|
+
prompt: ./ownership-scope-risk.prompt.md
|
|
16
|
+
contextScope: per-cluster
|
|
17
|
+
maxTokens: 1800
|
|
18
|
+
aiConfig:
|
|
19
|
+
tier: regular
|
|
20
|
+
prRouting:
|
|
21
|
+
group: spring-security-risk-group
|
|
22
|
+
targetLayers: [controller, service, repository]
|
|
23
|
+
triggers: ["userId", "tenantId", "ownerId", "accountId", "organizationId", "scope", "findById"]
|
|
24
|
+
riskWeight: 5
|
|
25
|
+
requiresContext: [diff, primaryFile, relatedController, relatedService, relatedRepository]
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
Ban la senior Spring Boot reviewer. Danh gia review unit duoi day ve **pagination va result-window contract**.
|
|
2
|
+
|
|
3
|
+
## CRITICAL RULES
|
|
4
|
+
|
|
5
|
+
CRITICAL NON-VIOLATIONS:
|
|
6
|
+
|
|
7
|
+
- NEVER report owner/tenant/account scope gaps here; `ownership-scope-risk` owns object-scope and tenant filtering.
|
|
8
|
+
- NEVER report transaction atomicity or request-controlled loops with writes/external side effects here; `transaction-loop-risk` owns those.
|
|
9
|
+
- NEVER report missing cache/event/authorization/error-handling issues here.
|
|
10
|
+
- NEVER require pagination for clearly bounded enum/config/reference-data endpoints, health/admin maintenance endpoints, tests, demos, or generated samples.
|
|
11
|
+
|
|
12
|
+
1. **CHI report loi co bang chung cu the** trong PRIMARY hoac support files. Khong doan theo ten method neu khong thay data access/result flow.
|
|
13
|
+
2. **`line` BAT BUOC tro ve PRIMARY controller file**. Neu bug nam trong service/repository, dung dong controller goi flow do.
|
|
14
|
+
3. **Confidence `<50` -> KHONG emit**.
|
|
15
|
+
|
|
16
|
+
## ONLY REPORT WHEN co pagination/result-window bug cu the
|
|
17
|
+
|
|
18
|
+
- Public/list/search endpoint tra ve collection tu `findAll()`, `repository.find...()`, query khong `Pageable`/`Limit`/`Top`/`Slice`/`Page`, va khong co max result ro rang.
|
|
19
|
+
- Controller nhan `page`, `size`, `limit`, `offset` tu request nhung service/repository khong validate/clamp max size, cho phep request lay dataset qua lon.
|
|
20
|
+
- Controller nhan `Pageable`/`PageRequest` nhung service bo qua no va goi unpaged repository/query.
|
|
21
|
+
- In-memory pagination/filtering: service load full table/list roi moi `subList`, `stream().skip/limit`, `PageImpl`, hoac filter trong memory thay vi day pagination xuong DB.
|
|
22
|
+
- Export/download endpoint sync goi unbounded query de tra file/response lon, khong streaming/job/throttle/limit ro rang.
|
|
23
|
+
- Negative/overflow page/size/offset duoc tinh truc tiep tu request va truyen xuong query neu cluster cho thay co the gay loi runtime hoac full scan.
|
|
24
|
+
|
|
25
|
+
## KHONG flag
|
|
26
|
+
|
|
27
|
+
- Repository/service nhan `Pageable`, `PageRequest` co max size, `Slice`, `Page`, `Limit`, `Top`, query `setMaxResults`, hoac SQL/JPA limit ro rang.
|
|
28
|
+
- `@PageableDefault` chi nen duoc xem la safe khi cluster cung co max size/clamp hoac resolver max-page-size; neu chi default ma client van co the set size cuc lon thi co the flag.
|
|
29
|
+
- Endpoint tra small static config/list enum/reference values ro rang bounded.
|
|
30
|
+
- Async export job/streaming cursor/batch job co throttle hoac page loop bounded.
|
|
31
|
+
- Object-scope/tenant filter thieu ma pagination van co: de `ownership-scope-risk` xu ly.
|
|
32
|
+
- Loop qua request id/list co repository write/external call: de `transaction-loop-risk` xu ly.
|
|
33
|
+
- Style/naming/refactor suggestion.
|
|
34
|
+
|
|
35
|
+
## Primary file
|
|
36
|
+
|
|
37
|
+
File: `{{file}}`
|
|
38
|
+
Language: `{{language}}`
|
|
39
|
+
|
|
40
|
+
```{{language}}
|
|
41
|
+
{{code}}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Support files cung cluster
|
|
45
|
+
|
|
46
|
+
Chi dung support files lam bang chung neu lien quan den controller PRIMARY.
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
{{cluster_files}}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
{{cluster_summary}}
|
|
53
|
+
|
|
54
|
+
## Output yeu cau
|
|
55
|
+
|
|
56
|
+
Tra ve **JSON HOP LE DUY NHAT** (khong markdown fence, khong text khac) theo schema:
|
|
57
|
+
|
|
58
|
+
```
|
|
59
|
+
{
|
|
60
|
+
"violations": [
|
|
61
|
+
{
|
|
62
|
+
"line": <so nguyen duong, 1-based, trong PRIMARY>,
|
|
63
|
+
"endLine": <so nguyen duong | null>,
|
|
64
|
+
"message": "<<=200 ky tu, tieng Viet, neu list/search/export flow unbounded>",
|
|
65
|
+
"suggestion": "<goi y fix | null>",
|
|
66
|
+
"confidence": <so nguyen 0-100>
|
|
67
|
+
}
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Neu khong co pagination/result-window bug ro rang: `{"violations": []}`.
|
|
73
|
+
|
|
74
|
+
## REPEAT CRITICAL RULES
|
|
75
|
+
|
|
76
|
+
- `line` phai tro ve PRIMARY controller, khong dung line tu service/repository.
|
|
77
|
+
- Chi report khi thay endpoint/list/search/export + unbounded query/result-window evidence.
|
|
78
|
+
- Khong duplicate `ownership-scope-risk`, `transaction-loop-risk`, `io-boundary-risk`, `business-invariant-risk`, `cache-consistency-risk`, `event-publishing-risk`, hoac static rules.
|
|
79
|
+
- Confidence `<50` -> KHONG emit.
|
|
80
|
+
|
|
81
|
+
Khong giai thich. JSON thuan.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
id: spring-boot/pagination-risk
|
|
2
|
+
version: 1
|
|
3
|
+
kind: ai
|
|
4
|
+
title: "Pagination Risk"
|
|
5
|
+
description: |
|
|
6
|
+
Per-cluster AI rule for backend pagination and result-window risks:
|
|
7
|
+
public list/search/export endpoints that ignore Pageable/limit, unbounded
|
|
8
|
+
repository scans, in-memory pagination after loading full tables, and
|
|
9
|
+
request-controlled page size/offset without a visible maximum.
|
|
10
|
+
severity: warning
|
|
11
|
+
category: backend-pagination
|
|
12
|
+
languages: [java]
|
|
13
|
+
scope: spring-boot
|
|
14
|
+
baseConfidence: 60
|
|
15
|
+
prompt: ./pagination-risk.prompt.md
|
|
16
|
+
contextScope: per-cluster
|
|
17
|
+
maxTokens: 1800
|
|
18
|
+
aiConfig:
|
|
19
|
+
tier: regular
|
|
20
|
+
prRouting:
|
|
21
|
+
group: spring-data-consistency-group
|
|
22
|
+
targetLayers: [controller, service, repository]
|
|
23
|
+
triggers: ["Pageable", "PageRequest", "Page<", "Slice<", "findAll", "offset", "limit", "page", "size", "list", "search", "export"]
|
|
24
|
+
riskWeight: 4
|
|
25
|
+
requiresContext: [diff, primaryFile, relatedController, relatedService, relatedRepository]
|