@code-sentinel-cli/code-sentinel-cli 3.0.9 → 3.0.11
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 +38961 -19863
- package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +3 -6
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +4 -8
- package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +0 -2
- package/dist/builtin-rules/ai/general/code-clarity.prompt.md +19 -2
- package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +8 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +3 -3
- package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +0 -1
- package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +4 -10
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +9 -8
- package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +12 -14
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +4 -4
- package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +3 -3
- package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +3 -3
- package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +1 -2
- package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +1 -2
- package/dist/builtin-rules/static/angular/button-accessible-name.rule.js +143 -0
- package/dist/builtin-rules/static/angular/component-prefix.rule.js +6 -2
- package/dist/builtin-rules/static/angular/img-alt-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/inject-pattern.rule.js +3 -2
- package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +14 -5
- package/dist/builtin-rules/static/angular/onpush-required.rule.js +3 -2
- package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +28 -4
- package/dist/builtin-rules/static/angular/trackby-required.rule.js +3 -2
- package/dist/builtin-rules/static/flutter/no-undisposed-resource.rule.js +143 -0
- package/dist/builtin-rules/static/general/file-too-long.rule.js +5 -4
- package/dist/builtin-rules/static/general/function-too-long.rule.js +46 -27
- package/dist/builtin-rules/static/general/no-code-injection.rule.js +8 -1
- package/dist/builtin-rules/static/general/no-console-log.rule.js +3 -2
- package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +14 -8
- package/dist/builtin-rules/static/general/no-hardcoded-vietnamese.rule.js +58 -0
- package/dist/builtin-rules/static/general/no-magic-number.rule.js +151 -8
- package/dist/builtin-rules/static/general/no-todo-comment.rule.js +88 -0
- package/dist/builtin-rules/static/general/no-unused-export.rule.js +53 -6
- package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +14 -1
- package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +1 -1
- package/dist/builtin-rules/static/spring-boot/no-servlet-xss.rule.js +41 -0
- package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +8 -1
- package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +35 -4
- package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +1 -1
- package/dist/builtin-rules/static/spring-boot/no-unzoned-datetime.rule.js +96 -0
- package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +4 -2
- package/dist/index.d.ts +316 -132
- package/dist/index.js +38952 -19854
- package/package.json +1 -1
- package/templates/ci/github-actions.yml +60 -2
- package/templates/ci/gitlab-ci.yml +51 -2
- package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +0 -30
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
// builtin-rules/static/general/no-todo-comment.rule.ts
|
|
2
|
+
var TODO_KEYWORD_RE = /\b([Tt][Oo][Dd][Oo]|[Ff][Ii][Xx][Mm][Ee]|[Hh][Aa][Cc][Kk]|XXX|xxx)\b/;
|
|
3
|
+
var rule = {
|
|
4
|
+
id: "general/no-todo-comment",
|
|
5
|
+
version: 2,
|
|
6
|
+
kind: "static-ts",
|
|
7
|
+
title: "Kh\xF4ng \u0111\u1EC3 TODO/FIXME/HACK/XXX trong code \u0111\xE3 commit",
|
|
8
|
+
description: 'TODO comments kh\xF4ng ph\u1EA3i l\xE0 c\xE1ch tracking c\xF4ng vi\u1EC7c \u2014 ch\xFAng t\xEDch t\u1EE5 v\xE0 b\u1ECB qu\xEAn. H\xE3y t\u1EA1o issue trong tracker (Jira/Linear), commit code \u0111\xE3 ho\xE0n th\xE0nh, v\xE0 \u0111\u1EC3 comment gi\u1EA3i th\xEDch "t\u1EA1i sao" thay v\xEC "c\xF2n thi\u1EBFu g\xEC". Rule n\xE0y flag m\u1ECDi comment ch\u1EE9a TODO, FIXME, HACK, XXX (kh\xF4ng ph\xE2n bi\u1EC7t hoa th\u01B0\u1EDDng).',
|
|
9
|
+
severity: "info",
|
|
10
|
+
category: "maintainability",
|
|
11
|
+
languages: ["typescript", "javascript", "java", "dart"],
|
|
12
|
+
scope: "general",
|
|
13
|
+
requires: "text",
|
|
14
|
+
baseConfidence: 100,
|
|
15
|
+
check(ctx) {
|
|
16
|
+
const content = ctx.file.content;
|
|
17
|
+
const lines = content.split(/\r?\n/);
|
|
18
|
+
const findings = [];
|
|
19
|
+
let inBlockComment = false;
|
|
20
|
+
for (let i = 0; i < lines.length; i++) {
|
|
21
|
+
const lineText = lines[i];
|
|
22
|
+
if (lineText === void 0) continue;
|
|
23
|
+
const lineNum = i + 1;
|
|
24
|
+
if (inBlockComment) {
|
|
25
|
+
const endIdx = lineText.indexOf("*/");
|
|
26
|
+
const commentChunk = endIdx !== -1 ? lineText.slice(0, endIdx + 2) : lineText;
|
|
27
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
28
|
+
if (match) {
|
|
29
|
+
findings.push({
|
|
30
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
31
|
+
file: ctx.file.path,
|
|
32
|
+
range: { line: lineNum, column: (match.index ?? 0) + 1 },
|
|
33
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
if (endIdx !== -1) {
|
|
37
|
+
inBlockComment = false;
|
|
38
|
+
}
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const singleIdx = lineText.indexOf("//");
|
|
42
|
+
const blockStartIdx = lineText.indexOf("/*");
|
|
43
|
+
if (singleIdx !== -1 && (blockStartIdx === -1 || singleIdx < blockStartIdx)) {
|
|
44
|
+
const commentChunk = lineText.slice(singleIdx);
|
|
45
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
46
|
+
if (match) {
|
|
47
|
+
findings.push({
|
|
48
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
49
|
+
file: ctx.file.path,
|
|
50
|
+
range: { line: lineNum, column: singleIdx + (match.index ?? 0) + 1 },
|
|
51
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
} else if (blockStartIdx !== -1) {
|
|
55
|
+
const endIdx = lineText.indexOf("*/", blockStartIdx + 2);
|
|
56
|
+
if (endIdx !== -1) {
|
|
57
|
+
const commentChunk = lineText.slice(blockStartIdx, endIdx + 2);
|
|
58
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
59
|
+
if (match) {
|
|
60
|
+
findings.push({
|
|
61
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
62
|
+
file: ctx.file.path,
|
|
63
|
+
range: { line: lineNum, column: blockStartIdx + (match.index ?? 0) + 1 },
|
|
64
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
} else {
|
|
68
|
+
inBlockComment = true;
|
|
69
|
+
const commentChunk = lineText.slice(blockStartIdx);
|
|
70
|
+
const match = TODO_KEYWORD_RE.exec(commentChunk);
|
|
71
|
+
if (match) {
|
|
72
|
+
findings.push({
|
|
73
|
+
message: "Comment ch\u1EE9a TODO/FIXME/HACK/XXX \u2014 t\u1EA1o issue trong tracker thay v\xEC \u0111\u1EC3 trong code.",
|
|
74
|
+
file: ctx.file.path,
|
|
75
|
+
range: { line: lineNum, column: blockStartIdx + (match.index ?? 0) + 1 },
|
|
76
|
+
suggestion: "T\u1EA1o ticket trong Jira/Linear v\u1EDBi context c\u1EE5 th\u1EC3, xo\xE1 comment khi \u0111\xE3 c\xF3 ticket."
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return findings;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export { rule };
|
|
87
|
+
//# sourceMappingURL=no-todo-comment.rule.js.map
|
|
88
|
+
//# sourceMappingURL=no-todo-comment.rule.js.map
|
|
@@ -1,4 +1,11 @@
|
|
|
1
|
+
import { asTsMorphSourceFile } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
1
3
|
// builtin-rules/static/general/no-unused-export.rule.ts
|
|
4
|
+
var TYPE_ONLY_KINDS = /* @__PURE__ */ new Set([
|
|
5
|
+
"interface",
|
|
6
|
+
"type",
|
|
7
|
+
"enum"
|
|
8
|
+
]);
|
|
2
9
|
var DEFAULT_SKIP_PATHS = [
|
|
3
10
|
"**/index.ts",
|
|
4
11
|
"**/index.tsx",
|
|
@@ -12,6 +19,19 @@ var DEFAULT_SKIP_PATHS = [
|
|
|
12
19
|
"**/*.module.ts",
|
|
13
20
|
"**/*.routes.ts",
|
|
14
21
|
"**/*.config.ts",
|
|
22
|
+
// v2 (ADR-0065) — shared-contract file conventions. These hold the types,
|
|
23
|
+
// constants and models a codebase deliberately publishes for other modules
|
|
24
|
+
// to import; "nobody in the reviewed subtree imports it" is not evidence
|
|
25
|
+
// that nobody imports it.
|
|
26
|
+
"**/*.types.ts",
|
|
27
|
+
"**/*.interface.ts",
|
|
28
|
+
"**/*.interfaces.ts",
|
|
29
|
+
"**/*.model.ts",
|
|
30
|
+
"**/*.models.ts",
|
|
31
|
+
"**/*.const.ts",
|
|
32
|
+
"**/*.constants.ts",
|
|
33
|
+
"**/*.enum.ts",
|
|
34
|
+
"**/*.dto.ts",
|
|
15
35
|
"**/test-setup.ts",
|
|
16
36
|
"**/jest-setup.ts",
|
|
17
37
|
"**/vitest-setup.ts"
|
|
@@ -19,7 +39,29 @@ var DEFAULT_SKIP_PATHS = [
|
|
|
19
39
|
var DEFAULTS = {
|
|
20
40
|
skipPaths: DEFAULT_SKIP_PATHS,
|
|
21
41
|
includeDefaultExports: false,
|
|
22
|
-
includeOrphanFiles: false
|
|
42
|
+
includeOrphanFiles: false,
|
|
43
|
+
includeTypeOnlyExports: false
|
|
44
|
+
};
|
|
45
|
+
var declarationLines = (parsed) => {
|
|
46
|
+
const lines = /* @__PURE__ */ new Map();
|
|
47
|
+
try {
|
|
48
|
+
const sf = asTsMorphSourceFile(parsed);
|
|
49
|
+
const declarations = [
|
|
50
|
+
...sf.getVariableDeclarations(),
|
|
51
|
+
...sf.getFunctions(),
|
|
52
|
+
...sf.getClasses(),
|
|
53
|
+
...sf.getInterfaces(),
|
|
54
|
+
...sf.getEnums(),
|
|
55
|
+
...sf.getTypeAliases()
|
|
56
|
+
];
|
|
57
|
+
for (const declaration of declarations) {
|
|
58
|
+
const name = declaration.getName();
|
|
59
|
+
if (name === void 0 || name === "" || lines.has(name)) continue;
|
|
60
|
+
lines.set(name, sf.getLineAndColumnAtPos(declaration.getStart()).line);
|
|
61
|
+
}
|
|
62
|
+
} catch {
|
|
63
|
+
}
|
|
64
|
+
return lines;
|
|
23
65
|
};
|
|
24
66
|
var REGEX_SPECIAL = new Set(".+^$()|[]\\".split(""));
|
|
25
67
|
var globToRegex = (pattern) => {
|
|
@@ -90,17 +132,19 @@ var consumedNames = (graph, targetPath) => {
|
|
|
90
132
|
};
|
|
91
133
|
var rule = {
|
|
92
134
|
id: "general/no-unused-export",
|
|
93
|
-
|
|
135
|
+
// v2 (ADR-0065): type-only exports off by default, shared-contract skipPaths,
|
|
136
|
+
// finding anchored on the declaration line. Precision v1 đo được 13,3 %.
|
|
137
|
+
version: 2,
|
|
94
138
|
kind: "static-ts",
|
|
95
139
|
title: "Kh\xF4ng export symbol n\u1EBFu kh\xF4ng ai d\xF9ng",
|
|
96
|
-
description: "Symbol \u0111\u01B0\u1EE3c export nh\u01B0ng kh\xF4ng c\xF3 file n\xE0o trong project import l\u1EA1i. Conservative: b\u1ECF qua
|
|
140
|
+
description: "Symbol \u0111\u01B0\u1EE3c export nh\u01B0ng kh\xF4ng c\xF3 file n\xE0o trong project import l\u1EA1i. Conservative: b\u1ECF qua export ki\u1EC3u (interface/type/enum \u2014 m\u1EB7c \u0111\u1ECBnh, v\xEC \u0111\xF3 l\xE0 h\u1EE3p \u0111\u1ED3ng d\xF9ng chung), wildcard re-export targets, default exports, orphan files, v\xE0 c\xE1c file public-API/entry-point/h\u1EE3p \u0111\u1ED3ng (index.ts, public-api.ts, *.module.ts, *.routes.ts, *.types.ts, *.interface.ts, *.const.ts, *.model.ts, *.d.ts, ...). \u26A0 CH\u1EC8 \u0111\xE1ng tin khi qu\xE9t TO\xC0N d\u1EF1 \xE1n: \u0111\u1ED3 th\u1ECB ch\u1EC9 ch\u1EE9a file \u0111\u01B0\u1EE3c qu\xE9t, n\xEAn qu\xE9t m\u1ED9t th\u01B0 m\u1EE5c con s\u1EBD l\xE0m m\u1ECDi export \u1EDF bi\xEAn module tr\xF4ng nh\u01B0 kh\xF4ng ai d\xF9ng.",
|
|
97
141
|
severity: "info",
|
|
98
142
|
category: "maintainability",
|
|
99
143
|
languages: ["typescript", "javascript"],
|
|
100
144
|
scope: "general",
|
|
101
145
|
requires: "semantic-ts",
|
|
102
146
|
usesAstGraph: true,
|
|
103
|
-
baseConfidence:
|
|
147
|
+
baseConfidence: 45,
|
|
104
148
|
defaultOptions: DEFAULTS,
|
|
105
149
|
check(ctx) {
|
|
106
150
|
const graph = ctx.astGraph;
|
|
@@ -108,7 +152,8 @@ var rule = {
|
|
|
108
152
|
const options = {
|
|
109
153
|
skipPaths: ctx.options.skipPaths ?? DEFAULTS.skipPaths,
|
|
110
154
|
includeDefaultExports: ctx.options.includeDefaultExports ?? DEFAULTS.includeDefaultExports,
|
|
111
|
-
includeOrphanFiles: ctx.options.includeOrphanFiles ?? DEFAULTS.includeOrphanFiles
|
|
155
|
+
includeOrphanFiles: ctx.options.includeOrphanFiles ?? DEFAULTS.includeOrphanFiles,
|
|
156
|
+
includeTypeOnlyExports: ctx.options.includeTypeOnlyExports ?? DEFAULTS.includeTypeOnlyExports
|
|
112
157
|
};
|
|
113
158
|
const skipRegexes = compilePatterns(options.skipPaths);
|
|
114
159
|
if (matchesAny(ctx.file.path, skipRegexes)) return [];
|
|
@@ -119,15 +164,17 @@ var rule = {
|
|
|
119
164
|
const hasAnyIncomingEdge = incoming.some((e) => CONSUMING_KINDS.has(e.kind));
|
|
120
165
|
if (!hasAnyIncomingEdge && !options.includeOrphanFiles) return [];
|
|
121
166
|
const consumed = consumedNames(graph, ctx.file.path);
|
|
167
|
+
const lineOf = declarationLines(ctx.parsed);
|
|
122
168
|
const findings = [];
|
|
123
169
|
for (const symbol of node.symbols) {
|
|
124
170
|
if (!symbol.exported) continue;
|
|
125
171
|
if (symbol.name === "default" && !options.includeDefaultExports) continue;
|
|
172
|
+
if (!options.includeTypeOnlyExports && TYPE_ONLY_KINDS.has(symbol.kind)) continue;
|
|
126
173
|
if (consumed.has(symbol.name)) continue;
|
|
127
174
|
findings.push({
|
|
128
175
|
message: `Exported ${symbol.kind} '${symbol.name}' is not imported by any file in the project.`,
|
|
129
176
|
file: ctx.file.path,
|
|
130
|
-
range: { line: 1, column: 1 },
|
|
177
|
+
range: { line: lineOf.get(symbol.name) ?? 1, column: 1 },
|
|
131
178
|
suggestion: "Remove the export, mark the symbol non-exported (file-local), or move it behind the public API barrel that consumers actually import."
|
|
132
179
|
});
|
|
133
180
|
}
|
|
@@ -11,7 +11,14 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "spring-boot/no-command-injection",
|
|
14
|
-
|
|
14
|
+
// v4 (Pentest Coverage Layer P3 #4): the Java analyzer now folds a tainted
|
|
15
|
+
// collection element (`argList.add("echo " + param)`) into the collection so
|
|
16
|
+
// the whole list reaching `pb.command(argList)` / `new ProcessBuilder(argList)`
|
|
17
|
+
// is detected — the dominant OWASP-Benchmark command-injection List shape. The
|
|
18
|
+
// rule's projection logic is unchanged; the bump invalidates findings cached on
|
|
19
|
+
// unchanged file content before the broader analyzer coverage.
|
|
20
|
+
// v5 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
21
|
+
version: 5,
|
|
15
22
|
kind: "static-ts",
|
|
16
23
|
title: "Kh\xF4ng ch\u1EA1y l\u1EC7nh h\u1EC7 th\u1ED1ng t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (OS Command Injection)",
|
|
17
24
|
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.",
|
|
@@ -34,6 +41,12 @@ var rule = {
|
|
|
34
41
|
message: `\u26A0 Command Injection: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ch\u1EA3y v\xE0o ${sinkLabel} \u2014 k\u1EBB t\u1EA5n c\xF4ng c\xF3 th\u1EC3 ch\u1EA1y l\u1EC7nh h\u1EC7 th\u1ED1ng t\xF9y \xFD tr\xEAn server (RCE).${trace}`,
|
|
35
42
|
file: ctx.file.path,
|
|
36
43
|
range: { line: tf.line, column: tf.column ?? 1 },
|
|
44
|
+
// ADR-0065 (calibration): luồng TRỰC TIẾP source→sink lớp RCE là đúng
|
|
45
|
+
// thứ tầng `blocker` sinh ra để chặn — trước bản này catalog KHÔNG có
|
|
46
|
+
// rule nào phát `blocker`, nên thang 4 mức thực chất chỉ có 3.
|
|
47
|
+
// Luồng laundered (truy vết liên thủ tục) giữ `error`: bằng chứng yếu
|
|
48
|
+
// hơn một bậc, không đủ để chặn merge.
|
|
49
|
+
severity: laundered ? "error" : "blocker",
|
|
37
50
|
confidence: laundered ? 75 : 85,
|
|
38
51
|
suggestion: 'Tr\xE1nh g\u1ECDi shell v\u1EDBi d\u1EEF li\u1EC7u ng\u01B0\u1EDDi d\xF9ng. N\u1EBFu b\u1EAFt bu\u1ED9c: validate b\u1EB1ng allowlist l\u1EC7nh/tham s\u1ED1 c\u1ED1 \u0111\u1ECBnh, truy\u1EC1n tham s\u1ED1 d\u1EA1ng m\u1EA3ng (`new ProcessBuilder(List.of("cmd", arg))`) thay v\xEC n\u1ED1i chu\u1ED7i v\xE0o `sh -c`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng d\u1EF1ng l\u1EC7nh t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp.'
|
|
39
52
|
});
|
|
@@ -11,7 +11,7 @@ var SINK_LABEL = {
|
|
|
11
11
|
};
|
|
12
12
|
var rule = {
|
|
13
13
|
id: "spring-boot/no-path-traversal",
|
|
14
|
-
version:
|
|
14
|
+
version: 3,
|
|
15
15
|
kind: "static-ts",
|
|
16
16
|
title: "Kh\xF4ng m\u1EDF file theo \u0111\u01B0\u1EDDng d\u1EABn t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (Path Traversal)",
|
|
17
17
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, @RequestPart, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o \u0111\u01B0\u1EDDng d\u1EABn filesystem (`new File(...)`, `new FileInputStream(...)`, `getResource(...)`) ho\u1EB7c kh\xF3a object-store MinIO (`.object(...)`) l\xE0 l\u1ED7 h\u1ED5ng Path Traversal (CWE-22) \u2014 k\u1EBB t\u1EA5n c\xF4ng d\xF9ng `../../../../etc/passwd` \u0111\u1EC3 \u0111\u1ECDc/ghi file ngo\xE0i th\u01B0 m\u1EE5c d\u1EF1 ki\u1EBFn. Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: chu\u1EA9n h\xF3a \u0111\u01B0\u1EDDng d\u1EABn (`getCanonicalPath()`) r\u1ED3i ki\u1EC3m tra n\u1EB1m trong th\u01B0 m\u1EE5c g\u1ED1c cho ph\xE9p (allowlist); kh\xF4ng bao gi\u1EDD gh\xE9p \u0111\u01B0\u1EDDng d\u1EABn tr\u1EF1c ti\u1EBFp t\u1EEB input ng\u01B0\u1EDDi d\xF9ng.",
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// builtin-rules/static/spring-boot/no-servlet-xss.rule.ts
|
|
2
|
+
var SERVLET_XSS_SINK_IDS = /* @__PURE__ */ new Set(["spring/servlet-writer"]);
|
|
3
|
+
var SINK_LABEL = {
|
|
4
|
+
"spring/servlet-writer": "response.getWriter().write/print(...)"
|
|
5
|
+
};
|
|
6
|
+
var rule = {
|
|
7
|
+
id: "spring-boot/no-servlet-xss",
|
|
8
|
+
version: 1,
|
|
9
|
+
kind: "static-ts",
|
|
10
|
+
title: "Kh\xF4ng ghi d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t v\xE0o response HTML (Reflected XSS)",
|
|
11
|
+
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, Cookie, \u2026) ghi th\u1EB3ng v\xE0o body response qua `response.getWriter().write/print/println/printf/format(...)` m\xE0 kh\xF4ng encode l\xE0 l\u1ED7 h\u1ED5ng Reflected Cross-Site Scripting (CWE-79) \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n `<script>` ch\u1EA1y trong phi\xEAn \u0111\u0103ng nh\u1EADp c\u1EE7a n\u1EA1n nh\xE2n (\u0111\xE1nh c\u1EAFp session, thao t\xE1c thay ng\u01B0\u1EDDi d\xF9ng). Rule d\xF9ng taint analysis (Tier-1 trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u; sink \u0111\u01B0\u1EE3c gate theo receiver `getWriter()` n\xEAn kh\xF4ng nh\u1EA7m v\u1EDBi `System.out.println` / `String.format`. Kh\u1EAFc ph\u1EE5c: HTML-encode gi\xE1 tr\u1ECB tr\u01B0\u1EDBc khi ghi (OWASP Java Encoder `Encode.forHtml(...)`), ho\u1EB7c tr\u1EA3 JSON qua `@ResponseBody` \u0111\u1EC3 Spring t\u1EF1 serialize thay v\xEC ghi tay ra writer.",
|
|
12
|
+
severity: "error",
|
|
13
|
+
category: "security",
|
|
14
|
+
languages: ["java"],
|
|
15
|
+
scope: "spring-boot",
|
|
16
|
+
requires: "syntactic",
|
|
17
|
+
usesTaint: true,
|
|
18
|
+
baseConfidence: 80,
|
|
19
|
+
check(ctx) {
|
|
20
|
+
const findings = [];
|
|
21
|
+
for (const tf of ctx.taintFindings ?? []) {
|
|
22
|
+
if (!SERVLET_XSS_SINK_IDS.has(tf.sinkId)) continue;
|
|
23
|
+
const sources = [...new Set(tf.sourceIds)].join(", ");
|
|
24
|
+
const laundered = (tf.path?.length ?? 0) > 0;
|
|
25
|
+
const sinkLabel = SINK_LABEL[tf.sinkId] ?? tf.sinkId;
|
|
26
|
+
const trace = laundered ? " (truy v\u1EBFt li\xEAn th\u1EE7 t\u1EE5c)" : "";
|
|
27
|
+
findings.push({
|
|
28
|
+
message: `\u26A0 Reflected XSS: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ghi v\xE0o ${sinkLabel} kh\xF4ng encode \u2014 k\u1EBB t\u1EA5n c\xF4ng ch\xE8n \u0111\u01B0\u1EE3c m\xE3 script ch\u1EA1y trong tr\xECnh duy\u1EC7t n\u1EA1n nh\xE2n.${trace}`,
|
|
29
|
+
file: ctx.file.path,
|
|
30
|
+
range: { line: tf.line, column: tf.column ?? 1 },
|
|
31
|
+
confidence: laundered ? 75 : 85,
|
|
32
|
+
suggestion: "HTML-encode gi\xE1 tr\u1ECB tr\u01B0\u1EDBc khi ghi ra response (vd OWASP Java Encoder `Encode.forHtml(value)`), ho\u1EB7c tr\u1EA3 d\u1EEF li\u1EC7u d\u1EA1ng JSON qua `@ResponseBody` / `ResponseEntity` \u0111\u1EC3 framework t\u1EF1 serialize + set content-type an to\xE0n, thay v\xEC ghi HTML tay ra `getWriter()`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng echo input ng\u01B0\u1EDDi d\xF9ng v\xE0o HTML m\xE0 kh\xF4ng escape."
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return findings;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export { rule };
|
|
40
|
+
//# sourceMappingURL=no-servlet-xss.rule.js.map
|
|
41
|
+
//# sourceMappingURL=no-servlet-xss.rule.js.map
|
|
@@ -5,7 +5,8 @@ var SINK_LABEL = {
|
|
|
5
5
|
};
|
|
6
6
|
var rule = {
|
|
7
7
|
id: "spring-boot/no-spel-injection",
|
|
8
|
-
|
|
8
|
+
// v3 (ADR-0065 calibration): luồng taint trực tiếp → severity blocker
|
|
9
|
+
version: 3,
|
|
9
10
|
kind: "static-ts",
|
|
10
11
|
title: "Kh\xF4ng parse SpEL t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (Expression Language Injection)",
|
|
11
12
|
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`.",
|
|
@@ -28,6 +29,12 @@ var rule = {
|
|
|
28
29
|
message: `\u26A0 SpEL Injection: d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (${sources}) ch\u1EA3y v\xE0o ${sinkLabel} \u2014 k\u1EBB t\u1EA5n c\xF4ng c\xF3 th\u1EC3 ch\u1EA1y m\xE3 t\xF9y \xFD qua bi\u1EC3u th\u1EE9c SpEL (RCE).${trace}`,
|
|
29
30
|
file: ctx.file.path,
|
|
30
31
|
range: { line: tf.line, column: tf.column ?? 1 },
|
|
32
|
+
// ADR-0065 (calibration): luồng TRỰC TIẾP source→sink lớp RCE là đúng
|
|
33
|
+
// thứ tầng `blocker` sinh ra để chặn — trước bản này catalog KHÔNG có
|
|
34
|
+
// rule nào phát `blocker`, nên thang 4 mức thực chất chỉ có 3.
|
|
35
|
+
// Luồng laundered (truy vết liên thủ tục) giữ `error`: bằng chứng yếu
|
|
36
|
+
// hơn một bậc, không đủ để chặn merge.
|
|
37
|
+
severity: laundered ? "error" : "blocker",
|
|
31
38
|
confidence: laundered ? 75 : 85,
|
|
32
39
|
suggestion: "Kh\xF4ng 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 \u0111\xE1nh gi\xE1 v\u1EDBi `SimpleEvaluationContext` (ch\u1EB7n type reference / g\u1ECDi method nguy hi\u1EC3m) thay cho `StandardEvaluationContext`. Tuy\u1EC7t \u0111\u1ED1i kh\xF4ng d\u1EF1ng bi\u1EC3u th\u1EE9c t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp."
|
|
33
40
|
});
|
|
@@ -12,7 +12,16 @@ var SQL_SINK_CALLEES = /* @__PURE__ */ new Set([
|
|
|
12
12
|
"queryForRowSet",
|
|
13
13
|
"update",
|
|
14
14
|
"execute",
|
|
15
|
-
"batchUpdate"
|
|
15
|
+
"batchUpdate",
|
|
16
|
+
// v6 (P3 #2): raw JDBC Statement/PreparedStatement sinks — mirrors the new
|
|
17
|
+
// `spring/jdbc-raw` taint sink so a taint-confirmed raw-JDBC concat upgrades
|
|
18
|
+
// to CONFIRMED (error/90) instead of the UNKNOWN advisory band.
|
|
19
|
+
"prepareStatement",
|
|
20
|
+
"prepareCall",
|
|
21
|
+
"executeQuery",
|
|
22
|
+
"executeUpdate",
|
|
23
|
+
"executeLargeUpdate",
|
|
24
|
+
"addBatch"
|
|
16
25
|
]);
|
|
17
26
|
var SANITIZER_CALLEES = /* @__PURE__ */ new Set([
|
|
18
27
|
"parseLong",
|
|
@@ -113,6 +122,18 @@ var isDynamicOperand = (op, staticFinals) => {
|
|
|
113
122
|
}
|
|
114
123
|
return true;
|
|
115
124
|
};
|
|
125
|
+
var isInsideAnnotationArg = (node) => {
|
|
126
|
+
let cur = node.parent;
|
|
127
|
+
while (cur) {
|
|
128
|
+
const t = cur.type;
|
|
129
|
+
if (t === "annotation_argument_list" || t === "annotation") return true;
|
|
130
|
+
if (t === "block" || t === "constructor_body" || t === "class_body" || t === "program") {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
cur = cur.parent;
|
|
134
|
+
}
|
|
135
|
+
return false;
|
|
136
|
+
};
|
|
116
137
|
var enclosingSqlSinkLine = (node) => {
|
|
117
138
|
let cur = node.parent;
|
|
118
139
|
while (cur) {
|
|
@@ -131,7 +152,8 @@ var isConcatRoot = (node) => {
|
|
|
131
152
|
};
|
|
132
153
|
var rule = {
|
|
133
154
|
id: "spring-boot/no-sql-string-concat",
|
|
134
|
-
|
|
155
|
+
// v7 (ADR-0065 calibration): band CONFIRMED → severity blocker
|
|
156
|
+
version: 7,
|
|
135
157
|
kind: "static-ts",
|
|
136
158
|
title: "Kh\xF4ng n\u1ED1i SQL b\u1EB1ng `+` \u2014 d\xF9ng prepared statement / named parameter",
|
|
137
159
|
description: "N\u1ED1i chu\u1ED7i SQL b\u1EB1ng `+` l\xE0 pattern \u0111i\u1EC3n h\xECnh c\u1EE7a SQL Injection. v2 d\xF9ng taint analysis: n\u1ED1i c\xF3 gi\xE1 tr\u1ECB t\u1EEB request (taint-confirmed) \u2192 error tin c\u1EADy cao; n\u1ED1i to\xE0n h\u1EB1ng s\u1ED1 (literal / `static final`) \u2192 b\u1ECF qua; c\xF2n l\u1EA1i gi\u1EEF c\u1EA3nh b\xE1o nh\u01B0 v1. D\xF9ng JdbcTemplate `?` + args, JPQL `:param` + `setParameter(...)`, ho\u1EB7c Spring Data query methods.",
|
|
@@ -141,7 +163,9 @@ var rule = {
|
|
|
141
163
|
scope: "spring-boot",
|
|
142
164
|
requires: "syntactic",
|
|
143
165
|
usesTaint: true,
|
|
144
|
-
|
|
166
|
+
// Declared default `severity: error` applies to the CONFIRMED band only; the
|
|
167
|
+
// UNKNOWN band overrides to `warning`/55 per-finding (v5, ADR-0031).
|
|
168
|
+
baseConfidence: 55,
|
|
145
169
|
check(ctx) {
|
|
146
170
|
const tree = asTreeSitterTree(ctx.parsed);
|
|
147
171
|
const root = tree.rootNode;
|
|
@@ -155,6 +179,7 @@ var rule = {
|
|
|
155
179
|
(op) => op.type === "string_literal" && SQL_KEYWORD.test(op.text)
|
|
156
180
|
);
|
|
157
181
|
if (!hasSqlKeyword) continue;
|
|
182
|
+
if (isInsideAnnotationArg(concat)) continue;
|
|
158
183
|
const dynamicOperands = operands.filter((op) => isDynamicOperand(op, staticFinals));
|
|
159
184
|
if (dynamicOperands.length === 0) continue;
|
|
160
185
|
const range = {
|
|
@@ -173,14 +198,20 @@ var rule = {
|
|
|
173
198
|
message: `\u26A0 SQL Injection x\xE1c nh\u1EADn: gi\xE1 tr\u1ECB t\u1EEB request (${sources}) n\u1ED1i th\u1EB3ng v\xE0o c\xE2u SQL \u2014 d\xF9ng prepared statement / named parameter.`,
|
|
174
199
|
file: ctx.file.path,
|
|
175
200
|
range,
|
|
201
|
+
// ADR-0065: band CONFIRMED = taint đã xác nhận request→SQL sink.
|
|
202
|
+
// Đó là bằng chứng mạnh nhất rule này có → `blocker`. Band UNKNOWN
|
|
203
|
+
// bên dưới vẫn `warning`/55 (advisory) theo ADR-0031.
|
|
204
|
+
severity: "blocker",
|
|
176
205
|
confidence: 90,
|
|
177
206
|
suggestion: "Bind tham s\u1ED1: JdbcTemplate `?` + args, ho\u1EB7c JPQL `:param` + `setParameter(...)`."
|
|
178
207
|
});
|
|
179
208
|
} else {
|
|
180
209
|
findings.push({
|
|
181
|
-
message: "
|
|
210
|
+
message: "N\u1ED1i chu\u1ED7i SQL \u0111\u1ED9ng \u2014 taint kh\xF4ng x\xE1c nh\u1EADn \u0111\u01B0\u1EE3c ngu\u1ED3n t\u1EEB request, ch\u01B0a r\xF5 \u0111\xE3 tham s\u1ED1 ho\xE1 hay ch\u01B0a. Review th\u1EE7 c\xF4ng (advisory, KH\xD4NG ch\u1EB7n merge): n\u1EBFu m\u1ECDi gi\xE1 tr\u1ECB \u0111\xE3 bind qua `?` / `:param` th\xEC b\u1ECF qua.",
|
|
182
211
|
file: ctx.file.path,
|
|
183
212
|
range,
|
|
213
|
+
severity: "warning",
|
|
214
|
+
confidence: 55,
|
|
184
215
|
suggestion: "JdbcTemplate `?` placeholders + args, ho\u1EB7c JPQL `:param` + `setParameter(...)`, ho\u1EB7c Spring Data query methods."
|
|
185
216
|
});
|
|
186
217
|
}
|
|
@@ -13,7 +13,7 @@ var SINK_LABEL = {
|
|
|
13
13
|
};
|
|
14
14
|
var rule = {
|
|
15
15
|
id: "spring-boot/no-ssrf",
|
|
16
|
-
version:
|
|
16
|
+
version: 4,
|
|
17
17
|
kind: "static-ts",
|
|
18
18
|
title: "Kh\xF4ng g\u1ECDi HTTP ra ngo\xE0i b\u1EB1ng URL t\u1EEB d\u1EEF li\u1EC7u ch\u01B0a ki\u1EC3m so\xE1t (SSRF)",
|
|
19
19
|
description: "D\u1EEF li\u1EC7u t\u1EEB request (@RequestParam, @PathVariable, @RequestBody, @RequestHeader, HttpServletRequest, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o URL c\u1EE7a m\u1ED9t l\u1EDDi g\u1ECDi HTTP ra ngo\xE0i (RestTemplate `getForObject`/`exchange`/\u2026, WebClient `.uri(...)`, ho\u1EB7c OkHttp `Request.Builder.url(...)`) l\xE0 l\u1ED7 h\u1ED5ng Server-Side Request Forgery (CWE-918) \u2014 k\u1EBB t\u1EA5n c\xF4ng \u0111i\u1EC1u khi\u1EC3n server g\u1ECDi t\u1EDBi \u0111\u1ECBa ch\u1EC9 n\u1ED9i b\u1ED9 / metadata cloud (vd. 169.254.169.254) ho\u1EB7c d\u1ECBch v\u1EE5 n\u1ED9i b\u1ED9 kh\xF4ng \u0111\u01B0\u1EE3c ph\xE9p truy c\u1EADp t\u1EEB b\xEAn ngo\xE0i. Rule d\xF9ng taint analysis (Tier-1 li\xEAn th\u1EE7 t\u1EE5c trong c\xF9ng method) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: validate URL b\u1EB1ng allowlist host/scheme c\u1ED1 \u0111\u1ECBnh; kh\xF4ng bao gi\u1EDD gh\xE9p URL \u0111\xEDch tr\u1EF1c ti\u1EBFp t\u1EEB gi\xE1 tr\u1ECB do ng\u01B0\u1EDDi d\xF9ng nh\u1EADp.",
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { asTreeSitterTree } from '@code-sentinel/parsers';
|
|
2
|
+
|
|
3
|
+
// builtin-rules/static/spring-boot/no-unzoned-datetime.rule.ts
|
|
4
|
+
var UNZONED_STATIC_OBJECTS = /* @__PURE__ */ new Set([
|
|
5
|
+
"LocalDateTime",
|
|
6
|
+
"LocalDate",
|
|
7
|
+
"LocalTime"
|
|
8
|
+
]);
|
|
9
|
+
var CALENDAR_OBJECTS = /* @__PURE__ */ new Set(["Calendar", "GregorianCalendar"]);
|
|
10
|
+
var isTestFile = (path) => {
|
|
11
|
+
const norm = path.replace(/\\/g, "/").toLowerCase();
|
|
12
|
+
return norm.includes("/test/") || norm.includes("/test-fixtures/") || norm.endsWith("test.java") || norm.endsWith("tests.java") || norm.endsWith("testcase.java");
|
|
13
|
+
};
|
|
14
|
+
function* walkNodes(node) {
|
|
15
|
+
const stack = [node];
|
|
16
|
+
while (stack.length > 0) {
|
|
17
|
+
const cur = stack.pop();
|
|
18
|
+
if (!cur) break;
|
|
19
|
+
yield cur;
|
|
20
|
+
for (let i = cur.namedChildCount - 1; i >= 0; i--) {
|
|
21
|
+
const child = cur.namedChild(i);
|
|
22
|
+
if (child) stack.push(child);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
var rule = {
|
|
27
|
+
id: "spring-boot/no-unzoned-datetime",
|
|
28
|
+
version: 1,
|
|
29
|
+
kind: "static-ts",
|
|
30
|
+
title: "Kh\xF4ng g\u1ECDi `LocalDateTime.now()` ho\u1EB7c `new Date()` thi\u1EBFu `Clock`/`ZoneId`",
|
|
31
|
+
description: "G\u1ECDi `LocalDateTime.now()`, `new Date()`, `Calendar.getInstance()` kh\xF4ng truy\u1EC1n `Clock` ho\u1EB7c `ZoneId` ng\u1EA7m s\u1EED d\u1EE5ng m\xFAi gi\u1EDD c\u1EE7a m\xE1y ch\u1EE7. Khi ch\u1EA1y tr\xEAn m\xF4i tr\u01B0\u1EDDng Cloud/K8s c\xF3 m\xFAi gi\u1EDD UTC, \u0111i\u1EC1u n\xE0y d\u1EABn \u0111\u1EBFn sai l\u1EC7ch d\u1EEF li\u1EC7u ng\xE0y gi\u1EDD v\xE0 kh\xF4ng th\u1EC3 mock khi vi\u1EBFt test.",
|
|
32
|
+
severity: "warning",
|
|
33
|
+
category: "correctness",
|
|
34
|
+
languages: ["java"],
|
|
35
|
+
scope: "spring-boot",
|
|
36
|
+
requires: "syntactic",
|
|
37
|
+
baseConfidence: 80,
|
|
38
|
+
check(ctx) {
|
|
39
|
+
if (isTestFile(ctx.file.path)) return [];
|
|
40
|
+
const tree = asTreeSitterTree(ctx.parsed);
|
|
41
|
+
const findings = [];
|
|
42
|
+
for (const node of walkNodes(tree.rootNode)) {
|
|
43
|
+
if (node.type === "method_invocation") {
|
|
44
|
+
const nameNode = node.childForFieldName("name");
|
|
45
|
+
const objectNode = node.childForFieldName("object");
|
|
46
|
+
const argsNode = node.childForFieldName("arguments");
|
|
47
|
+
if (nameNode && objectNode && argsNode) {
|
|
48
|
+
const methodName = nameNode.text;
|
|
49
|
+
const objectName = objectNode.text;
|
|
50
|
+
const argCount = argsNode.namedChildCount;
|
|
51
|
+
if (methodName === "now" && UNZONED_STATIC_OBJECTS.has(objectName) && argCount === 0) {
|
|
52
|
+
findings.push({
|
|
53
|
+
message: `G\u1ECDi \`${objectName}.now()\` kh\xF4ng truy\u1EC1n \`ZoneId\` ho\u1EB7c \`Clock\` \u2014 r\u1EE7i ro sai l\u1EC7ch m\xFAi gi\u1EDD tr\xEAn K8s/Cloud v\xE0 kh\xF4ng th\u1EC3 mock khi vi\u1EBFt unit test.`,
|
|
54
|
+
file: ctx.file.path,
|
|
55
|
+
range: {
|
|
56
|
+
line: node.startPosition.row + 1,
|
|
57
|
+
column: node.startPosition.column + 1
|
|
58
|
+
},
|
|
59
|
+
suggestion: `D\xF9ng \`Instant.now(clock)\` ho\u1EB7c truy\u1EC1n \`ZoneId.of("...")\` / \`Clock\` v\xE0o \`${objectName}.now(...)\`.`
|
|
60
|
+
});
|
|
61
|
+
} else if (methodName === "getInstance" && CALENDAR_OBJECTS.has(objectName) && argCount === 0) {
|
|
62
|
+
findings.push({
|
|
63
|
+
message: `G\u1ECDi \`${objectName}.getInstance()\` ng\u1EA7m l\u1EA5y timezone v\xE0 locale c\u1EE7a JVM. N\xEAn d\xF9ng java.time API (\`ZonedDateTime\`, \`Instant\`) v\u1EDBi Clock t\u01B0\u1EDDng minh.`,
|
|
64
|
+
file: ctx.file.path,
|
|
65
|
+
range: {
|
|
66
|
+
line: node.startPosition.row + 1,
|
|
67
|
+
column: node.startPosition.column + 1
|
|
68
|
+
},
|
|
69
|
+
suggestion: "Chuy\u1EC3n sang d\xF9ng `java.time` API (`ZonedDateTime.now(zoneId)` / `Instant.now(clock)`)."
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
if (node.type === "object_creation_expression") {
|
|
75
|
+
const typeNode = node.childForFieldName("type");
|
|
76
|
+
const argsNode = node.childForFieldName("arguments");
|
|
77
|
+
if (typeNode && argsNode && typeNode.text === "Date" && argsNode.namedChildCount === 0) {
|
|
78
|
+
findings.push({
|
|
79
|
+
message: "Kh\u1EDFi t\u1EA1o `new Date()` ng\u1EA7m s\u1EED d\u1EE5ng system clock c\u1EE7a m\xE1y ch\u1EE7 v\xE0 l\xE0 legacy API. N\xEAn d\xF9ng `Instant.now(clock)` \u0111\u1EC3 c\xF3 th\u1EC3 inject Clock khi test.",
|
|
80
|
+
file: ctx.file.path,
|
|
81
|
+
range: {
|
|
82
|
+
line: node.startPosition.row + 1,
|
|
83
|
+
column: node.startPosition.column + 1
|
|
84
|
+
},
|
|
85
|
+
suggestion: "S\u1EED d\u1EE5ng `Instant.now(clock)` ho\u1EB7c `Clock.systemUTC()` thay cho `new Date()`."
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return findings;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { rule };
|
|
95
|
+
//# sourceMappingURL=no-unzoned-datetime.rule.js.map
|
|
96
|
+
//# sourceMappingURL=no-unzoned-datetime.rule.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
id: spring-boot/repository-naming
|
|
2
|
-
|
|
2
|
+
# v2 (ADR-0065 calibration): severity warning→info (quy ước đặt tên)
|
|
3
|
+
version: 2
|
|
3
4
|
kind: static-yaml
|
|
4
5
|
title: "Spring Data interface phải kết thúc bằng `Repository`"
|
|
5
6
|
description: |
|
|
@@ -14,7 +15,8 @@ description: |
|
|
|
14
15
|
Phase 8: dùng negative lookahead `(?!...)` trong regex predicate để
|
|
15
16
|
loại trừ tên đã đúng (vd `UserRepository`). Match cả `extends X` lẫn
|
|
16
17
|
`extends X<...>` (generic).
|
|
17
|
-
|
|
18
|
+
# ADR-0065: quy ước đặt tên thuần tuý → info (đồng bộ angular/observable-naming).
|
|
19
|
+
severity: info
|
|
18
20
|
category: naming
|
|
19
21
|
languages: [java]
|
|
20
22
|
scope: spring-boot
|