@code-sentinel-cli/code-sentinel-cli 4.0.7 → 4.0.8
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 +17536 -12664
- package/dist/builtin-rules/{ai → fortify/ai}/angular/cross-feature-route-permission-drift.rule.yaml +4 -0
- package/dist/builtin-rules/{ai → fortify/ai}/angular/route-permission-flow.rule.yaml +4 -0
- package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/io-boundary-risk.rule.yaml +4 -0
- package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-redirect-risk.rule.yaml +4 -0
- package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-sensitive-data-risk.rule.yaml +4 -0
- package/dist/builtin-rules/{static → fortify/static}/angular/sensitive-input-masking.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/general/java-weak-randomness.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/general/no-client-identity-header.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/general/no-guessable-websql-database-name.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/general/no-reflective-access-override.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/general/no-sensitive-string-materialization.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-command-injection.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-path-traversal.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-servlet-xss.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-spel-injection.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-sql-string-concat.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-ssrf.rule.js +5 -1
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-weak-tls-protocol.rule.js +5 -1
- package/dist/builtin-rules/performance/static/spring-boot/http-client-without-timeout.rule.js +83 -0
- package/dist/builtin-rules/performance/static/spring-boot/open-in-view-enabled.rule.js +89 -0
- package/dist/builtin-rules/performance/static/spring-boot/transaction-holds-remote-call.rule.js +323 -0
- package/dist/builtin-rules/performance/static/spring-boot/unbounded-repository-fetch.rule.js +125 -0
- package/dist/builtin-rules/performance/static/spring-boot/xssf-workbook-for-export.rule.js +81 -0
- package/dist/builtin-rules/static/general/no-circular-import.rule.js +12 -2
- package/dist/builtin-rules/static/general/no-open-redirect.rule.js +7 -3
- package/dist/index.d.ts +273 -101
- package/dist/index.js +17538 -12666
- package/package.json +1 -1
- /package/dist/builtin-rules/{ai → fortify/ai}/angular/cross-feature-route-permission-drift.prompt.md +0 -0
- /package/dist/builtin-rules/{ai → fortify/ai}/angular/route-permission-flow.prompt.md +0 -0
- /package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/io-boundary-risk.prompt.md +0 -0
- /package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-redirect-risk.prompt.md +0 -0
- /package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-sensitive-data-risk.prompt.md +0 -0
package/dist/builtin-rules/performance/static/spring-boot/transaction-holds-remote-call.rule.js
ADDED
|
@@ -0,0 +1,323 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/performance/static/spring-boot/transaction-holds-remote-call.rule.ts
|
|
4
|
+
var REMOTE_CLIENT_TYPES = /* @__PURE__ */ new Set([
|
|
5
|
+
// HTTP clients (synchronous use)
|
|
6
|
+
"RestTemplate",
|
|
7
|
+
"WebClient",
|
|
8
|
+
// only `.block()` is synchronous — the callee gate below enforces it
|
|
9
|
+
// Viettel corpus integrations
|
|
10
|
+
"MinioClient",
|
|
11
|
+
"CarboneService",
|
|
12
|
+
// Carbone render HTTP API (tcct-be-base document export)
|
|
13
|
+
// Messaging — Synchronous send: `.send(…).get()` waits for the broker ack.
|
|
14
|
+
// v1 flags the `.get()` chain only when the receiver types to KafkaTemplate.
|
|
15
|
+
"KafkaTemplate"
|
|
16
|
+
]);
|
|
17
|
+
var MINIO_OFFLINE_METHODS = /* @__PURE__ */ new Set([
|
|
18
|
+
"getPresignedObjectUrl",
|
|
19
|
+
"getPresignedObjectUrlAsync"
|
|
20
|
+
]);
|
|
21
|
+
var WEBCLIENT_SYNC_METHODS = /* @__PURE__ */ new Set(["block", "blockFirst", "blockLast"]);
|
|
22
|
+
var WEBCLIENT_CHAIN_HEADS = /* @__PURE__ */ new Set([
|
|
23
|
+
"get",
|
|
24
|
+
"post",
|
|
25
|
+
"put",
|
|
26
|
+
"patch",
|
|
27
|
+
"delete",
|
|
28
|
+
"head",
|
|
29
|
+
"options",
|
|
30
|
+
"method"
|
|
31
|
+
]);
|
|
32
|
+
var KAFTA_BLOCK_METHODS = /* @__PURE__ */ new Set(["get"]);
|
|
33
|
+
function* walk(node, type) {
|
|
34
|
+
const stack = [node];
|
|
35
|
+
while (stack.length > 0) {
|
|
36
|
+
const cur = stack.pop();
|
|
37
|
+
if (!cur) continue;
|
|
38
|
+
if (cur.type === type) yield cur;
|
|
39
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
40
|
+
const child = cur.namedChild(i);
|
|
41
|
+
if (child) stack.push(child);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
var annotationNames = (decl) => {
|
|
46
|
+
const names = /* @__PURE__ */ new Set();
|
|
47
|
+
for (let i = 0; i < decl.namedChildCount; i++) {
|
|
48
|
+
const child = decl.namedChild(i);
|
|
49
|
+
if (!child || child.type !== "modifiers") continue;
|
|
50
|
+
for (let j = 0; j < child.namedChildCount; j++) {
|
|
51
|
+
const mod = child.namedChild(j);
|
|
52
|
+
if (!mod) continue;
|
|
53
|
+
if (mod.type !== "marker_annotation" && mod.type !== "annotation") continue;
|
|
54
|
+
const name = mod.childForFieldName("name")?.text ?? "";
|
|
55
|
+
const simple = name.split(".").pop() ?? name;
|
|
56
|
+
if (simple) names.add(simple);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return names;
|
|
60
|
+
};
|
|
61
|
+
function resolveRemoteReceivers(root) {
|
|
62
|
+
const receivers = /* @__PURE__ */ new Map();
|
|
63
|
+
const localFeignTypes = /* @__PURE__ */ new Set();
|
|
64
|
+
for (const iface of walk(root, "interface_declaration")) {
|
|
65
|
+
if (annotationNames(iface).has("FeignClient")) {
|
|
66
|
+
const n = iface.childForFieldName("name")?.text;
|
|
67
|
+
if (n) localFeignTypes.add(n);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const typeIsRemote = (typeName, root2) => {
|
|
71
|
+
if (localFeignTypes.has(typeName)) return "feign";
|
|
72
|
+
if (typeName === "KafkaTemplate") return "messaging";
|
|
73
|
+
if (typeName === "RestTemplate") return "rest-template";
|
|
74
|
+
if (typeName === "WebClient") return "web-client";
|
|
75
|
+
if (REMOTE_CLIENT_TYPES.has(typeName)) return "object-store";
|
|
76
|
+
if (/(FeignClient|Client)$/.test(typeName)) {
|
|
77
|
+
if (/^(Rest|Web|Http|OkHttp|Minio|Kafka|Carbone)/.test(typeName)) return null;
|
|
78
|
+
for (const imp of walk(root2, "import_declaration")) {
|
|
79
|
+
if (imp.text.includes(` ${typeName};`) || imp.text.includes(`.${typeName};`)) {
|
|
80
|
+
if (/java\.|javax\.|org\.springframework\.|com\.fasterxml|io\.minio|okhttp3|reactor\./.test(
|
|
81
|
+
imp.text
|
|
82
|
+
)) {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
return "feign";
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return null;
|
|
90
|
+
};
|
|
91
|
+
const typeNameOfDecl = (decl) => {
|
|
92
|
+
for (let i = 0; i < decl.namedChildCount; i++) {
|
|
93
|
+
const child = decl.namedChild(i);
|
|
94
|
+
if (!child) continue;
|
|
95
|
+
if (child.type === "type_identifier" || child.type === "scoped_type_identifier") {
|
|
96
|
+
return child.text;
|
|
97
|
+
}
|
|
98
|
+
if (child.type === "generic_type") {
|
|
99
|
+
const base = child.namedChild(0);
|
|
100
|
+
if (base) return base.text;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return "";
|
|
104
|
+
};
|
|
105
|
+
const declaratorNamesOfDecl = (decl) => {
|
|
106
|
+
const names = [];
|
|
107
|
+
for (let i = 0; i < decl.namedChildCount; i++) {
|
|
108
|
+
const child = decl.namedChild(i);
|
|
109
|
+
if (!child || child.type !== "variable_declarator") continue;
|
|
110
|
+
const id = child.namedChild(0);
|
|
111
|
+
if (id && (id.type === "identifier" || id.type === "field_access")) {
|
|
112
|
+
names.push(id.text);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return names;
|
|
116
|
+
};
|
|
117
|
+
for (const field of walk(root, "field_declaration")) {
|
|
118
|
+
const typeName = typeNameOfDecl(field);
|
|
119
|
+
if (!typeName) continue;
|
|
120
|
+
const channel = typeIsRemote(typeName, root);
|
|
121
|
+
if (!channel) continue;
|
|
122
|
+
for (const name of declaratorNamesOfDecl(field)) {
|
|
123
|
+
receivers.set(name, { name, channel });
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
for (const local of walk(root, "local_variable_declaration")) {
|
|
127
|
+
const typeName = typeNameOfDecl(local);
|
|
128
|
+
if (!typeName) continue;
|
|
129
|
+
const channel = typeIsRemote(typeName, root);
|
|
130
|
+
if (!channel) continue;
|
|
131
|
+
for (const name of declaratorNamesOfDecl(local)) {
|
|
132
|
+
receivers.set(name, { name, channel });
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
for (const param of walk(root, "formal_parameter")) {
|
|
136
|
+
let typeName = "";
|
|
137
|
+
let name = null;
|
|
138
|
+
for (let i = 0; i < param.namedChildCount; i++) {
|
|
139
|
+
const child = param.namedChild(i);
|
|
140
|
+
if (!child) continue;
|
|
141
|
+
if (child.type === "type_identifier" || child.type === "scoped_type_identifier") {
|
|
142
|
+
typeName = child.text;
|
|
143
|
+
} else if (child.type === "identifier" && !typeName) ; else if (child.type === "identifier" && typeName) {
|
|
144
|
+
name = child.text;
|
|
145
|
+
} else if (child.type === "void_type" || child.type === "array_type" || child.type === "generic_type") {
|
|
146
|
+
typeName = typeName || child.text.split("<")[0]?.trim() || child.text;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
if (!name) {
|
|
150
|
+
const ids = param.descendantsOfType("identifier");
|
|
151
|
+
name = ids[ids.length - 1]?.text ?? null;
|
|
152
|
+
const spread = param.descendantsOfType("spread_parameter");
|
|
153
|
+
if (spread.length > 0) name = null;
|
|
154
|
+
}
|
|
155
|
+
if (!name || !typeName) continue;
|
|
156
|
+
const channel = typeIsRemote(typeName, root);
|
|
157
|
+
if (channel) receivers.set(name, { name, channel });
|
|
158
|
+
}
|
|
159
|
+
return receivers;
|
|
160
|
+
}
|
|
161
|
+
function isSynchronousRemoteCall(method, channel) {
|
|
162
|
+
if (channel === "messaging") return false;
|
|
163
|
+
if (channel === "web-client") return false;
|
|
164
|
+
if (MINIO_OFFLINE_METHODS.has(method)) return false;
|
|
165
|
+
return true;
|
|
166
|
+
}
|
|
167
|
+
function isChainBlockingTail(call, method, channel) {
|
|
168
|
+
if (channel === "web-client") {
|
|
169
|
+
if (!WEBCLIENT_SYNC_METHODS.has(method)) return false;
|
|
170
|
+
let cur = call.childForFieldName("object") ?? null;
|
|
171
|
+
while (cur && cur.type === "method_invocation") {
|
|
172
|
+
if (WEBCLIENT_CHAIN_HEADS.has(cur.childForFieldName("name")?.text ?? "")) return true;
|
|
173
|
+
cur = cur.childForFieldName("object") ?? null;
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
if (channel === "messaging") {
|
|
178
|
+
if (!KAFTA_BLOCK_METHODS.has(method)) return false;
|
|
179
|
+
const recv = call.childForFieldName("object");
|
|
180
|
+
if (!recv || recv.type !== "method_invocation") return false;
|
|
181
|
+
return recv.childForFieldName("name")?.text === "send";
|
|
182
|
+
}
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
var transactionalMethods = (root) => {
|
|
186
|
+
const names = /* @__PURE__ */ new Set();
|
|
187
|
+
for (const m of walk(root, "method_declaration")) {
|
|
188
|
+
if (annotationNames(m).has("Transactional")) {
|
|
189
|
+
const n = m.childForFieldName("name")?.text;
|
|
190
|
+
if (n) names.add(n);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
return names;
|
|
194
|
+
};
|
|
195
|
+
var hasClassLevelTransactional = (root) => walk(root, "class_declaration").some((c) => annotationNames(c).has("Transactional"));
|
|
196
|
+
var enclosingMethod = (node) => {
|
|
197
|
+
let cur = node.parent;
|
|
198
|
+
while (cur) {
|
|
199
|
+
if (cur.type === "method_declaration") return cur;
|
|
200
|
+
cur = cur.parent;
|
|
201
|
+
}
|
|
202
|
+
return null;
|
|
203
|
+
};
|
|
204
|
+
var ASYNC_ANNOTATIONS = /* @__PURE__ */ new Set(["Async"]);
|
|
205
|
+
var rule = {
|
|
206
|
+
id: "spring-boot/transaction-holds-remote-call",
|
|
207
|
+
version: 1,
|
|
208
|
+
kind: "static-ts",
|
|
209
|
+
pack: "performance",
|
|
210
|
+
title: "G\u1ECDi m\u1EA1ng \u0111\u1ED3ng b\u1ED9 trong ph\u1EA1m vi @Transactional \u2014 gi\u1EEF k\u1EBFt n\u1ED1i DB",
|
|
211
|
+
description: "Ph\u1EA1m vi transaction gi\u1EEF k\u1EBFt n\u1ED1i DB (pool HikariCP) su\u1ED1t th\u1EDDi gian ch\u1EA1y, k\u1EC3 c\u1EA3 l\xFAc ch\u1EDD l\u1EDDi g\u1ECDi m\u1EA1ng \u0111\u1ED3ng b\u1ED9 (HTTP/Feign/MinIO). M\u1ED7i gi\xE2y ch\u1EDD remote l\xE0 m\u1ED9t gi\xE2y k\u1EBFt n\u1ED1i kh\xF4ng d\xF9ng \u0111\u01B0\u1EE3c cho request kh\xE1c; d\u01B0\u1EDBi t\u1EA3i \u0111\u1ED3ng th\u1EDDi pool c\xF3 th\u1EC3 c\u1EA1n. \u0110o b\u1EB1ng fixture (ADR-0087 V2): REQUIRES_NEW/NOT_SUPPORTED \u1EDF callee v\xE0 afterCommit() KH\xD4NG tr\u1EA3 k\u1EBFt n\u1ED1i ngo\xE0i.",
|
|
212
|
+
severity: "warning",
|
|
213
|
+
category: "performance",
|
|
214
|
+
languages: ["java"],
|
|
215
|
+
scope: "spring-boot",
|
|
216
|
+
requires: "syntactic",
|
|
217
|
+
baseConfidence: 80,
|
|
218
|
+
examples: {
|
|
219
|
+
good: [
|
|
220
|
+
{
|
|
221
|
+
code: [
|
|
222
|
+
"@Service",
|
|
223
|
+
"public class ExportService {",
|
|
224
|
+
" private final PortalClient portalClient;",
|
|
225
|
+
"",
|
|
226
|
+
" public byte[] export(Long id) {",
|
|
227
|
+
" List<Item> items = portalClient.fetchItems(id); // I/O ngo\xE0i transaction",
|
|
228
|
+
" return self.writeInTransaction(items); // transaction ng\u1EAFn, kh\xF4ng I/O",
|
|
229
|
+
" }",
|
|
230
|
+
"",
|
|
231
|
+
" @Transactional",
|
|
232
|
+
" public byte[] writeInTransaction(List<Item> items) { /* ch\u1EC9 ghi DB */ return null;",
|
|
233
|
+
" }",
|
|
234
|
+
"}"
|
|
235
|
+
].join("\n"),
|
|
236
|
+
explanation: "L\u1EDDi g\u1ECDi m\u1EA1ng di\u1EC5n ra TR\u01AF\u1EDAC khi transaction m\u1EDF \u2014 k\u1EBFt n\u1ED1i DB ch\u1EC9 b\u1ECB gi\u1EEF trong ph\u1EA7n ghi."
|
|
237
|
+
}
|
|
238
|
+
],
|
|
239
|
+
bad: [
|
|
240
|
+
{
|
|
241
|
+
code: [
|
|
242
|
+
"@Service",
|
|
243
|
+
"@Transactional",
|
|
244
|
+
"public class FundService {",
|
|
245
|
+
" private final CarboneService carboneService;",
|
|
246
|
+
"",
|
|
247
|
+
" public byte[] detailExport(ExportFundDetailsRequest request) {",
|
|
248
|
+
" // \u0110ang n\u1EB1m trong transaction c\u1EE7a class \u2014 k\u1EBFt n\u1ED1i DB b\u1ECB gi\u1EEF su\u1ED1t l\xFAc ch\u1EDD Carbone render.",
|
|
249
|
+
" return carboneService.renderReport(output, template, fileName, XLSX);",
|
|
250
|
+
" }",
|
|
251
|
+
"}"
|
|
252
|
+
].join("\n"),
|
|
253
|
+
explanation: "`@Transactional` c\u1EA5p class m\u1EDF transaction cho m\u1ECDi method public; l\u1EDDi g\u1ECDi render HTTP b\xEAn trong khi\u1EBFn k\u1EBFt n\u1ED1i DB ch\u1EDD theo \u0111\u1ED9 tr\u1EC5 c\u1EE7a Carbone."
|
|
254
|
+
}
|
|
255
|
+
]
|
|
256
|
+
},
|
|
257
|
+
check(ctx) {
|
|
258
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
259
|
+
const root = tree.rootNode;
|
|
260
|
+
const receivers = resolveRemoteReceivers(root);
|
|
261
|
+
if (receivers.size === 0) return [];
|
|
262
|
+
const txMethods = transactionalMethods(root);
|
|
263
|
+
const classLevelTx = hasClassLevelTransactional(root);
|
|
264
|
+
if (txMethods.size === 0 && !classLevelTx) return [];
|
|
265
|
+
const findings = [];
|
|
266
|
+
for (const call of walk(root, "method_invocation")) {
|
|
267
|
+
const method = call.childForFieldName("name")?.text;
|
|
268
|
+
if (!method) continue;
|
|
269
|
+
const receiverNode = call.childForFieldName("object");
|
|
270
|
+
if (!receiverNode) continue;
|
|
271
|
+
let baseName = null;
|
|
272
|
+
let channel = null;
|
|
273
|
+
let isChainTail = false;
|
|
274
|
+
if (receiverNode.type === "identifier") {
|
|
275
|
+
const receiver = receivers.get(receiverNode.text);
|
|
276
|
+
if (!receiver) continue;
|
|
277
|
+
baseName = receiverNode.text;
|
|
278
|
+
channel = receiver.channel;
|
|
279
|
+
} else if (receiverNode.type === "method_invocation") {
|
|
280
|
+
let base = receiverNode;
|
|
281
|
+
let chainDepth = 0;
|
|
282
|
+
while (base && base.type === "method_invocation" && chainDepth < 20) {
|
|
283
|
+
base = base.childForFieldName("object") ?? null;
|
|
284
|
+
chainDepth++;
|
|
285
|
+
}
|
|
286
|
+
if (!base) continue;
|
|
287
|
+
const name = base.type === "identifier" ? base.text : base.type === "field_access" ? base.childForFieldName("field")?.text ?? null : null;
|
|
288
|
+
if (!name) continue;
|
|
289
|
+
const receiver = receivers.get(name);
|
|
290
|
+
if (!receiver) continue;
|
|
291
|
+
isChainTail = true;
|
|
292
|
+
baseName = name;
|
|
293
|
+
channel = receiver.channel;
|
|
294
|
+
} else {
|
|
295
|
+
continue;
|
|
296
|
+
}
|
|
297
|
+
const syncRemote = isChainTail ? isChainBlockingTail(call, method, channel) : isSynchronousRemoteCall(method, channel);
|
|
298
|
+
if (!syncRemote) continue;
|
|
299
|
+
const owner = enclosingMethod(call);
|
|
300
|
+
if (!owner) continue;
|
|
301
|
+
const ownerName = owner.childForFieldName("name")?.text ?? "";
|
|
302
|
+
const inTxBoundary = classLevelTx || txMethods.has(ownerName);
|
|
303
|
+
if (!inTxBoundary) continue;
|
|
304
|
+
if ([...annotationNames(owner)].some((a) => ASYNC_ANNOTATIONS.has(a))) continue;
|
|
305
|
+
findings.push({
|
|
306
|
+
message: `G\u1ECDi m\u1EA1ng \u0111\u1ED3ng b\u1ED9 \`${baseName}.${method}(\u2026)\` trong ph\u1EA1m vi @Transactional ${classLevelTx && !txMethods.has(ownerName) ? "(c\u1EA5p class)" : `(method \`${ownerName}\`)`}: k\u1EBFt n\u1ED1i DB b\u1ECB gi\u1EEF su\u1ED1t th\u1EDDi gian ch\u1EDD I/O; m\u1EE9c \u1EA3nh h\u01B0\u1EDFng ph\u1EE5 thu\u1ED9c s\u1ED1 request \u0111\u1ED3ng th\u1EDDi v\xE0 \u0111\u1ED9 tr\u1EC5 d\u1ECBch v\u1EE5 \u0111\xEDch.`,
|
|
307
|
+
file: ctx.file.path,
|
|
308
|
+
range: {
|
|
309
|
+
line: call.startPosition.row + 1,
|
|
310
|
+
column: call.startPosition.column + 1
|
|
311
|
+
},
|
|
312
|
+
snippet: call.text.length > 200 ? `${call.text.slice(0, 200)}\u2026` : call.text,
|
|
313
|
+
suggestion: "\u0110\u01B0a I/O ra ngo\xE0i transaction: g\u1ECDi remote tr\u01B0\u1EDBc khi m\u1EDF transaction (ho\u1EB7c sau commit), ho\u1EB7c t\xE1ch method ch\u1EE9a I/O kh\u1ECFi method @Transactional. L\u01B0u \xFD (\u0111o trong ADR-0087 V2): b\u1ECDc callee b\u1EB1ng REQUIRES_NEW/NOT_SUPPORTED ho\u1EB7c afterCommit KH\xD4NG tr\u1EA3 k\u1EBFt n\u1ED1i c\u1EE7a transaction ngo\xE0i.",
|
|
314
|
+
confidence: 80
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
return findings;
|
|
318
|
+
}
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
export { rule };
|
|
322
|
+
//# sourceMappingURL=transaction-holds-remote-call.rule.js.map
|
|
323
|
+
//# sourceMappingURL=transaction-holds-remote-call.rule.js.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/performance/static/spring-boot/unbounded-repository-fetch.rule.ts
|
|
4
|
+
var REPO_TYPE_SUFFIX = /(Repository|Repo)$/;
|
|
5
|
+
function* walk(node, type) {
|
|
6
|
+
const stack = [node];
|
|
7
|
+
while (stack.length > 0) {
|
|
8
|
+
const cur = stack.pop();
|
|
9
|
+
if (!cur) continue;
|
|
10
|
+
if (cur.type === type) yield cur;
|
|
11
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
12
|
+
const child = cur.namedChild(i);
|
|
13
|
+
if (child) stack.push(child);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
var typeNameOfDecl = (decl) => {
|
|
18
|
+
for (let i = 0; i < decl.namedChildCount; i++) {
|
|
19
|
+
const child = decl.namedChild(i);
|
|
20
|
+
if (!child) continue;
|
|
21
|
+
if (child.type === "type_identifier" || child.type === "scoped_type_identifier") {
|
|
22
|
+
return child.text;
|
|
23
|
+
}
|
|
24
|
+
if (child.type === "generic_type") {
|
|
25
|
+
const base = child.namedChild(0);
|
|
26
|
+
if (base) return base.text;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return "";
|
|
30
|
+
};
|
|
31
|
+
var declaratorNamesOfDecl = (decl) => {
|
|
32
|
+
const names = [];
|
|
33
|
+
for (let i = 0; i < decl.namedChildCount; i++) {
|
|
34
|
+
const child = decl.namedChild(i);
|
|
35
|
+
if (!child || child.type !== "variable_declarator") continue;
|
|
36
|
+
const id = child.namedChild(0);
|
|
37
|
+
if (id && (id.type === "identifier" || id.type === "field_access")) names.push(id.text);
|
|
38
|
+
}
|
|
39
|
+
return names;
|
|
40
|
+
};
|
|
41
|
+
function resolveRepositoryReceivers(root) {
|
|
42
|
+
const receivers = /* @__PURE__ */ new Set();
|
|
43
|
+
for (const declType of ["field_declaration", "local_variable_declaration"]) {
|
|
44
|
+
for (const decl of walk(root, declType)) {
|
|
45
|
+
const typeName = typeNameOfDecl(decl);
|
|
46
|
+
if (!typeName || !REPO_TYPE_SUFFIX.test(typeName)) continue;
|
|
47
|
+
for (const name of declaratorNamesOfDecl(decl)) receivers.add(name);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
for (const param of walk(root, "formal_parameter")) {
|
|
51
|
+
const typeName = typeNameOfDecl(param);
|
|
52
|
+
if (!typeName || !REPO_TYPE_SUFFIX.test(typeName)) continue;
|
|
53
|
+
const ids = param.descendantsOfType("identifier");
|
|
54
|
+
const name = ids[ids.length - 1]?.text;
|
|
55
|
+
if (name && !param.descendantsOfType("spread_parameter").length) receivers.add(name);
|
|
56
|
+
}
|
|
57
|
+
return receivers;
|
|
58
|
+
}
|
|
59
|
+
var rule = {
|
|
60
|
+
id: "spring-boot/unbounded-repository-fetch",
|
|
61
|
+
version: 1,
|
|
62
|
+
kind: "static-ts",
|
|
63
|
+
pack: "performance",
|
|
64
|
+
title: "Fetch repository kh\xF4ng gi\u1EDBi h\u1EA1n \u2014 findAll() n\u1EA1p to\xE0n b\u1EA3ng v\xE0o b\u1ED9 nh\u1EDB",
|
|
65
|
+
description: "G\u1ECDi `findAll()` kh\xF4ng \u0111\u1ED1i s\u1ED1 tr\xEAn repository n\u1EA1p TO\xC0N B\u1ED8 b\u1EA3ng v\xE0o b\u1ED9 nh\u1EDB r\u1ED3i chuy\u1EC3n qua DTO/JSON. Chi ph\xED t\u0103ng theo s\u1ED1 d\xF2ng c\u1EE7a b\u1EA3ng, kh\xF4ng theo y\xEAu c\u1EA7u \u2014 b\u1EA3ng l\u1EDBn d\u1EA7n th\xEC endpoint ch\u1EADm d\u1EA7n v\xE0 t\u1ED1n RAM d\u1EA7n kh\xF4ng c\u1EA7n \u0111\u1ED5i code. Thay b\u1EB1ng ph\xE2n trang (`Pageable`), `findAllById(ids)` gi\u1EDBi h\u1EA1n t\u1EADp id, ho\u1EB7c query c\xF3 `LIMIT`/\u0111i\u1EC1u ki\u1EC7n thu h\u1EB9p.",
|
|
66
|
+
severity: "warning",
|
|
67
|
+
category: "performance",
|
|
68
|
+
languages: ["java"],
|
|
69
|
+
scope: "spring-boot",
|
|
70
|
+
requires: "syntactic",
|
|
71
|
+
baseConfidence: 75,
|
|
72
|
+
examples: {
|
|
73
|
+
good: [
|
|
74
|
+
{
|
|
75
|
+
code: [
|
|
76
|
+
"public Page<CitizenDTO> getCitizens(Pageable pageable) {",
|
|
77
|
+
" return citizenRepository.findAll(pageable).map(citizenMapper::toDto);",
|
|
78
|
+
"}"
|
|
79
|
+
].join("\n"),
|
|
80
|
+
explanation: "C\xF3 Pageable \u2014 s\u1ED1 d\xF2ng l\u1EA5y v\u1EC1 b\u1ECB ch\u1EB7n theo trang."
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
bad: [
|
|
84
|
+
{
|
|
85
|
+
code: [
|
|
86
|
+
"public List<CitizenDTO> exportData() {",
|
|
87
|
+
" var entities = citizenRepository.findAll(); // to\xE0n b\u1EA3ng",
|
|
88
|
+
" return entities.stream().map(citizenMapper::toDto).toList();",
|
|
89
|
+
"}"
|
|
90
|
+
].join("\n"),
|
|
91
|
+
explanation: "findAll() tr\u1EA7n \u2014 kh\xF4ng ph\xE2n trang, kh\xF4ng gi\u1EDBi h\u1EA1n; b\u1EA3ng 1 tri\u1EC7u d\xF2ng th\xEC 1 tri\u1EC7u d\xF2ng v\xE0o RAM."
|
|
92
|
+
}
|
|
93
|
+
]
|
|
94
|
+
},
|
|
95
|
+
check(ctx) {
|
|
96
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
97
|
+
const root = tree.rootNode;
|
|
98
|
+
const receivers = resolveRepositoryReceivers(root);
|
|
99
|
+
if (receivers.size === 0) return [];
|
|
100
|
+
const findings = [];
|
|
101
|
+
for (const call of walk(root, "method_invocation")) {
|
|
102
|
+
const receiverNode = call.childForFieldName("object");
|
|
103
|
+
if (!receiverNode || receiverNode.type !== "identifier") continue;
|
|
104
|
+
if (!receivers.has(receiverNode.text)) continue;
|
|
105
|
+
const method = call.childForFieldName("name")?.text;
|
|
106
|
+
if (method !== "findAll") continue;
|
|
107
|
+
const args = call.childForFieldName("arguments");
|
|
108
|
+
const argCount = args ? args.namedChildCount : 0;
|
|
109
|
+
if (argCount > 0) continue;
|
|
110
|
+
findings.push({
|
|
111
|
+
message: `\`${receiverNode.text}.findAll()\` kh\xF4ng gi\u1EDBi h\u1EA1n \u2014 n\u1EA1p to\xE0n b\u1ED9 b\u1EA3ng v\xE0o b\u1ED9 nh\u1EDB; m\u1EE9c \u1EA3nh h\u01B0\u1EDFng t\u0103ng theo s\u1ED1 d\xF2ng c\u1EE7a b\u1EA3ng (kh\xF4ng theo y\xEAu c\u1EA7u). D\xF9ng \`Pageable\`, \`findAllById(ids)\`, ho\u1EB7c query c\xF3 \u0111i\u1EC1u ki\u1EC7n thu h\u1EB9p n\u1EBFu danh s\xE1ch c\xF3 th\u1EC3 l\u1EDBn.`,
|
|
112
|
+
file: ctx.file.path,
|
|
113
|
+
range: { line: call.startPosition.row + 1, column: call.startPosition.column + 1 },
|
|
114
|
+
snippet: call.text.length > 200 ? `${call.text.slice(0, 200)}\u2026` : call.text,
|
|
115
|
+
suggestion: "Ph\xE2n trang b\u1EB1ng `Pageable` cho endpoint danh s\xE1ch; v\u1EDBi export, gi\u1EDBi h\u1EA1n theo batch/streaming (`Stream<t>` + `@Transactional(readOnly)`) thay v\xEC list to\xE0n b\u1EA3ng.",
|
|
116
|
+
confidence: 75
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return findings;
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export { rule };
|
|
124
|
+
//# sourceMappingURL=unbounded-repository-fetch.rule.js.map
|
|
125
|
+
//# sourceMappingURL=unbounded-repository-fetch.rule.js.map
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/performance/static/spring-boot/xssf-workbook-for-export.rule.ts
|
|
4
|
+
function* walk(node, type) {
|
|
5
|
+
const stack = [node];
|
|
6
|
+
while (stack.length > 0) {
|
|
7
|
+
const cur = stack.pop();
|
|
8
|
+
if (!cur) continue;
|
|
9
|
+
if (cur.type === type) yield cur;
|
|
10
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
11
|
+
const child = cur.namedChild(i);
|
|
12
|
+
if (child) stack.push(child);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
var rule = {
|
|
17
|
+
id: "spring-boot/xssf-workbook-for-export",
|
|
18
|
+
version: 1,
|
|
19
|
+
kind: "static-ts",
|
|
20
|
+
pack: "performance",
|
|
21
|
+
title: "XSSFWorkbook (DOM \u0111\u1EA7y \u0111\u1EE7 trong RAM) cho \u0111\u01B0\u1EDDng xu\u1EA5t file \u2014 dangers RAM khi export l\u1EDBn",
|
|
22
|
+
description: "`new XSSFWorkbook()` kh\xF4ng tham s\u1ED1 d\u1EF1ng TO\xC0N B\u1ED8 m\xF4 h\xECnh workbook trong heap; xu\u1EA5t danh s\xE1ch l\u1EDBn (th\u01B0\u1EDDng \u0111\xE3 n\u1EA1p kh\xF4ng gi\u1EDBi h\u1EA1n tr\u01B0\u1EDBc \u0111\xF3) c\u1ED9ng th\xEAm chi ph\xED object POI m\u1ED7i \xF4. `SXSSFWorkbook` gi\u1EEF c\u1EEDa s\u1ED5 tr\u01B0\u1EE3t v\xE0 ghi sheet ra file t\u1EA1m \u2014 b\u1ED9 nh\u1EDB c\xF3 ch\u1EB7n b\u1EA5t k\u1EC3 s\u1ED1 d\xF2ng.",
|
|
23
|
+
severity: "warning",
|
|
24
|
+
category: "performance",
|
|
25
|
+
languages: ["java"],
|
|
26
|
+
scope: "spring-boot",
|
|
27
|
+
requires: "syntactic",
|
|
28
|
+
baseConfidence: 75,
|
|
29
|
+
examples: {
|
|
30
|
+
good: [
|
|
31
|
+
{
|
|
32
|
+
code: [
|
|
33
|
+
"try (Workbook wb = new SXSSFWorkbook(100); ByteArrayOutputStream out = new ByteArrayOutputStream()) {",
|
|
34
|
+
" //\u7A97\u53E3 100 d\xF2ng: c\xE1c sheet c\u0169 \u0111\xE3 flush ra file t\u1EA1m",
|
|
35
|
+
' Sheet sheet = wb.createSheet("export");',
|
|
36
|
+
" writeRows(sheet, rows);",
|
|
37
|
+
"}"
|
|
38
|
+
].join("\n"),
|
|
39
|
+
explanation: "SXSSFWorkbook: b\u1ED9 nh\u1EDB theo c\u1EEDa s\u1ED5, kh\xF4ng theo t\u1ED5ng s\u1ED1 d\xF2ng."
|
|
40
|
+
}
|
|
41
|
+
],
|
|
42
|
+
bad: [
|
|
43
|
+
{
|
|
44
|
+
code: [
|
|
45
|
+
"try (Workbook wb = new XSSFWorkbook(); ByteArrayOutputStream out = new ByteArrayOutputStream()) {",
|
|
46
|
+
' Sheet sheet = wb.createSheet("export");',
|
|
47
|
+
" writeRows(sheet, allRowsInMemory); // DOM \u0111\u1EA7y \u0111\u1EE7 c\u1EE7a m\u1ECDi d\xF2ng",
|
|
48
|
+
"}"
|
|
49
|
+
].join("\n"),
|
|
50
|
+
explanation: "XSSFWorkbook(): to\xE0n b\u1ED9 workbook n\u1EB1m trong RAM \u2014 grows theo s\u1ED1 d\xF2ng xu\u1EA5t."
|
|
51
|
+
}
|
|
52
|
+
]
|
|
53
|
+
},
|
|
54
|
+
check(ctx) {
|
|
55
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
56
|
+
const findings = [];
|
|
57
|
+
for (const creation of walk(tree.rootNode, "object_creation_expression")) {
|
|
58
|
+
const typeNode = creation.childForFieldName("type");
|
|
59
|
+
if (!typeNode || typeNode.text !== "XSSFWorkbook") continue;
|
|
60
|
+
const args = creation.childForFieldName("arguments");
|
|
61
|
+
const argCount = args ? args.namedChildCount : 0;
|
|
62
|
+
if (argCount > 0) continue;
|
|
63
|
+
findings.push({
|
|
64
|
+
message: "`new XSSFWorkbook()` d\u1EF1ng to\xE0n b\u1ED9 workbook trong b\u1ED9 nh\u1EDB \u2014 m\u1EE9c ti\xEAu RAM t\u0103ng theo s\u1ED1 d\xF2ng xu\u1EA5t (POI th\xEAm object overhead m\u1ED7i \xF4). V\u1EDBi export l\u1EDBn, d\xF9ng `SXSSFWorkbook(window)` \u0111\u1EC3 ghi streaming; `XSSFWorkbook(InputStream)` (\u0111\u1ECDc file) l\xE0 tr\u01B0\u1EDDng h\u1EE3p kh\xE1c, kh\xF4ng b\u1ECB b\xE1o \u1EDF \u0111\xE2y.",
|
|
65
|
+
file: ctx.file.path,
|
|
66
|
+
range: {
|
|
67
|
+
line: creation.startPosition.row + 1,
|
|
68
|
+
column: creation.startPosition.column + 1
|
|
69
|
+
},
|
|
70
|
+
snippet: creation.text,
|
|
71
|
+
suggestion: "Thay `new XSSFWorkbook()` b\u1EB1ng `new SXSSFWorkbook(100)` (c\u1EEDa s\u1ED5 d\xF2ng flush ra file t\u1EA1m) tr\xEAn \u0111\u01B0\u1EDDng xu\u1EA5t file; \u0111\u1EB7t `wb.dispose()` sau khi ghi xong v\u1EDBi SXSSF.",
|
|
72
|
+
confidence: 75
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
return findings;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export { rule };
|
|
80
|
+
//# sourceMappingURL=xssf-workbook-for-export.rule.js.map
|
|
81
|
+
//# sourceMappingURL=xssf-workbook-for-export.rule.js.map
|
|
@@ -2,6 +2,16 @@ import { findDirectedCycles } from '@code-sentinel/core';
|
|
|
2
2
|
|
|
3
3
|
// builtin-rules/static/general/no-circular-import.rule.ts
|
|
4
4
|
var importLikeKinds = ["import", "re-export"];
|
|
5
|
+
var cyclesByGraph = /* @__PURE__ */ new WeakMap();
|
|
6
|
+
var cyclesForGraph = (graph) => {
|
|
7
|
+
const cachedCycles = cyclesByGraph.get(graph);
|
|
8
|
+
if (cachedCycles) {
|
|
9
|
+
return cachedCycles;
|
|
10
|
+
}
|
|
11
|
+
const cycles = findDirectedCycles(graph, { edgeKinds: importLikeKinds });
|
|
12
|
+
cyclesByGraph.set(graph, cycles);
|
|
13
|
+
return cycles;
|
|
14
|
+
};
|
|
5
15
|
var formatCycle = (paths) => paths.join(" -> ");
|
|
6
16
|
var rule = {
|
|
7
17
|
id: "general/no-circular-import",
|
|
@@ -18,7 +28,7 @@ var rule = {
|
|
|
18
28
|
baseConfidence: 95,
|
|
19
29
|
check(ctx) {
|
|
20
30
|
if (!ctx.astGraph) return [];
|
|
21
|
-
const cycles =
|
|
31
|
+
const cycles = cyclesForGraph(ctx.astGraph);
|
|
22
32
|
const findings = [];
|
|
23
33
|
for (const cycle of cycles) {
|
|
24
34
|
const primaryPath = cycle.paths[0];
|
|
@@ -34,6 +44,6 @@ var rule = {
|
|
|
34
44
|
}
|
|
35
45
|
};
|
|
36
46
|
|
|
37
|
-
export { rule };
|
|
47
|
+
export { cyclesForGraph, rule };
|
|
38
48
|
//# sourceMappingURL=no-circular-import.rule.js.map
|
|
39
49
|
//# sourceMappingURL=no-circular-import.rule.js.map
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
// builtin-rules/static/general/no-open-redirect.rule.ts
|
|
2
2
|
var OPEN_REDIRECT_SINK_IDS = /* @__PURE__ */ new Set([
|
|
3
3
|
"general/location-redirect",
|
|
4
|
-
"angular/router-navigate"
|
|
4
|
+
"angular/router-navigate",
|
|
5
|
+
"angular/location-assign-replace",
|
|
6
|
+
"angular/window-open"
|
|
5
7
|
]);
|
|
6
8
|
var SINK_LABEL = {
|
|
7
9
|
"general/location-redirect": "location.href / window.location",
|
|
8
|
-
"angular/router-navigate": "Router.navigateByUrl"
|
|
10
|
+
"angular/router-navigate": "Router.navigateByUrl",
|
|
11
|
+
"angular/location-assign-replace": "location.assign / replace",
|
|
12
|
+
"angular/window-open": "window.open"
|
|
9
13
|
};
|
|
10
14
|
var rule = {
|
|
11
15
|
id: "general/no-open-redirect",
|
|
12
|
-
version:
|
|
16
|
+
version: 2,
|
|
13
17
|
kind: "static-ts",
|
|
14
18
|
title: "Kh\xF4ng \u0111i\u1EC1u h\u01B0\u1EDBng t\u1EDBi URL ch\u01B0a ki\u1EC3m so\xE1t (location.href / window.location / Router.navigateByUrl)",
|
|
15
19
|
description: "D\u1EEF li\u1EC7u t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng (query params, ActivatedRoute, location.*, document.referrer, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o \u0111\xEDch \u0111i\u1EC1u h\u01B0\u1EDBng (g\xE1n `location.href` / `window.location`, ho\u1EB7c `Router.navigateByUrl(...)`) m\xE0 kh\xF4ng ki\u1EC3m tra l\xE0 l\u1ED7 h\u1ED5ng Open Redirect \u2014 k\u1EBB t\u1EA5n c\xF4ng c\xF3 th\u1EC3 l\u1EEBa ng\u01B0\u1EDDi d\xF9ng chuy\u1EC3n sang site l\u1EEBa \u0111\u1EA3o. Rule d\xF9ng taint analysis (Tier-2 li\xEAn h\xE0m/li\xEAn file) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: ki\u1EC3m tra URL v\u1EDBi allow-list (ch\u1EC9 cho ph\xE9p \u0111\u01B0\u1EDDng d\u1EABn n\u1ED9i b\u1ED9 / host tin c\u1EADy) tr\u01B0\u1EDBc khi \u0111i\u1EC1u h\u01B0\u1EDBng.",
|