@code-sentinel-cli/code-sentinel-cli 4.0.6 → 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 +41568 -30374
- 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/fortify/static/general/java-weak-randomness.rule.js +45 -0
- 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/fortify/static/general/no-reflective-access-override.rule.js +37 -0
- 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 +12 -2
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-path-traversal.rule.js +12 -2
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-servlet-xss.rule.js +12 -2
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-spel-injection.rule.js +12 -2
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-sql-string-concat.rule.js +12 -2
- package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-ssrf.rule.js +28 -4
- 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/dockerfile-dependency-confusion.rule.js +27 -2
- package/dist/builtin-rules/static/general/kubernetes-pod-security.rule.js +90 -0
- package/dist/builtin-rules/static/general/no-circular-import.rule.js +12 -2
- package/dist/builtin-rules/static/general/no-dynamic-code-eval.rule.js +84 -0
- package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +179 -13
- package/dist/builtin-rules/static/general/no-open-redirect.rule.js +7 -3
- package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +50 -7
- package/dist/builtin-rules/static/general/openapi-https-credentials.rule.js +90 -0
- package/dist/builtin-rules/static/general/sensitive-exception-response.rule.js +44 -0
- package/dist/builtin-rules/static/general/sensitive-output-exposure.rule.js +1 -1
- package/dist/builtin-rules/static/spring-boot/explicit-csp-required.rule.js +37 -0
- package/dist/builtin-rules/static/spring-boot/no-devtools-in-production.rule.js +13 -16
- package/dist/builtin-rules/static/spring-boot/no-global-permit-all.rule.js +50 -0
- package/dist/builtin-rules/static/spring-boot/no-negative-sensitive-input.rule.js +91 -0
- package/dist/builtin-rules/static/spring-boot/password-reset-without-proof.rule.js +84 -0
- package/dist/builtin-rules/static/spring-boot/stored-content-without-sanitization.rule.js +93 -0
- package/dist/index.d.ts +384 -76
- package/dist/index.js +41570 -30376
- package/node_modules/@code-sentinel/parsers/index.js +330 -198
- package/package.json +1 -1
- package/dist/builtin-rules/static/general/no-reflective-access-override.rule.js +0 -50
- /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/{ai → fortify/ai}/angular/cross-feature-route-permission-drift.rule.yaml
RENAMED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
id: angular/cross-feature-route-permission-drift
|
|
2
|
+
# Fortify-family AI detectors: pentest-only by default. `cs review` runs them
|
|
3
|
+
# ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
4
|
+
# `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
5
|
+
pack: fortify
|
|
2
6
|
# v2 (Phase 15.5.3): POC gate PASSED on ctdv/periodic-report (GLM-4.7) —
|
|
3
7
|
# 2/2 findings TP = 100% precision (>= 80% ADR-0016 bar). The finding (route
|
|
4
8
|
# guard on add/edit/detail vs UI-only `*hasPermission` for delete/export on
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
id: angular/route-permission-flow
|
|
2
|
+
# Fortify-family AI detectors: pentest-only by default. `cs review` runs them
|
|
3
|
+
# ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
4
|
+
# `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
5
|
+
pack: fortify
|
|
2
6
|
# v5 (ADR-0065 calibration): conf 60→85 (đo 21/21 TP)
|
|
3
7
|
version: 5
|
|
4
8
|
kind: ai
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
id: spring-boot/io-boundary-risk
|
|
2
|
+
# Fortify-family AI detectors: pentest-only by default. `cs review` runs them
|
|
3
|
+
# ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
4
|
+
# `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
5
|
+
pack: fortify
|
|
2
6
|
version: 2
|
|
3
7
|
kind: ai
|
|
4
8
|
title: "Spring Boot filesystem/HTTP/queue boundary co rui ro khong?"
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
id: spring-boot/security-redirect-risk
|
|
2
|
+
# Fortify-family AI detectors: pentest-only by default. `cs review` runs them
|
|
3
|
+
# ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
4
|
+
# `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
5
|
+
pack: fortify
|
|
2
6
|
version: 2
|
|
3
7
|
kind: ai
|
|
4
8
|
title: "Spring Boot open redirect or unsafe forward?"
|
package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-sensitive-data-risk.rule.yaml
RENAMED
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
id: spring-boot/security-sensitive-data-risk
|
|
2
|
+
# Fortify-family AI detectors: pentest-only by default. `cs review` runs them
|
|
3
|
+
# ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
4
|
+
# `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
5
|
+
pack: fortify
|
|
2
6
|
version: 3
|
|
3
7
|
kind: ai
|
|
4
8
|
title: "Spring Boot sensitive data exposure?"
|
package/dist/builtin-rules/{static → fortify/static}/angular/sensitive-input-masking.rule.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
2
|
|
|
3
|
-
// builtin-rules/static/angular/sensitive-input-masking.rule.ts
|
|
3
|
+
// builtin-rules/fortify/static/angular/sensitive-input-masking.rule.ts
|
|
4
4
|
var SENSITIVE_IDENTITY_ATTRS = /* @__PURE__ */ new Set(["name", "id", "formcontrolname"]);
|
|
5
5
|
var VISIBLE_TEXT_TYPES = /* @__PURE__ */ new Set(["text", "search", "email", "url", "tel"]);
|
|
6
6
|
var PASSWORD_NAME_RE = /(?:password|passwd|pwd|matkhau)/i;
|
|
@@ -61,6 +61,10 @@ var inputAttributes = (tag) => {
|
|
|
61
61
|
var isInputTag = (tag) => childOfType(tag, "tag_name")?.text.toLowerCase() === "input";
|
|
62
62
|
var rule = {
|
|
63
63
|
id: "angular/sensitive-input-masking",
|
|
64
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
65
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
66
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
67
|
+
pack: "fortify",
|
|
64
68
|
version: 1,
|
|
65
69
|
kind: "static-ts",
|
|
66
70
|
title: '\xD4 nh\u1EADp m\u1EADt kh\u1EA9u ph\u1EA3i d\xF9ng type="password"',
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { maskJavaFiles } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/fortify/static/general/java-weak-randomness.rule.ts
|
|
4
|
+
var rule = {
|
|
5
|
+
id: "general/java-weak-randomness",
|
|
6
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
7
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
8
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
9
|
+
pack: "fortify",
|
|
10
|
+
version: 1,
|
|
11
|
+
kind: "static-ts",
|
|
12
|
+
title: "Java PRNG kh\xF4ng d\xF9ng cho gi\xE1 tr\u1ECB c\u1EA7n kh\xF3 \u0111o\xE1n",
|
|
13
|
+
severity: "warning",
|
|
14
|
+
category: "security",
|
|
15
|
+
languages: ["java"],
|
|
16
|
+
scope: "general",
|
|
17
|
+
usesParser: false,
|
|
18
|
+
baseConfidence: 60,
|
|
19
|
+
check: (ctx) => {
|
|
20
|
+
const masked = maskJavaFiles([ctx.file])[0]?.content ?? ctx.file.content;
|
|
21
|
+
const source = masked.replace(
|
|
22
|
+
/"(?:[^"\\]|\\.)*"/g,
|
|
23
|
+
(literal) => literal.replace(/[^\r\n]/g, " ")
|
|
24
|
+
);
|
|
25
|
+
const weakVariables = new Set(
|
|
26
|
+
[...source.matchAll(/\b(?:java\.util\.)?Random\s+([A-Za-z_$][\w$]*)\b/g)].map((m) => m[1])
|
|
27
|
+
);
|
|
28
|
+
const calls = [
|
|
29
|
+
...source.matchAll(
|
|
30
|
+
/\bMath\s*\.\s*random\s*\(|\bThreadLocalRandom\s*\.\s*current\s*\(\s*\)\s*\.\s*next\w*\s*\(|\b([A-Za-z_$][\w$]*)\s*\.\s*next(?:Int|Long|Float|Double|Bytes|Boolean|Gaussian)\s*\(/g
|
|
31
|
+
)
|
|
32
|
+
];
|
|
33
|
+
return calls.filter((match) => !match[1] || weakVariables.has(match[1])).map((match) => ({
|
|
34
|
+
file: ctx.file.path,
|
|
35
|
+
range: { line: source.slice(0, match.index).split("\n").length, column: 1 },
|
|
36
|
+
confidence: 60,
|
|
37
|
+
message: "Non-cryptographic Java PRNG used; review whether the generated value requires unpredictability or collision resistance. No security-sensitive use is proven. [control=weak-prng-review]",
|
|
38
|
+
suggestion: "Use SecureRandom for security values; use a uniqueness strategy for business identifiers. Suppress documented test/non-security uses after review."
|
|
39
|
+
}));
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export { rule };
|
|
44
|
+
//# sourceMappingURL=java-weak-randomness.rule.js.map
|
|
45
|
+
//# sourceMappingURL=java-weak-randomness.rule.js.map
|
package/dist/builtin-rules/{static → fortify/static}/general/no-client-identity-header.rule.js
RENAMED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { maskJsComments } from '@code-sentinel/parsers';
|
|
2
2
|
|
|
3
|
-
// builtin-rules/static/general/no-client-identity-header.rule.ts
|
|
3
|
+
// builtin-rules/fortify/static/general/no-client-identity-header.rule.ts
|
|
4
4
|
var IDENTITY_HEADER_RE = /^(?:x-)?(?:[a-z0-9-]*)(?:user[-_]?id|userid|tenant[-_]?id|tenantid|account[-_]?id|accountid|role)$/i;
|
|
5
5
|
var SET_HEADER_RE = /\.\s*setHeader\s*\(\s*(['"])([^'"\r\n]+)\1\s*,/g;
|
|
6
6
|
var NAMED_HEADERS_RE = /\b(?:this\s*\.\s*)?(?:headers|httpHeaders|requestHeaders)\s*\.\s*(?:set|append)\s*\(\s*(['"])([^'"\r\n]+)\1\s*,/g;
|
|
7
7
|
var lineOf = (content, index) => content.slice(0, index).split("\n").length;
|
|
8
8
|
var rule = {
|
|
9
9
|
id: "general/no-client-identity-header",
|
|
10
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
11
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
12
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
13
|
+
pack: "fortify",
|
|
10
14
|
version: 1,
|
|
11
15
|
kind: "static-ts",
|
|
12
16
|
title: "Kh\xF4ng g\u1EAFn \u0111\u1ECBnh danh ho\u1EB7c quy\u1EC1n t\u1EEB HTTP header ph\xEDa client",
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import { maskJsComments } from '@code-sentinel/parsers';
|
|
2
2
|
|
|
3
|
-
// builtin-rules/static/general/no-guessable-websql-database-name.rule.ts
|
|
3
|
+
// builtin-rules/fortify/static/general/no-guessable-websql-database-name.rule.ts
|
|
4
4
|
var OPEN_DATABASE_LITERAL_RE = /\b(?:(?:[A-Za-z_$][\w$]*\s*\.\s*)*)openDatabase\s*\(\s*(['"])([^'"\r\n]+)\1/g;
|
|
5
5
|
var lineOf = (content, index) => content.slice(0, index).split("\n").length;
|
|
6
6
|
var rule = {
|
|
7
7
|
id: "general/no-guessable-websql-database-name",
|
|
8
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
9
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
10
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
11
|
+
pack: "fortify",
|
|
8
12
|
version: 2,
|
|
9
13
|
kind: "static-ts",
|
|
10
14
|
title: "Kh\xF4ng d\xF9ng t\xEAn Web SQL c\xF3 th\u1EC3 \u0111o\xE1n t\u1EEB bundle",
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { findReflectiveAccess } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/fortify/static/general/no-reflective-access-override.rule.ts
|
|
4
|
+
var finding = (file, line, api) => ({
|
|
5
|
+
file,
|
|
6
|
+
range: { line, column: 1 },
|
|
7
|
+
confidence: 80,
|
|
8
|
+
message: `Reflection ${api} v\u01B0\u1EE3t ki\u1EC3m so\xE1t private/protected c\u1EE7a Java (Access Specifier Manipulation).`,
|
|
9
|
+
suggestion: "\u01AFu ti\xEAn getter/setter ho\u1EB7c mapper c\xF3 allowlist. N\u1EBFu b\u1EAFt bu\u1ED9c reflection, gi\u1EDBi h\u1EA1n class/field c\u1ED1 \u0111\u1ECBnh, kh\xF4ng nh\u1EADn t\xEAn field hay object t\u1EEB request/config kh\xF4ng tin c\u1EADy, v\xE0 ghi suppression k\xE8m l\xFD do."
|
|
10
|
+
});
|
|
11
|
+
var rule = {
|
|
12
|
+
id: "general/no-reflective-access-override",
|
|
13
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
14
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
15
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
16
|
+
pack: "fortify",
|
|
17
|
+
version: 2,
|
|
18
|
+
kind: "static-ts",
|
|
19
|
+
title: "Kh\xF4ng v\u01B0\u1EE3t access modifier b\u1EB1ng Java reflection",
|
|
20
|
+
description: "Ph\xE1t hi\u1EC7n Field/Method/AccessibleObject g\u1ECDi setAccessible(true) ho\u1EB7c trySetAccessible(), c\xF3 th\u1EC3 v\u01B0\u1EE3t private/protected access control.",
|
|
21
|
+
severity: "warning",
|
|
22
|
+
category: "security",
|
|
23
|
+
languages: ["java"],
|
|
24
|
+
scope: "general",
|
|
25
|
+
requires: "text",
|
|
26
|
+
usesParser: false,
|
|
27
|
+
baseConfidence: 80,
|
|
28
|
+
check(ctx) {
|
|
29
|
+
return findReflectiveAccess(ctx.file.content, ctx.file.path).map(
|
|
30
|
+
(hit) => finding(hit.file, hit.line, hit.api)
|
|
31
|
+
);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export { rule };
|
|
36
|
+
//# sourceMappingURL=no-reflective-access-override.rule.js.map
|
|
37
|
+
//# sourceMappingURL=no-reflective-access-override.rule.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { maskJavaFiles, asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
2
|
|
|
3
|
-
// builtin-rules/static/general/no-sensitive-string-materialization.rule.ts
|
|
3
|
+
// builtin-rules/fortify/static/general/no-sensitive-string-materialization.rule.ts
|
|
4
4
|
var STRING_CONSTRUCTOR_RE = /\bnew\s+String\s*\(\s*([^;\n]{0,300}?)(?:\)|$)/g;
|
|
5
5
|
var SENSITIVE_PRODUCER_RE = /\bdecrypt\w*\s*\(|\bget(?:Password|Passwd|Pwd|Secret|Token|Key)\s*\(/i;
|
|
6
6
|
var SENSITIVE_IDENTIFIER_RE = /\b\w*(?:password|passwd|pwd|secret|token|privatekey|apikey|credential|accesskey|signingkey|encryptionkey)\w*\b/i;
|
|
@@ -69,6 +69,10 @@ var firstConstructorArgument = (node) => {
|
|
|
69
69
|
var isStringConstructor = (node) => node.type === "object_creation_expression" && node.childForFieldName("type")?.text === "String";
|
|
70
70
|
var rule = {
|
|
71
71
|
id: "general/no-sensitive-string-materialization",
|
|
72
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
73
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
74
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
75
|
+
pack: "fortify",
|
|
72
76
|
version: 2,
|
|
73
77
|
kind: "static-ts",
|
|
74
78
|
title: "Kh\xF4ng chuy\u1EC3n d\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m sang Java String",
|
package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-command-injection.rule.js
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// builtin-rules/static/spring-boot/no-command-injection.rule.ts
|
|
1
|
+
// builtin-rules/fortify/static/spring-boot/no-command-injection.rule.ts
|
|
2
2
|
var COMMAND_INJECTION_SINK_IDS = /* @__PURE__ */ new Set([
|
|
3
3
|
"spring/runtime-exec",
|
|
4
4
|
"spring/process-builder-command",
|
|
@@ -11,6 +11,10 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "spring-boot/no-command-injection",
|
|
14
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
15
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
16
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
17
|
+
pack: "fortify",
|
|
14
18
|
// v4 (Pentest Coverage Layer P3 #4): the Java analyzer now folds a tainted
|
|
15
19
|
// collection element (`argList.add("echo " + param)`) into the collection so
|
|
16
20
|
// the whole list reaching `pb.command(argList)` / `new ProcessBuilder(argList)`
|
|
@@ -18,7 +22,13 @@ var rule = {
|
|
|
18
22
|
// rule's projection logic is unchanged; the bump invalidates findings cached on
|
|
19
23
|
// unchanged file content before the broader analyzer coverage.
|
|
20
24
|
// v5 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
21
|
-
|
|
25
|
+
// v6 (D1 — JAX-RS taint sources): no rule-logic change. The Java analyzer
|
|
26
|
+
// gained 8 `jaxrs/*` parameter sources (`@QueryParam`/`@FormParam`/…, javax +
|
|
27
|
+
// jakarta) and seeds a bare impl param from the annotation on the interface
|
|
28
|
+
// method it overrides. The rule cache key is `(id, version, file.hash)`, so a
|
|
29
|
+
// taint-table change alone does NOT rotate it — without this bump a warm cache
|
|
30
|
+
// keeps serving the pre-D1 result (measured: 1 vs 10 SSRF on the same module).
|
|
31
|
+
version: 6,
|
|
22
32
|
kind: "static-ts",
|
|
23
33
|
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)",
|
|
24
34
|
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.",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// builtin-rules/static/spring-boot/no-path-traversal.rule.ts
|
|
1
|
+
// builtin-rules/fortify/static/spring-boot/no-path-traversal.rule.ts
|
|
2
2
|
var PATH_TRAVERSAL_SINK_IDS = /* @__PURE__ */ new Set([
|
|
3
3
|
"spring/path-file",
|
|
4
4
|
"spring/path-resource",
|
|
@@ -11,7 +11,17 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "spring-boot/no-path-traversal",
|
|
14
|
-
|
|
14
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
15
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
16
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
17
|
+
pack: "fortify",
|
|
18
|
+
// v4 (D1 — JAX-RS taint sources): no rule-logic change. The Java analyzer
|
|
19
|
+
// gained 8 `jaxrs/*` parameter sources (`@QueryParam`/`@FormParam`/…, javax +
|
|
20
|
+
// jakarta) and seeds a bare impl param from the annotation on the interface
|
|
21
|
+
// method it overrides. The rule cache key is `(id, version, file.hash)`, so a
|
|
22
|
+
// taint-table change alone does NOT rotate it — without this bump a warm cache
|
|
23
|
+
// keeps serving the pre-D1 result (measured: 1 vs 10 SSRF on the same module).
|
|
24
|
+
version: 4,
|
|
15
25
|
kind: "static-ts",
|
|
16
26
|
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
27
|
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.",
|
|
@@ -1,11 +1,21 @@
|
|
|
1
|
-
// builtin-rules/static/spring-boot/no-servlet-xss.rule.ts
|
|
1
|
+
// builtin-rules/fortify/static/spring-boot/no-servlet-xss.rule.ts
|
|
2
2
|
var SERVLET_XSS_SINK_IDS = /* @__PURE__ */ new Set(["spring/servlet-writer"]);
|
|
3
3
|
var SINK_LABEL = {
|
|
4
4
|
"spring/servlet-writer": "response.getWriter().write/print(...)"
|
|
5
5
|
};
|
|
6
6
|
var rule = {
|
|
7
7
|
id: "spring-boot/no-servlet-xss",
|
|
8
|
-
|
|
8
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
9
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
10
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
11
|
+
pack: "fortify",
|
|
12
|
+
// v2 (D1 — JAX-RS taint sources): no rule-logic change. The Java analyzer
|
|
13
|
+
// gained 8 `jaxrs/*` parameter sources (`@QueryParam`/`@FormParam`/…, javax +
|
|
14
|
+
// jakarta) and seeds a bare impl param from the annotation on the interface
|
|
15
|
+
// method it overrides. The rule cache key is `(id, version, file.hash)`, so a
|
|
16
|
+
// taint-table change alone does NOT rotate it — without this bump a warm cache
|
|
17
|
+
// keeps serving the pre-D1 result (measured: 1 vs 10 SSRF on the same module).
|
|
18
|
+
version: 2,
|
|
9
19
|
kind: "static-ts",
|
|
10
20
|
title: "Kh\xF4ng ghi d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t v\xE0o response HTML (Reflected XSS)",
|
|
11
21
|
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.",
|
|
@@ -1,12 +1,22 @@
|
|
|
1
|
-
// builtin-rules/static/spring-boot/no-spel-injection.rule.ts
|
|
1
|
+
// builtin-rules/fortify/static/spring-boot/no-spel-injection.rule.ts
|
|
2
2
|
var SPEL_SINK_IDS = /* @__PURE__ */ new Set(["spring/spel-parse"]);
|
|
3
3
|
var SINK_LABEL = {
|
|
4
4
|
"spring/spel-parse": "ExpressionParser.parseExpression(...)"
|
|
5
5
|
};
|
|
6
6
|
var rule = {
|
|
7
7
|
id: "spring-boot/no-spel-injection",
|
|
8
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
9
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
10
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
11
|
+
pack: "fortify",
|
|
8
12
|
// v3 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
9
|
-
|
|
13
|
+
// v4 (D1 — JAX-RS taint sources): no rule-logic change. The Java analyzer
|
|
14
|
+
// gained 8 `jaxrs/*` parameter sources (`@QueryParam`/`@FormParam`/…, javax +
|
|
15
|
+
// jakarta) and seeds a bare impl param from the annotation on the interface
|
|
16
|
+
// method it overrides. The rule cache key is `(id, version, file.hash)`, so a
|
|
17
|
+
// taint-table change alone does NOT rotate it — without this bump a warm cache
|
|
18
|
+
// keeps serving the pre-D1 result (measured: 1 vs 10 SSRF on the same module).
|
|
19
|
+
version: 4,
|
|
10
20
|
kind: "static-ts",
|
|
11
21
|
title: "Kh\xF4ng parse SpEL t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (Expression Language Injection)",
|
|
12
22
|
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`.",
|
package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-sql-string-concat.rule.js
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
2
|
|
|
3
|
-
// builtin-rules/static/spring-boot/no-sql-string-concat.rule.ts
|
|
3
|
+
// builtin-rules/fortify/static/spring-boot/no-sql-string-concat.rule.ts
|
|
4
4
|
var SQL_KEYWORD = /\b(SELECT|INSERT|UPDATE|DELETE|FROM|WHERE)\b/;
|
|
5
5
|
var SQL_SINK_CALLEES = /* @__PURE__ */ new Set([
|
|
6
6
|
"createQuery",
|
|
@@ -152,8 +152,18 @@ var isConcatRoot = (node) => {
|
|
|
152
152
|
};
|
|
153
153
|
var rule = {
|
|
154
154
|
id: "spring-boot/no-sql-string-concat",
|
|
155
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
156
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
157
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
158
|
+
pack: "fortify",
|
|
155
159
|
// v7 (ADR-0065 calibration): band CONFIRMED → severity blocker
|
|
156
|
-
|
|
160
|
+
// v8 (D1 — JAX-RS taint sources): no rule-logic change. The Java analyzer
|
|
161
|
+
// gained 8 `jaxrs/*` parameter sources (`@QueryParam`/`@FormParam`/…, javax +
|
|
162
|
+
// jakarta) and seeds a bare impl param from the annotation on the interface
|
|
163
|
+
// method it overrides. The rule cache key is `(id, version, file.hash)`, so a
|
|
164
|
+
// taint-table change alone does NOT rotate it — without this bump a warm cache
|
|
165
|
+
// keeps serving the pre-D1 result (measured: 1 vs 10 SSRF on the same module).
|
|
166
|
+
version: 8,
|
|
157
167
|
kind: "static-ts",
|
|
158
168
|
title: "Kh\xF4ng n\u1ED1i SQL b\u1EB1ng `+` \u2014 d\xF9ng prepared statement / named parameter",
|
|
159
169
|
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.",
|
|
@@ -1,19 +1,43 @@
|
|
|
1
|
-
// builtin-rules/static/spring-boot/no-ssrf.rule.ts
|
|
1
|
+
// builtin-rules/fortify/static/spring-boot/no-ssrf.rule.ts
|
|
2
2
|
var SSRF_SINK_IDS = /* @__PURE__ */ new Set([
|
|
3
3
|
"spring/rest-template-ssrf",
|
|
4
4
|
"spring/web-client-ssrf",
|
|
5
5
|
"spring/url-ssrf",
|
|
6
|
-
"spring/okhttp-url"
|
|
6
|
+
"spring/okhttp-url",
|
|
7
|
+
"spring/jdbc-url-ssrf",
|
|
8
|
+
"spring/datasource-url-ssrf"
|
|
7
9
|
]);
|
|
8
10
|
var SINK_LABEL = {
|
|
9
11
|
"spring/rest-template-ssrf": "RestTemplate (getForObject / exchange / \u2026)",
|
|
10
12
|
"spring/web-client-ssrf": "WebClient.uri(...)",
|
|
11
13
|
"spring/url-ssrf": "new URL(...) / new URI(...)",
|
|
12
|
-
"spring/okhttp-url": "OkHttp Request.Builder.url(...)"
|
|
14
|
+
"spring/okhttp-url": "OkHttp Request.Builder.url(...)",
|
|
15
|
+
"spring/jdbc-url-ssrf": "DriverManager.getConnection(jdbcUrl, ...)",
|
|
16
|
+
"spring/datasource-url-ssrf": "DataSource.setJdbcUrl / setUrl(...)"
|
|
13
17
|
};
|
|
14
18
|
var rule = {
|
|
15
19
|
id: "spring-boot/no-ssrf",
|
|
16
|
-
|
|
20
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
21
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
22
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
23
|
+
pack: "fortify",
|
|
24
|
+
// v5 (D1 — JAX-RS taint sources): no rule-logic change. The Java analyzer
|
|
25
|
+
// gained 8 `jaxrs/*` parameter sources (`@QueryParam`/`@FormParam`/…, javax +
|
|
26
|
+
// jakarta) and seeds a bare impl param from the annotation on the interface
|
|
27
|
+
// method it overrides. The rule cache key is `(id, version, file.hash)`, so a
|
|
28
|
+
// taint-table change alone does NOT rotate it — without this bump a warm cache
|
|
29
|
+
// keeps serving the pre-D1 result (measured: 1 vs 10 SSRF on the same module).
|
|
30
|
+
// v7 (2026-09-17): no rule-logic change. The analyzer drops `new URL(spec)` when the assigned
|
|
31
|
+
// value is only read through inert accessors (getHost/getProtocol/…) — a redirect GUARD on
|
|
32
|
+
// mcdt_bqp was a CONFIRMED-VULN SSRF. Also two JDBC-URL sinks (DriverManager.getConnection, DataSource
|
|
33
|
+
// setJdbcUrl/setUrl — SR BUG-53088). Bumped so a warm cache cannot keep the pre-gate result.
|
|
34
|
+
// v6 (ADR-0086 — host-fixing prefix): no rule-logic change either. The four SSRF sinks now
|
|
35
|
+
// carry `urlAuthority`, so the Java analyzer no longer reports taint that reaches the URL only
|
|
36
|
+
// AFTER a host-fixing constant (`base + "?q=" + t`, `"/api/items/" + id`,
|
|
37
|
+
// `endpoint + StringPool.QUESTION + params`) — a query value / path segment on a host the
|
|
38
|
+
// server chose is parameter injection, not SSRF. Same cache reason as v5: bump or a warm cache
|
|
39
|
+
// keeps serving the suppressed findings.
|
|
40
|
+
version: 7,
|
|
17
41
|
kind: "static-ts",
|
|
18
42
|
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
43
|
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.",
|
package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-weak-tls-protocol.rule.js
RENAMED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// builtin-rules/static/spring-boot/no-weak-tls-protocol.rule.ts
|
|
1
|
+
// builtin-rules/fortify/static/spring-boot/no-weak-tls-protocol.rule.ts
|
|
2
2
|
var WEAK_TLS_PATTERNS = [
|
|
3
3
|
{
|
|
4
4
|
regex: /\bSSLContext\.getInstance\s*\(\s*["'](?:SSL|SSLv2|SSLv3|TLSv1|TLSv1\.0|TLSv1\.1)["']/g,
|
|
@@ -17,6 +17,10 @@ var lineColumnAt = (content, index) => {
|
|
|
17
17
|
};
|
|
18
18
|
var rule = {
|
|
19
19
|
id: "spring-boot/no-weak-tls-protocol",
|
|
20
|
+
// Fortify-family flaw detectors: pentest-only by default. `cs review` runs them
|
|
21
|
+
// ONLY when the pack is activated (`rules.packs: ['fortify']` or --packs fortify);
|
|
22
|
+
// `cs assess` always activates the pack for its fold lanes (fold-rules.ts).
|
|
23
|
+
pack: "fortify",
|
|
20
24
|
version: 1,
|
|
21
25
|
kind: "static-ts",
|
|
22
26
|
title: "Kh\xF4ng s\u1EED d\u1EE5ng giao th\u1EE9c SSL/TLS l\u1ED7i th\u1EDDi (SSLv3, TLSv1, TLSv1.1)",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/performance/static/spring-boot/http-client-without-timeout.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/http-client-without-timeout",
|
|
18
|
+
version: 1,
|
|
19
|
+
kind: "static-ts",
|
|
20
|
+
pack: "performance",
|
|
21
|
+
title: "RestTemplate kh\xF4ng \u0111\u1EB7t timeout \u2014 treo v\xF4 h\u1EA1n khi upstream \u0111\u1EE9ng",
|
|
22
|
+
description: "`new RestTemplate()` tr\u1EA7n d\xF9ng `SimpleClientHttpRequestFactory` c\u1EE7a JDK v\u1EDBi connect/read timeout M\u1EB6C \u0110\u1ECANH KH\xD4NG \u0110\u1EB6T (v\xF4 h\u1EA1n). M\u1ED9t l\u1EDDi g\u1ECDi t\u1EDBi d\u1ECBch v\u1EE5 b\u1ECB \u0111\u1EE9ng s\u1EBD gi\u1EEF thread (v\xE0 k\u1EBFt n\u1ED1i DB n\u1EBFu \u0111ang trong transaction) ch\u1EDD v\xF4 th\u1EDDi h\u1EA1n. \u0110\u1EB7t timeout qua `SimpleClientHttpRequestFactory.setConnectTimeout/setReadTimeout` r\u1ED3i truy\u1EC1n v\xE0o constructor, ho\u1EB7c d\xF9ng `RestTemplateBuilder.setConnectTimeout/\u2026setReadTimeout`.",
|
|
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
|
+
"@Bean",
|
|
34
|
+
"public RestTemplate restTemplate() {",
|
|
35
|
+
" SimpleClientHttpRequestFactory f = new SimpleClientHttpRequestFactory();",
|
|
36
|
+
" f.setConnectTimeout(5_000);",
|
|
37
|
+
" f.setReadTimeout(30_000);",
|
|
38
|
+
" return new RestTemplate(f);",
|
|
39
|
+
"}"
|
|
40
|
+
].join("\n"),
|
|
41
|
+
explanation: "Factory c\xF3 timeout \u2014 l\u1EDDi g\u1ECDi \u0111\u1EE9ng s\u1EBD th\u1EA5t b\u1EA1i sau th\u1EDDi h\u1EA1n thay v\xEC treo v\xF4 h\u1EA1n."
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
bad: [
|
|
45
|
+
{
|
|
46
|
+
code: [
|
|
47
|
+
"@Bean",
|
|
48
|
+
"public RestTemplate restTemplate() {",
|
|
49
|
+
" return new RestTemplate(); // timeout v\xF4 h\u1EA1n (m\u1EB7c \u0111\u1ECBnh JDK factory)",
|
|
50
|
+
"}"
|
|
51
|
+
].join("\n"),
|
|
52
|
+
explanation: "Constructor tr\u1EA7n \u2014 kh\xF4ng c\xF3 timeout n\xE0o; upstream \u0111\u1EE9ng \u21D2 thread ch\u1EDD v\xF4 h\u1EA1n."
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
check(ctx) {
|
|
57
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
58
|
+
const findings = [];
|
|
59
|
+
for (const creation of walk(tree.rootNode, "object_creation_expression")) {
|
|
60
|
+
const typeNode = creation.childForFieldName("type");
|
|
61
|
+
if (!typeNode || typeNode.text !== "RestTemplate") continue;
|
|
62
|
+
const args = creation.childForFieldName("arguments");
|
|
63
|
+
const argCount = args ? args.namedChildCount : 0;
|
|
64
|
+
if (argCount > 0) continue;
|
|
65
|
+
findings.push({
|
|
66
|
+
message: "`new RestTemplate()` kh\xF4ng \u0111\u1EB7t timeout \u2014 factory JDK m\u1EB7c \u0111\u1ECBnh c\xF3 connect/read timeout v\xF4 h\u1EA1n: m\u1ED9t l\u1EDDi g\u1ECDi t\u1EDBi d\u1ECBch v\u1EE5 \u0111\u1EE9ng s\u1EBD gi\u1EEF thread (v\xE0 k\u1EBFt n\u1ED1i DB n\u1EBFu trong transaction) ch\u1EDD v\xF4 th\u1EDDi h\u1EA1n. M\u1EE9c \u1EA3nh h\u01B0\u1EDFng ph\u1EE5 thu\u1ED9c kh\u1EA3 n\u0103ng d\u1ECBch v\u1EE5 \u0111\xEDch b\u1ECB \u0111\u1EE9ng.",
|
|
67
|
+
file: ctx.file.path,
|
|
68
|
+
range: {
|
|
69
|
+
line: creation.startPosition.row + 1,
|
|
70
|
+
column: creation.startPosition.column + 1
|
|
71
|
+
},
|
|
72
|
+
snippet: creation.text,
|
|
73
|
+
suggestion: "\u0110\u1EB7t `SimpleClientHttpRequestFactory` v\u1EDBi `setConnectTimeout`/`setReadTimeout` r\u1ED3i truy\u1EC1n v\xE0o constructor, ho\u1EB7c d\xF9ng `RestTemplateBuilder` v\u1EDBi `setConnectTimeout(\u2026).setReadTimeout(\u2026)`.",
|
|
74
|
+
confidence: 75
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return findings;
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export { rule };
|
|
82
|
+
//# sourceMappingURL=http-client-without-timeout.rule.js.map
|
|
83
|
+
//# sourceMappingURL=http-client-without-timeout.rule.js.map
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
// builtin-rules/performance/static/spring-boot/open-in-view-enabled.rule.ts
|
|
2
|
+
var BASE_CONFIG_RE = /^(?:.*\/)?services\/[^/]+\/src\/main\/resources\/(?:config\/)?application\.yml$/;
|
|
3
|
+
function readKeys(content) {
|
|
4
|
+
const keys = /* @__PURE__ */ new Map();
|
|
5
|
+
const stack = [];
|
|
6
|
+
const lines = content.split("\n");
|
|
7
|
+
for (let i = 0; i < lines.length; i++) {
|
|
8
|
+
const raw = lines[i] ?? "";
|
|
9
|
+
const trimmed = raw.trim();
|
|
10
|
+
if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith("-")) continue;
|
|
11
|
+
const indent = (raw.match(/^(\s*)/)?.[1] ?? "").length;
|
|
12
|
+
while (stack.length > 0 && (stack[stack.length - 1]?.indent ?? 0) >= indent) {
|
|
13
|
+
stack.pop();
|
|
14
|
+
}
|
|
15
|
+
const sep = trimmed.match(/^([^:=#]+)[:=]\s*(.*)$/);
|
|
16
|
+
if (!sep) continue;
|
|
17
|
+
const key = sep[1]?.trim() ?? "";
|
|
18
|
+
const value = (sep[2] ?? "").replace(/\s*#.*$/, "").trim();
|
|
19
|
+
if (!value) {
|
|
20
|
+
stack.push({ indent, key });
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
const fullKey = [...stack.map((s) => s.key), key].join(".");
|
|
24
|
+
keys.set(fullKey, { value, line: i + 1 });
|
|
25
|
+
}
|
|
26
|
+
return keys;
|
|
27
|
+
}
|
|
28
|
+
var rule = {
|
|
29
|
+
id: "spring-boot/open-in-view-enabled",
|
|
30
|
+
version: 1,
|
|
31
|
+
kind: "static-ts",
|
|
32
|
+
pack: "performance",
|
|
33
|
+
title: "OSIV kh\xF4ng t\u1EAFt t\u01B0\u1EDDng minh \u2014 k\u1EBFt n\u1ED1i DB gi\u1EEF su\u1ED1t request (Spring Boot m\u1EB7c \u0111\u1ECBnh b\u1EADt)",
|
|
34
|
+
description: "Config ch\xEDnh c\u1EE7a service kh\xF4ng khai b\xE1o `spring.jpa.open-in-view: false` (ho\u1EB7c khai b\xE1o b\u1EADt) \u21D2 Spring Boot m\u1EB7c \u0111\u1ECBnh B\u1EACT Open-In-View: EntityManager v\xE0 k\u1EBFt n\u1ED1i DB b\u1ECB bu\u1ED9c v\xE0o thread request t\u1EDBi khi response render xong sau l\u1EA7n truy v\u1EA5n \u0111\u1EA7u ti\xEAn (\u0111o b\u1EB1ng fixture, ADR-0087 V2 case g). M\u1ECDi I/O sau \u0111\xF3 (g\u1ECDi HTTP, render file) \u0111\u1EC1u gi\u1EEF k\u1EBFt n\u1ED1i pool.",
|
|
35
|
+
severity: "warning",
|
|
36
|
+
category: "performance",
|
|
37
|
+
languages: ["yaml", "text"],
|
|
38
|
+
scope: "spring-boot",
|
|
39
|
+
requires: "text",
|
|
40
|
+
usesParser: false,
|
|
41
|
+
baseConfidence: 80,
|
|
42
|
+
examples: {
|
|
43
|
+
good: [
|
|
44
|
+
{
|
|
45
|
+
code: "spring:\n jpa:\n open-in-view: false\n",
|
|
46
|
+
explanation: "T\u1EAFt t\u01B0\u1EDDng minh \u2014 EntityManager ch\u1EC9 m\u1EDF trong transaction, k\u1EBFt n\u1ED1i tr\u1EA3 v\u1EC1 pool ngay sau commit."
|
|
47
|
+
}
|
|
48
|
+
],
|
|
49
|
+
bad: [
|
|
50
|
+
{
|
|
51
|
+
code: "# spring.jpa.open-in-view kh\xF4ng khai b\xE1o \u2014 Spring Boot m\u1EB7c \u0111\u1ECBnh true\nspring:\n jpa:\n hibernate:\n ddl-auto: none\n",
|
|
52
|
+
explanation: "Thi\u1EBFu khai b\xE1o = m\u1EB7c \u0111\u1ECBnh b\u1EADt; controller g\u1ECDi HTTP/render sau khi \u0111\xE3 query s\u1EBD gi\u1EEF k\u1EBFt n\u1ED1i DB su\u1ED1t request."
|
|
53
|
+
}
|
|
54
|
+
]
|
|
55
|
+
},
|
|
56
|
+
check(ctx) {
|
|
57
|
+
const file = ctx.file;
|
|
58
|
+
if (!BASE_CONFIG_RE.test(file.path)) return [];
|
|
59
|
+
const keys = readKeys(file.content);
|
|
60
|
+
const osiv = keys.get("spring.jpa.open-in-view");
|
|
61
|
+
const hasJpaBlock = [...keys.keys()].some((k) => k.startsWith("spring.jpa."));
|
|
62
|
+
if (!hasJpaBlock) return [];
|
|
63
|
+
if (osiv?.value === "false") return [];
|
|
64
|
+
if (osiv) {
|
|
65
|
+
return [
|
|
66
|
+
{
|
|
67
|
+
message: `\`${file.path.split("/").pop()}\` khai b\xE1o \`spring.jpa.open-in-view: ${osiv.value}\` \u2014 OSIV b\u1EADt: EntityManager v\xE0 k\u1EBFt n\u1ED1i DB b\u1ECB gi\u1EEF t\u1EDBi khi response render xong sau l\u1EA7n truy v\u1EA5n \u0111\u1EA7u ti\xEAn (ADR-0087 V2 case g). Gi\xE1 tr\u1ECB hi\u1EC7u l\u1EF1c ph\u1EE5 thu\u1ED9c profile tri\u1EC3n khai.`,
|
|
68
|
+
file: file.path,
|
|
69
|
+
range: { line: osiv.line, column: 1 },
|
|
70
|
+
confidence: 85,
|
|
71
|
+
suggestion: "Khai b\xE1o t\u01B0\u1EDDng minh `spring.jpa.open-in-view: false` trong config ch\xEDnh c\u1EE7a service."
|
|
72
|
+
}
|
|
73
|
+
];
|
|
74
|
+
}
|
|
75
|
+
return [
|
|
76
|
+
{
|
|
77
|
+
message: "Config ch\xEDnh c\u1EE7a service KH\xD4NG khai b\xE1o `spring.jpa.open-in-view: false` \u2014 Spring Boot m\u1EB7c \u0111\u1ECBnh B\u1EACT OSIV: k\u1EBFt n\u1ED1i DB b\u1ECB gi\u1EEF t\u1EDBi khi response render xong sau l\u1EA7n truy v\u1EA5n \u0111\u1EA7u ti\xEAn (ADR-0087 V2 case g). Gi\xE1 tr\u1ECB hi\u1EC7u l\u1EF1c ph\u1EE5 thu\u1ED9c profile tri\u1EC3n khai.",
|
|
78
|
+
file: file.path,
|
|
79
|
+
range: { line: 1, column: 1 },
|
|
80
|
+
confidence: 80,
|
|
81
|
+
suggestion: "Th\xEAm `spring.jpa.open-in-view: false` v\xE0o kh\u1ED1i `spring.jpa` trong `application.yml`. N\u1EBFu ch\u1EE7 \xFD gi\u1EEF b\u1EADt, khai b\xE1o `true` t\u01B0\u1EDDng minh k\xE8m l\xFD do \u0111\u1EC3 m\u1EB7c \u0111\u1ECBnh kh\xF4ng b\u1ECB \u0111\u1ECDc l\xE0 c\u1ED1 \xFD."
|
|
82
|
+
}
|
|
83
|
+
];
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export { rule };
|
|
88
|
+
//# sourceMappingURL=open-in-view-enabled.rule.js.map
|
|
89
|
+
//# sourceMappingURL=open-in-view-enabled.rule.js.map
|