@code-sentinel-cli/code-sentinel-cli 4.0.2 → 4.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/bin.js +23934 -19887
  2. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +47 -8
  3. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +1 -1
  4. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.prompt.md +128 -0
  5. package/dist/builtin-rules/ai/spring-boot/state-transition-guard-risk.rule.yaml +27 -0
  6. package/dist/builtin-rules/static/angular/sensitive-input-masking.rule.js +97 -0
  7. package/dist/builtin-rules/static/flutter/android-debug-certificate-risk.rule.js +140 -0
  8. package/dist/builtin-rules/static/flutter/android-minsdk-low.rule.js +108 -0
  9. package/dist/builtin-rules/static/general/dockerfile-dependency-confusion.rule.js +34 -0
  10. package/dist/builtin-rules/static/general/dockerfile-no-root-user.rule.js +37 -0
  11. package/dist/builtin-rules/static/general/html-password-autocomplete-off.rule.js +34 -0
  12. package/dist/builtin-rules/static/general/no-client-identity-header.rule.js +47 -0
  13. package/dist/builtin-rules/static/general/no-empty-encryption-key.rule.js +79 -0
  14. package/dist/builtin-rules/static/general/no-guessable-websql-database-name.rule.js +39 -0
  15. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +22 -3
  16. package/dist/builtin-rules/static/general/no-insecure-external-link.rule.js +52 -0
  17. package/dist/builtin-rules/static/general/no-insecure-password-submission.rule.js +75 -0
  18. package/dist/builtin-rules/static/general/no-reflective-access-override.rule.js +50 -0
  19. package/dist/builtin-rules/static/general/no-sensitive-string-materialization.rule.js +124 -0
  20. package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +65 -0
  21. package/dist/builtin-rules/static/general/sensitive-output-exposure.rule.js +30 -0
  22. package/dist/builtin-rules/static/spring-boot/mfa-enforcement-required.rule.js +110 -0
  23. package/dist/builtin-rules/static/spring-boot/no-cleartext-http-client.rule.js +53 -0
  24. package/dist/builtin-rules/static/spring-boot/no-devtools-in-production.rule.js +37 -0
  25. package/dist/builtin-rules/static/spring-boot/no-print-stack-trace.rule.js +71 -0
  26. package/dist/builtin-rules/static/spring-boot/no-sensitive-config-response.rule.js +53 -0
  27. package/dist/builtin-rules/static/spring-boot/no-weak-tls-protocol.rule.js +57 -0
  28. package/dist/builtin-rules/static/spring-boot/password-expiration-policy.rule.js +104 -0
  29. package/dist/index.js +23933 -19886
  30. package/node_modules/@code-sentinel/parsers/index.js +527 -6
  31. package/package.json +1 -1
@@ -0,0 +1,65 @@
1
+ import { maskJsComments } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-unsafe-html-sink.rule.ts
4
+ var JQUERY_HTML_RE = /(?:\$|jQuery)\s*\([^\n)]{1,240}\)\s*\.\s*html\s*\(\s*([^;\n)]{1,240})\s*\)/g;
5
+ var INNER_HTML_RE = /\.\s*(innerHTML|outerHTML)\s*=\s*([^;\n]{1,240})/g;
6
+ var INSERT_ADJACENT_HTML_RE = /\.\s*insertAdjacentHTML\s*\(\s*[^,;\n]+\s*,\s*([^;\n)]{1,240})\s*\)/g;
7
+ var DOCUMENT_WRITE_RE = /\bdocument\s*\.\s*(write|writeln)\s*\(\s*([^;\n)]{1,240})\s*\)/g;
8
+ var HTML_COMMENT_RE = /<!--[\s\S]*?-->/g;
9
+ var STATIC_LITERAL_RE = /^(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*")$/;
10
+ var ENCODED_VALUE_RE = /\b(?:sanitize|sanitise|dompurify|escapehtml|htmlencode|encodehtml)\b/i;
11
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
12
+ var isSafeStaticValue = (value) => {
13
+ const trimmed = value.trim();
14
+ return STATIC_LITERAL_RE.test(trimmed) || ENCODED_VALUE_RE.test(trimmed);
15
+ };
16
+ var matches = (content) => {
17
+ const found = [];
18
+ const add = (api, value, index) => {
19
+ if (value === void 0 || index === void 0 || isSafeStaticValue(value)) return;
20
+ found.push({ api, value: value.trim(), index });
21
+ };
22
+ JQUERY_HTML_RE.lastIndex = 0;
23
+ for (const match of content.matchAll(JQUERY_HTML_RE)) add("jQuery.html()", match[1], match.index);
24
+ INNER_HTML_RE.lastIndex = 0;
25
+ for (const match of content.matchAll(INNER_HTML_RE))
26
+ add(`${match[1] ?? "innerHTML"} assignment`, match[2], match.index);
27
+ INSERT_ADJACENT_HTML_RE.lastIndex = 0;
28
+ for (const match of content.matchAll(INSERT_ADJACENT_HTML_RE))
29
+ add("insertAdjacentHTML()", match[1], match.index);
30
+ DOCUMENT_WRITE_RE.lastIndex = 0;
31
+ for (const match of content.matchAll(DOCUMENT_WRITE_RE))
32
+ add(`document.${match[1] ?? "write"}()`, match[2], match.index);
33
+ return found.sort((a, b) => a.index - b.index);
34
+ };
35
+ var rule = {
36
+ id: "general/no-unsafe-html-sink",
37
+ version: 1,
38
+ kind: "static-ts",
39
+ title: "Kh\xF4ng \u0111\u01B0a gi\xE1 tr\u1ECB \u0111\u1ED9ng v\xE0o HTML sink kh\xF4ng \u0111\u01B0\u1EE3c encode",
40
+ description: "Ph\xE1t hi\u1EC7n jQuery.html(), innerHTML/outerHTML, insertAdjacentHTML() v\xE0 document.write() nh\u1EADn gi\xE1 tr\u1ECB \u0111\u1ED9ng. \u0110\xE2y l\xE0 HTML Injection; n\u1EBFu gi\xE1 tr\u1ECB \u0111\u01B0\u1EE3c l\u01B0u v\xE0 hi\u1EC3n th\u1ECB l\u1EA1i th\xEC c\xF3 th\u1EC3 l\xE0 Stored XSS.",
41
+ severity: "warning",
42
+ category: "security",
43
+ languages: ["typescript", "javascript", "html"],
44
+ scope: "general",
45
+ requires: "syntactic",
46
+ usesParser: false,
47
+ baseConfidence: 80,
48
+ check(ctx) {
49
+ const content = maskJsComments(ctx.file.content).replace(
50
+ HTML_COMMENT_RE,
51
+ (comment) => comment.replace(/[^\n]/g, " ")
52
+ );
53
+ return matches(content).map((match) => ({
54
+ file: ctx.file.path,
55
+ range: { line: lineOf(content, match.index), column: 1 },
56
+ confidence: 80,
57
+ message: `${match.api} nh\u1EADn gi\xE1 tr\u1ECB \u0111\u1ED9ng \`${match.value}\` v\xE0 \u0111\u01B0a th\u1EB3ng v\xE0o DOM (HTML Injection; c\xF3 th\u1EC3 l\xE0 Stored XSS n\u1EBFu d\u1EEF li\u1EC7u \u0111\u01B0\u1EE3c l\u01B0u r\u1ED3i render l\u1EA1i).`,
58
+ suggestion: "D\xF9ng textContent/jQuery.text()/Angular interpolation \u0111\u1EC3 hi\u1EC3n th\u1ECB text. N\u1EBFu nghi\u1EC7p v\u1EE5 b\u1EAFt bu\u1ED9c HTML, sanitize b\u1EB1ng allowlist \u0111\xE1ng tin c\u1EADy tr\u01B0\u1EDBc khi render; ki\u1EC3m th\u1EED lu\u1ED3ng t\u1EA1o/s\u1EEDa \u2192 l\u01B0u \u2192 m\u1EDF l\u1EA1i b\u1EB1ng ng\u01B0\u1EDDi d\xF9ng kh\xE1c \u0111\u1EC3 x\xE1c nh\u1EADn ho\u1EB7c lo\u1EA1i tr\u1EEB Stored XSS."
59
+ }));
60
+ }
61
+ };
62
+
63
+ export { rule };
64
+ //# sourceMappingURL=no-unsafe-html-sink.rule.js.map
65
+ //# sourceMappingURL=no-unsafe-html-sink.rule.js.map
@@ -0,0 +1,30 @@
1
+ import { findSensitiveOutput } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/sensitive-output-exposure.rule.ts
4
+ var rule = {
5
+ id: "general/sensitive-output-exposure",
6
+ version: 1,
7
+ kind: "static-ts",
8
+ title: "Kh\xF4ng ghi d\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m ra log ho\u1EB7c console",
9
+ description: "Ph\xE1t hi\u1EC7n password/token/secret/PII b\u1ECB \u0111\u01B0a v\xE0o Java logger, System.out/System.err, ho\u1EB7c browser console. D\xF9ng c\xF9ng b\u1EB1ng ch\u1EE9ng v\u1EDBi `cs assess` checklist #83 (CWE-532).",
10
+ severity: "warning",
11
+ category: "security",
12
+ languages: ["java", "typescript", "javascript"],
13
+ scope: "general",
14
+ requires: "syntactic",
15
+ usesParser: false,
16
+ baseConfidence: 75,
17
+ check(ctx) {
18
+ return findSensitiveOutput([ctx.file]).map((hit) => ({
19
+ message: hit.note,
20
+ file: hit.file,
21
+ range: { line: hit.line, column: 1 },
22
+ confidence: hit.confidence,
23
+ suggestion: "Kh\xF4ng ghi gi\xE1 tr\u1ECB nh\u1EA1y c\u1EA3m ra log/console. Xo\xE1 tr\u01B0\u1EDDng \u0111\xF3 kh\u1ECFi payload ho\u1EB7c mask/redact tr\u01B0\u1EDBc khi ghi."
24
+ }));
25
+ }
26
+ };
27
+
28
+ export { rule };
29
+ //# sourceMappingURL=sensitive-output-exposure.rule.js.map
30
+ //# sourceMappingURL=sensitive-output-exposure.rule.js.map
@@ -0,0 +1,110 @@
1
+ // builtin-rules/static/spring-boot/mfa-enforcement-required.rule.ts
2
+ var JAVA_FILE_RE = /\.java$/i;
3
+ var CONFIG_FILE_RE = /\.(?:ya?ml|properties)$/i;
4
+ var AUTH_ENDPOINT_RE = /@(?:PostMapping|RequestMapping)\s*\(\s*(?:value\s*=\s*)?["'][^"']*(?:login|authenticate|signin)["']/i;
5
+ var MFA_DISABLED_CODE_RE = /\b(?:boolean|Boolean)\s+(?:mfaEnabled|twoFactorEnabled|otpEnabled)\s*=\s*false\b/i;
6
+ var TOKEN_ISSUANCE_RE = /\b(?:generateToken|createToken|createAccessToken|generateAccessToken|token|jwt)\b/i;
7
+ var MFA_KEYWORD_RE = /\b(?:otp|mfa|2fa|totp|twoFactor|secondFactor|webauthn|authenticator|smsService|mailOtp)\b/i;
8
+ var rule = {
9
+ id: "spring-boot/mfa-enforcement-required",
10
+ version: 1,
11
+ kind: "static-ts",
12
+ title: "Y\xEAu c\u1EA7u x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 (MFA / 2FA) cho h\u1EC7 th\u1ED1ng x\xE1c th\u1EF1c ng\u01B0\u1EDDi d\xF9ng (CWE-308)",
13
+ description: "Ph\xE1t hi\u1EC7n lu\u1ED3ng x\xE1c th\u1EF1c \u0111\u0103ng nh\u1EADp ng\u01B0\u1EDDi d\xF9ng ch\u1EC9 s\u1EED d\u1EE5ng m\u1ED9t y\u1EBFu t\u1ED1 (username/password) m\xE0 kh\xF4ng c\xF3 x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 (MFA/2FA/OTP), ho\u1EB7c c\u1EA5u h\xECnh t\u1EAFt MFA (`mfa.enabled: false`). Theo chu\u1EA9n ATTT, h\u1EC7 th\u1ED1ng x\xE1c th\u1EF1c ng\u01B0\u1EDDi d\xF9ng b\u1EAFt bu\u1ED9c ph\u1EA3i h\u1ED7 tr\u1EE3 x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 (CWE-308).",
14
+ severity: "warning",
15
+ category: "security",
16
+ languages: ["java", "yaml", "text"],
17
+ scope: "spring-boot",
18
+ requires: "text",
19
+ usesParser: false,
20
+ baseConfidence: 80,
21
+ check(ctx) {
22
+ const file = ctx.file;
23
+ const isJava = JAVA_FILE_RE.test(file.path);
24
+ const isConfig = CONFIG_FILE_RE.test(file.path);
25
+ if (!isJava && !isConfig) return [];
26
+ const findings = [];
27
+ const lines = file.content.split("\n");
28
+ if (isConfig) {
29
+ const stack = [];
30
+ for (let i = 0; i < lines.length; i++) {
31
+ const line = lines[i] ?? "";
32
+ const trimmed = line.trim();
33
+ if (!trimmed || trimmed.startsWith("#")) continue;
34
+ const indent = (line.match(/^(\s*)/)?.[1] ?? "").length;
35
+ while (stack.length > 0 && (stack[stack.length - 1]?.indent ?? 0) >= indent) {
36
+ stack.pop();
37
+ }
38
+ const colonIdx = trimmed.indexOf(":");
39
+ const eqIdx = trimmed.indexOf("=");
40
+ let sepIdx = -1;
41
+ if (colonIdx !== -1 && eqIdx !== -1) sepIdx = Math.min(colonIdx, eqIdx);
42
+ else if (colonIdx !== -1) sepIdx = colonIdx;
43
+ else if (eqIdx !== -1) sepIdx = eqIdx;
44
+ if (sepIdx !== -1) {
45
+ const keyPart = trimmed.slice(0, sepIdx).trim();
46
+ const valPart = trimmed.slice(sepIdx + 1).trim();
47
+ const fullKey = [...stack.map((s) => s.key), keyPart].join(".");
48
+ if (!valPart) {
49
+ stack.push({ indent, key: keyPart });
50
+ } else {
51
+ if (/(?:mfa|2fa|two-factor|otp)\.enabled$/i.test(fullKey) && /^false\b/i.test(valPart)) {
52
+ findings.push({
53
+ message: `C\u1EA5u h\xECnh t\u1EAFt x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1: \`${fullKey} = false\` \u2014 vi ph\u1EA1m y\xEAu c\u1EA7u MFA b\u1EAFt bu\u1ED9c (CWE-308).`,
54
+ file: file.path,
55
+ range: { line: i + 1, column: 1 },
56
+ severity: "warning",
57
+ confidence: 85,
58
+ suggestion: "B\u1EADt c\u1EA5u h\xECnh x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 (`enabled: true`) v\xE0 t\xEDch h\u1EE3p c\u01A1 ch\u1EBF OTP/TOTP khi \u0111\u0103ng nh\u1EADp."
59
+ });
60
+ }
61
+ }
62
+ }
63
+ }
64
+ return findings;
65
+ }
66
+ if (isJava) {
67
+ for (let i = 0; i < lines.length; i++) {
68
+ const line = lines[i] ?? "";
69
+ const trimmed = line.trim();
70
+ if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("*")) continue;
71
+ if (MFA_DISABLED_CODE_RE.test(trimmed)) {
72
+ findings.push({
73
+ message: "C\u1EDD k\xEDch ho\u1EA1t x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 b\u1ECB v\xF4 hi\u1EC7u ho\xE1 c\u1EE9ng trong m\xE3 ngu\u1ED3n (`mfaEnabled = false`) \u2014 CWE-308.",
74
+ file: file.path,
75
+ range: { line: i + 1, column: 1 },
76
+ severity: "warning",
77
+ confidence: 90,
78
+ suggestion: "K\xEDch ho\u1EA1t x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 cho to\xE0n b\u1ED9 ng\u01B0\u1EDDi d\xF9ng/qu\u1EA3n tr\u1ECB vi\xEAn."
79
+ });
80
+ }
81
+ }
82
+ if (AUTH_ENDPOINT_RE.test(file.content)) {
83
+ const hasTokenIssuance = TOKEN_ISSUANCE_RE.test(file.content);
84
+ const hasMfaKeywords = MFA_KEYWORD_RE.test(file.content);
85
+ if (hasTokenIssuance && !hasMfaKeywords) {
86
+ let endpointLine = 1;
87
+ for (let i = 0; i < lines.length; i++) {
88
+ if (AUTH_ENDPOINT_RE.test(lines[i] ?? "")) {
89
+ endpointLine = i + 1;
90
+ break;
91
+ }
92
+ }
93
+ findings.push({
94
+ message: "Endpoint \u0111\u0103ng nh\u1EADp ph\xE1t sinh token truy c\u1EADp tr\u1EF1c ti\u1EBFp ch\u1EC9 d\u1EF1a tr\xEAn username/password m\xE0 kh\xF4ng c\xF3 b\u01B0\u1EDBc x\xE1c th\u1EF1c \u0111a y\u1EBFu t\u1ED1 (MFA/2FA/OTP) \u2014 CWE-308.",
95
+ file: file.path,
96
+ range: { line: endpointLine, column: 1 },
97
+ severity: "warning",
98
+ confidence: 75,
99
+ suggestion: "B\u1ED5 sung b\u01B0\u1EDBc x\xE1c th\u1EF1c y\u1EBFu t\u1ED1 th\u1EE9 hai (OTP qua SMS/Email/TOTP Authenticator) tr\u01B0\u1EDBc khi c\u1EA5p token ch\xEDnh th\u1EE9c."
100
+ });
101
+ }
102
+ }
103
+ }
104
+ return findings;
105
+ }
106
+ };
107
+
108
+ export { rule };
109
+ //# sourceMappingURL=mfa-enforcement-required.rule.js.map
110
+ //# sourceMappingURL=mfa-enforcement-required.rule.js.map
@@ -0,0 +1,53 @@
1
+ import { isExcludedHost } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/no-cleartext-http-client.rule.ts
4
+ var JAVA_FILE_RE = /\.java$/i;
5
+ var CLEARTEXT_CLIENT_CALL_RE = /(?:@FeignClient\b[^)]*\burl\s*=\s*["'](http:\/\/[^"'\s>]+)["']|(?:RestTemplate|restTemplate|WebClient|webClient|HttpClient|httpClient|new\s+URL)\b[^;]*?["'](http:\/\/[^"'\s>]+)["']|new\s+Http(?:Get|Post|Put|Delete)\s*\(\s*["'](http:\/\/[^"'\s>]+)["'])/gi;
6
+ var rule = {
7
+ id: "spring-boot/no-cleartext-http-client",
8
+ version: 1,
9
+ kind: "static-ts",
10
+ title: "Kh\xF4ng s\u1EED d\u1EE5ng giao th\u1EE9c HTTP cleartext trong HTTP client backend (CWE-319)",
11
+ description: "Ph\xE1t hi\u1EC7n backend client (Spring FeignClient, RestTemplate, WebClient, Java URL, Apache HttpClient) k\u1EBFt n\u1ED1i t\u1EDBi d\u1ECBch v\u1EE5 ngo\u1EA1i b\u1ED9 ho\u1EB7c microservice qua giao th\u1EE9c HTTP kh\xF4ng m\xE3 h\xF3a (cleartext). D\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m, token x\xE1c th\u1EF1c v\xE0 payload c\xF3 th\u1EC3 b\u1ECB nghe l\xE9n ho\u1EB7c s\u1EEDa \u0111\u1ED5i tr\xEAn \u0111\u01B0\u1EDDng truy\u1EC1n (CWE-319).",
12
+ severity: "error",
13
+ category: "security",
14
+ languages: ["java"],
15
+ scope: "spring-boot",
16
+ requires: "text",
17
+ usesParser: false,
18
+ baseConfidence: 90,
19
+ check(ctx) {
20
+ const file = ctx.file;
21
+ if (!JAVA_FILE_RE.test(file.path)) return [];
22
+ const findings = [];
23
+ const lines = file.content.split("\n");
24
+ for (let i = 0; i < lines.length; i++) {
25
+ const line = lines[i] ?? "";
26
+ const trimmed = line.trim();
27
+ if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("*")) continue;
28
+ CLEARTEXT_CLIENT_CALL_RE.lastIndex = 0;
29
+ let match = CLEARTEXT_CLIENT_CALL_RE.exec(trimmed);
30
+ while (match !== null) {
31
+ const url = match[1] ?? match[2] ?? match[3] ?? "";
32
+ const hostMatch = url.match(/^http:\/\/([A-Za-z0-9._\-]+(?::\d+)?)/i);
33
+ const host = hostMatch?.[1] ?? "";
34
+ if (host && !isExcludedHost(host)) {
35
+ findings.push({
36
+ message: `K\u1EBFt n\u1ED1i HTTP client t\u1EDBi \`${url}\` qua giao th\u1EE9c cleartext kh\xF4ng m\xE3 h\xF3a (CWE-319).`,
37
+ file: file.path,
38
+ range: { line: i + 1, column: 1 },
39
+ severity: "error",
40
+ confidence: 90,
41
+ suggestion: "Chuy\u1EC3n \u0111\u1ED5i URL sang giao th\u1EE9c HTTPS (`https://`) k\xE8m x\xE1c th\u1EF1c ch\u1EE9ng ch\u1EC9 CA h\u1EE3p l\u1EC7."
42
+ });
43
+ }
44
+ match = CLEARTEXT_CLIENT_CALL_RE.exec(trimmed);
45
+ }
46
+ }
47
+ return findings;
48
+ }
49
+ };
50
+
51
+ export { rule };
52
+ //# sourceMappingURL=no-cleartext-http-client.rule.js.map
53
+ //# sourceMappingURL=no-cleartext-http-client.rule.js.map
@@ -0,0 +1,37 @@
1
+ import { DEVTOOLS_BUILD_FILE_RE, auditBuildFile } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/no-devtools-in-production.rule.ts
4
+ var rule = {
5
+ id: "spring-boot/no-devtools-in-production",
6
+ version: 2,
7
+ kind: "static-ts",
8
+ title: "Khai b\xE1o Spring Boot DevTools an to\xE0n b\u1EB1ng optional ho\u1EB7c developmentOnly (CWE-489)",
9
+ description: "Ph\xE1t hi\u1EC7n dependency 'spring-boot-devtools' \u0111\u01B0\u1EE3c khai b\xE1o trong pom.xml thi\u1EBFu '<optional>true</optional>' ho\u1EB7c d\xF9ng c\u1EA5u h\xECnh 'implementation' trong Gradle, khi\u1EBFn DevTools c\xF3 nguy c\u01A1 b\u1ECB \u0111\xF3ng g\xF3i v\xE0o s\u1EA3n ph\u1EA9m production m\u1EDF ra c\xE1c c\u1ED5ng debug, reload v\xE0 H2 console.",
10
+ severity: "error",
11
+ category: "security",
12
+ languages: ["xml", "text"],
13
+ scope: "spring-boot",
14
+ requires: "text",
15
+ usesParser: false,
16
+ baseConfidence: 90,
17
+ check(ctx) {
18
+ const file = ctx.file;
19
+ if (!DEVTOOLS_BUILD_FILE_RE.test(file.path)) return [];
20
+ const finding = auditBuildFile(file.content, file.path);
21
+ if (!finding?.isVulnerable) return [];
22
+ return [
23
+ {
24
+ message: finding.reason,
25
+ file: file.path,
26
+ range: { line: finding.line, column: 1 },
27
+ severity: "error",
28
+ confidence: 90,
29
+ suggestion: file.path.toLowerCase().endsWith("pom.xml") ? "Th\xEAm '<optional>true</optional>' v\xE0o b\xEAn trong kh\u1ED1i <dependency> c\u1EE7a spring-boot-devtools." : "Chuy\u1EC3n c\u1EA5u h\xECnh t\u1EEB 'implementation' / 'compileOnly' sang 'developmentOnly' (v\xED d\u1EE5: developmentOnly 'org.springframework.boot:spring-boot-devtools')."
30
+ }
31
+ ];
32
+ }
33
+ };
34
+
35
+ export { rule };
36
+ //# sourceMappingURL=no-devtools-in-production.rule.js.map
37
+ //# sourceMappingURL=no-devtools-in-production.rule.js.map
@@ -0,0 +1,71 @@
1
+ // builtin-rules/static/spring-boot/no-print-stack-trace.rule.ts
2
+ var JAVA_FILE_RE = /\.java$/i;
3
+ var isTestPath = (p) => /[._-](?:test|tests|spec)\.java$/i.test(p) || /(?:^|[/\\])(?:test|tests|fixtures|mock)[/\\]/i.test(p);
4
+ var PRINT_STACK_TRACE_RE = /\b([A-Za-z0-9_$]+)\s*\.\s*printStackTrace\s*\(\s*\)/g;
5
+ var SYSTEM_PRINT_EXCEPTION_RE = /\bSystem\s*\.\s*(?:err|out)\s*\.\s*print(?:ln)?\s*\(\s*([A-Za-z0-9_$]+(?:\s*\.\s*getMessage\s*\(\s*\)|\s*\.\s*toString\s*\(\s*\))?)\s*\)/g;
6
+ var rule = {
7
+ id: "spring-boot/no-print-stack-trace",
8
+ version: 1,
9
+ kind: "static-ts",
10
+ title: "Kh\xF4ng g\u1ECDi printStackTrace ho\u1EB7c in tr\u1EF1c ti\u1EBFp ngo\u1EA1i l\u1EC7 ra console (CWE-209)",
11
+ description: "Ph\xE1t hi\u1EC7n l\u1EC7nh g\u1ECDi e.printStackTrace() ho\u1EB7c System.err.println(e.getMessage()) trong m\xE3 ngu\u1ED3n Java. C\xE1c l\u1EC7nh n\xE0y l\xE0m l\u1ED9 chi ti\u1EBFt c\u1EA5u tr\xFAc h\u1EC7 th\u1ED1ng, stack trace v\xE0 \u0111\u01B0\u1EDDng d\u1EABn file n\u1ED9i b\u1ED9 (CWE-209).",
12
+ severity: "error",
13
+ category: "security",
14
+ languages: ["java"],
15
+ scope: "spring-boot",
16
+ requires: "text",
17
+ usesParser: false,
18
+ baseConfidence: 85,
19
+ check(ctx) {
20
+ const file = ctx.file;
21
+ if (!JAVA_FILE_RE.test(file.path) || isTestPath(file.path)) return [];
22
+ const content = file.content;
23
+ const findings = [];
24
+ const masked = content.replace(/\/\/[^\n]*/g, (m) => " ".repeat(m.length)).replace(/\/\*[\s\S]*?\*\//g, (m) => " ".repeat(m.length));
25
+ PRINT_STACK_TRACE_RE.lastIndex = 0;
26
+ let match = PRINT_STACK_TRACE_RE.exec(masked);
27
+ while (match !== null) {
28
+ const varName = match[1] ?? "e";
29
+ const before = content.slice(0, match.index);
30
+ const lines = before.split("\n");
31
+ const line = lines.length;
32
+ const column = (lines.at(-1)?.length ?? 0) + 1;
33
+ findings.push({
34
+ message: `G\u1ECDi tr\u1EF1c ti\u1EBFp '${varName}.printStackTrace()' l\xE0m l\u1ED9 c\u1EA5u tr\xFAc m\xE3 ngu\u1ED3n v\xE0 stack trace h\u1EC7 th\u1ED1ng (CWE-209).`,
35
+ file: file.path,
36
+ range: { line, column },
37
+ severity: "error",
38
+ confidence: 85,
39
+ suggestion: `Thay th\u1EBF b\u1EB1ng logger chu\u1EA9n c\u1EE7a framework (v\xED d\u1EE5: log.error("L\u1ED7i x\u1EA3y ra: {}", ${varName}.getMessage(), ${varName})).`
40
+ });
41
+ match = PRINT_STACK_TRACE_RE.exec(masked);
42
+ }
43
+ SYSTEM_PRINT_EXCEPTION_RE.lastIndex = 0;
44
+ match = SYSTEM_PRINT_EXCEPTION_RE.exec(masked);
45
+ while (match !== null) {
46
+ const arg = match[1] ?? "";
47
+ const isExceptionArg = /\b(?:e|ex|err|error|exception|cause|throwable)\b/i.test(arg) || /\bgetMessage\s*\(\s*\)/i.test(arg);
48
+ if (isExceptionArg) {
49
+ const before = content.slice(0, match.index);
50
+ const lines = before.split("\n");
51
+ const line = lines.length;
52
+ const column = (lines.at(-1)?.length ?? 0) + 1;
53
+ const snippet = match[0];
54
+ findings.push({
55
+ message: `In tr\u1EF1c ti\u1EBFp th\xF4ng b\xE1o ngo\u1EA1i l\u1EC7 qua '${snippet}' l\xE0m l\u1ED9 th\xF4ng tin h\u1EC7 th\u1ED1ng ra console stream (CWE-209).`,
56
+ file: file.path,
57
+ range: { line, column },
58
+ severity: "error",
59
+ confidence: 80,
60
+ suggestion: "S\u1EED d\u1EE5ng logging framework c\xF3 c\u1EA5u h\xECnh ph\xE2n c\u1EA5p log level an to\xE0n."
61
+ });
62
+ }
63
+ match = SYSTEM_PRINT_EXCEPTION_RE.exec(masked);
64
+ }
65
+ return findings;
66
+ }
67
+ };
68
+
69
+ export { rule };
70
+ //# sourceMappingURL=no-print-stack-trace.rule.js.map
71
+ //# sourceMappingURL=no-print-stack-trace.rule.js.map
@@ -0,0 +1,53 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/no-sensitive-config-response.rule.ts
4
+ var CONTROLLER_SURFACE_RE = /@(?:RestController|Controller|(?:Get|Post|Put|Patch|Delete)Mapping)\b|\bResponseEntity\b/;
5
+ var SENSITIVE_FIELD_RE = /(?:password|passwd|pwd|secret|api[-_]?key|token|credential)/i;
6
+ var MAP_OF_RE = /\bMap\s*\.\s*of\s*\(\s*(['"])([^'"\r\n]+)\1\s*,\s*([^,\n)]{1,240})/g;
7
+ var PUT_RE = /\b[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*\.\s*put\s*\(\s*(['"])([^'"\r\n]+)\1\s*,\s*([^;\n)]{1,240})\)/g;
8
+ var MASKED_VALUE_RE = /^\s*(?:null|["']\*{3,}["']|[A-Za-z_$][\w$]*(?:\s*\.\s*)?(?:mask|masked|redact)[\w$]*\s*\()/i;
9
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
10
+ var rule = {
11
+ id: "spring-boot/no-sensitive-config-response",
12
+ version: 1,
13
+ kind: "static-ts",
14
+ title: "Kh\xF4ng tr\u1EA3 password/secret trong response c\u1EA5u h\xECnh",
15
+ description: "Ph\xE1t hi\u1EC7n RestController tr\u1EF1c ti\u1EBFp \u0111\u1EB7t password/secret/token/credential v\xE0o Map/JSON response. D\xF9ng cho endpoint c\u1EA5u h\xECnh nh\u01B0 pass-config/SMS config; DTO v\xE0 lu\u1ED3ng gi\xE1n ti\u1EBFp ti\u1EBFp t\u1EE5c \u0111\u01B0\u1EE3c AI rule security-sensitive-data-risk review.",
16
+ severity: "error",
17
+ category: "security",
18
+ languages: ["java"],
19
+ scope: "spring-boot",
20
+ requires: "syntactic",
21
+ usesParser: false,
22
+ baseConfidence: 85,
23
+ check(ctx) {
24
+ const source = maskJavaFiles([ctx.file])[0] ?? ctx.file;
25
+ const content = source.content;
26
+ if (!CONTROLLER_SURFACE_RE.test(content)) return [];
27
+ const findings = [];
28
+ const seen = /* @__PURE__ */ new Set();
29
+ for (const pattern of [MAP_OF_RE, PUT_RE]) {
30
+ pattern.lastIndex = 0;
31
+ for (const match of content.matchAll(pattern)) {
32
+ const field = match[2] ?? "";
33
+ const value = match[3] ?? "";
34
+ const index = match.index ?? 0;
35
+ if (!SENSITIVE_FIELD_RE.test(field) || MASKED_VALUE_RE.test(value) || seen.has(index))
36
+ continue;
37
+ seen.add(index);
38
+ findings.push({
39
+ file: source.path,
40
+ range: { line: lineOf(content, index), column: 1 },
41
+ confidence: 85,
42
+ message: `Response c\u1EA5u h\xECnh tr\u1EA3 field nh\u1EA1y c\u1EA3m \`${field}\` \u1EDF d\u1EA1ng tr\u1EF1c ti\u1EBFp (Information Disclosure).`,
43
+ suggestion: "Kh\xF4ng serialize password/secret/token/credential v\xE0o response. B\u1ECF field kh\u1ECFi response DTO/map; n\u1EBFu UI ch\u1EC9 c\u1EA7n tr\u1EA1ng th\xE1i c\u1EA5u h\xECnh, tr\u1EA3 boolean/metadata ho\u1EB7c gi\xE1 tr\u1ECB mask c\u1ED1 \u0111\u1ECBnh v\xE0 gi\u1EEF secret ch\u1EC9 \u1EDF server."
44
+ });
45
+ }
46
+ }
47
+ return findings.sort((a, b) => a.range.line - b.range.line);
48
+ }
49
+ };
50
+
51
+ export { rule };
52
+ //# sourceMappingURL=no-sensitive-config-response.rule.js.map
53
+ //# sourceMappingURL=no-sensitive-config-response.rule.js.map
@@ -0,0 +1,57 @@
1
+ // builtin-rules/static/spring-boot/no-weak-tls-protocol.rule.ts
2
+ var WEAK_TLS_PATTERNS = [
3
+ {
4
+ regex: /\bSSLContext\.getInstance\s*\(\s*["'](?:SSL|SSLv2|SSLv3|TLSv1|TLSv1\.0|TLSv1\.1)["']/g,
5
+ message: "Kh\u1EDFi t\u1EA1o SSLContext v\u1EDBi giao th\u1EE9c SSL/TLS l\u1ED7i th\u1EDDi/kh\xF4ng an to\xE0n (SSLv3/TLSv1/TLSv1.1) \u2014 CWE-326/CWE-327."
6
+ },
7
+ {
8
+ regex: /\b(?:setEnabledProtocols|protocols)\s*\([^)]*["'](?:SSL|SSLv2|SSLv3|TLSv1|TLSv1\.0|TLSv1\.1)["']/g,
9
+ message: "K\xEDch ho\u1EA1t giao th\u1EE9c SSL/TLS l\u1ED7i th\u1EDDi (SSLv3/TLSv1/TLSv1.1) tr\xEAn socket/client \u2014 CWE-326/CWE-327."
10
+ }
11
+ ];
12
+ var lineColumnAt = (content, index) => {
13
+ const safeIndex = Math.max(0, Math.min(index, content.length));
14
+ const before = content.slice(0, safeIndex);
15
+ const lines = before.split(/\r?\n/);
16
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
17
+ };
18
+ var rule = {
19
+ id: "spring-boot/no-weak-tls-protocol",
20
+ version: 1,
21
+ kind: "static-ts",
22
+ title: "Kh\xF4ng s\u1EED d\u1EE5ng giao th\u1EE9c SSL/TLS l\u1ED7i th\u1EDDi (SSLv3, TLSv1, TLSv1.1)",
23
+ description: "Ph\xE1t hi\u1EC7n vi\u1EC7c s\u1EED d\u1EE5ng ho\u1EB7c c\u1EA5u h\xECnh c\xE1c phi\xEAn b\u1EA3n giao th\u1EE9c SSL/TLS c\u0169 (SSLv3, TLSv1, TLSv1.1) d\u1EC5 b\u1ECB t\u1EA5n c\xF4ng man-in-the-middle ho\u1EB7c downgrade attack (POODLE, BEAST) \u2014 CWE-326/CWE-327.",
24
+ severity: "error",
25
+ category: "security",
26
+ languages: ["java"],
27
+ scope: "spring-boot",
28
+ requires: "text",
29
+ usesParser: false,
30
+ baseConfidence: 90,
31
+ check(ctx) {
32
+ const content = ctx.file.content;
33
+ const findings = [];
34
+ const masked = content.replace(/\/\/[^\n]*/g, (m) => " ".repeat(m.length)).replace(/\/\*[\s\S]*?\*\//g, (m) => " ".repeat(m.length));
35
+ for (const { regex, message } of WEAK_TLS_PATTERNS) {
36
+ regex.lastIndex = 0;
37
+ let match = regex.exec(masked);
38
+ while (match !== null) {
39
+ const { line, column } = lineColumnAt(content, match.index);
40
+ findings.push({
41
+ message,
42
+ file: ctx.file.path,
43
+ range: { line, column },
44
+ severity: "error",
45
+ confidence: 90,
46
+ suggestion: 'N\xE2ng c\u1EA5p l\xEAn giao th\u1EE9c b\u1EA3o m\u1EADt hi\u1EC7n \u0111\u1EA1i TLSv1.2 ho\u1EB7c TLSv1.3 (v\xED d\u1EE5: SSLContext.getInstance("TLSv1.3") ho\u1EB7c ch\u1EC9 \u0111\u1ECBnh setEnabledProtocols v\u1EDBi TLSv1.2, TLSv1.3).'
47
+ });
48
+ match = regex.exec(masked);
49
+ }
50
+ }
51
+ return findings;
52
+ }
53
+ };
54
+
55
+ export { rule };
56
+ //# sourceMappingURL=no-weak-tls-protocol.rule.js.map
57
+ //# sourceMappingURL=no-weak-tls-protocol.rule.js.map
@@ -0,0 +1,104 @@
1
+ // builtin-rules/static/spring-boot/password-expiration-policy.rule.ts
2
+ var JAVA_FILE_RE = /\.java$/i;
3
+ var CONFIG_FILE_RE = /\.(?:ya?ml|properties)$/i;
4
+ var USER_DETAILS_RE = /\bimplements\s+[^;{]*\bUserDetails\b/i;
5
+ var HARDCODED_CREDENTIALS_NON_EXPIRED_RE = /public\s+boolean\s+isCredentialsNonExpired\s*\(\s*\)\s*\{\s*return\s+true\s*;\s*\}/;
6
+ var rule = {
7
+ id: "spring-boot/password-expiration-policy",
8
+ version: 1,
9
+ kind: "static-ts",
10
+ title: "Thi\u1EBFt l\u1EADp ch\xEDnh s\xE1ch h\u1EBFt h\u1EA1n m\u1EADt kh\u1EA9u \u0111\u1ECBnh k\u1EF3 \u2264 90 ng\xE0y (CWE-262)",
11
+ description: "Ph\xE1t hi\u1EC7n thi\u1EBFu ch\xEDnh s\xE1ch h\u1EBFt h\u1EA1n m\u1EADt kh\u1EA9u \u0111\u1ECBnh k\u1EF3 ho\u1EB7c c\u1EA5u h\xECnh th\u1EDDi h\u1EA1n hi\u1EC7u l\u1EF1c c\u1EE7a m\u1EADt kh\u1EA9u v\u01B0\u1EE3t qu\xE1 90 ng\xE0y. Chu\u1EA9n ATTT (TC.CNVTQ\u0110.CNTT.16 #29) quy \u0111\u1ECBnh m\u1EADt kh\u1EA9u ph\u1EA3i h\u1EBFt hi\u1EC7u l\u1EF1c \u0111\u1ECBnh k\u1EF3 \u2264 90 ng\xE0y nh\u1EB1m gi\u1EA3m thi\u1EC3u r\u1EE7i ro khi m\u1EADt kh\u1EA9u b\u1ECB l\u1ED9 l\u1ECDt (CWE-262).",
12
+ severity: "warning",
13
+ category: "security",
14
+ languages: ["java", "yaml", "text"],
15
+ scope: "spring-boot",
16
+ requires: "text",
17
+ usesParser: false,
18
+ baseConfidence: 85,
19
+ check(ctx) {
20
+ const file = ctx.file;
21
+ const isJava = JAVA_FILE_RE.test(file.path);
22
+ const isConfig = CONFIG_FILE_RE.test(file.path);
23
+ if (!isJava && !isConfig) return [];
24
+ const findings = [];
25
+ const lines = file.content.split("\n");
26
+ if (isConfig) {
27
+ const stack = [];
28
+ for (let i = 0; i < lines.length; i++) {
29
+ const line = lines[i] ?? "";
30
+ const trimmed = line.trim();
31
+ if (!trimmed || trimmed.startsWith("#")) continue;
32
+ const indent = (line.match(/^(\s*)/)?.[1] ?? "").length;
33
+ while (stack.length > 0 && (stack[stack.length - 1]?.indent ?? 0) >= indent) {
34
+ stack.pop();
35
+ }
36
+ const colonIdx = trimmed.indexOf(":");
37
+ const eqIdx = trimmed.indexOf("=");
38
+ let sepIdx = -1;
39
+ if (colonIdx !== -1 && eqIdx !== -1) sepIdx = Math.min(colonIdx, eqIdx);
40
+ else if (colonIdx !== -1) sepIdx = colonIdx;
41
+ else if (eqIdx !== -1) sepIdx = eqIdx;
42
+ if (sepIdx !== -1) {
43
+ const keyPart = trimmed.slice(0, sepIdx).trim();
44
+ const valPart = trimmed.slice(sepIdx + 1).trim();
45
+ const fullKey = [...stack.map((s) => s.key), keyPart].join(".");
46
+ if (!valPart) {
47
+ stack.push({ indent, key: keyPart });
48
+ } else {
49
+ const isPasswordExpiryKey = /(?:password[._-]expiration[._-]days|password[._-]max[._-]age(?:[._-]days)?|password[._-]validity[._-]days|auth[._-]password[._-]expiry(?:[._-]days)?|expiration[._-]days)$/i.test(
50
+ fullKey
51
+ );
52
+ if (isPasswordExpiryKey) {
53
+ const numVal = Number.parseInt(valPart, 10);
54
+ if (valPart.startsWith("false") || numVal <= 0) {
55
+ findings.push({
56
+ message: `Ch\xEDnh s\xE1ch h\u1EBFt h\u1EA1n m\u1EADt kh\u1EA9u b\u1ECB v\xF4 hi\u1EC7u ho\xE1: \`${fullKey} = ${valPart}\` \u2014 vi ph\u1EA1m y\xEAu c\u1EA7u h\u1EBFt hi\u1EC7u l\u1EF1c m\u1EADt kh\u1EA9u \u0111\u1ECBnh k\u1EF3 (CWE-262).`,
57
+ file: file.path,
58
+ range: { line: i + 1, column: 1 },
59
+ severity: "warning",
60
+ confidence: 85,
61
+ suggestion: "C\u1EA5u h\xECnh th\u1EDDi h\u1EA1n m\u1EADt kh\u1EA9u hi\u1EC7u l\u1EF1c \u0111\u1ECBnh k\u1EF3 \u2264 90 ng\xE0y."
62
+ });
63
+ } else if (!Number.isNaN(numVal) && numVal > 90) {
64
+ findings.push({
65
+ message: `Th\u1EDDi h\u1EA1n h\u1EBFt hi\u1EC7u l\u1EF1c m\u1EADt kh\u1EA9u \`${fullKey} = ${numVal}\` ng\xE0y v\u01B0\u1EE3t qu\xE1 ng\u01B0\u1EE1ng quy \u0111\u1ECBnh (\u2264 90 ng\xE0y) theo TC.CNVTQ\u0110.CNTT.16 #29.`,
66
+ file: file.path,
67
+ range: { line: i + 1, column: 1 },
68
+ severity: "warning",
69
+ confidence: 90,
70
+ suggestion: "Gi\u1EA3m th\u1EDDi h\u1EA1n hi\u1EC7u l\u1EF1c m\u1EADt kh\u1EA9u xu\u1ED1ng \u2264 90 ng\xE0y (v\xED d\u1EE5: 90 ng\xE0y)."
71
+ });
72
+ }
73
+ }
74
+ }
75
+ }
76
+ }
77
+ return findings;
78
+ }
79
+ if (isJava && USER_DETAILS_RE.test(file.content)) {
80
+ if (HARDCODED_CREDENTIALS_NON_EXPIRED_RE.test(file.content)) {
81
+ let methodLine = 1;
82
+ for (let i = 0; i < lines.length; i++) {
83
+ if (/boolean\s+isCredentialsNonExpired\s*\(\s*\)/.test(lines[i] ?? "")) {
84
+ methodLine = i + 1;
85
+ break;
86
+ }
87
+ }
88
+ findings.push({
89
+ message: "`UserDetails.isCredentialsNonExpired()` tr\u1EA3 v\u1EC1 c\u1EE9ng `return true;` m\xE0 kh\xF4ng ki\u1EC3m tra th\u1EDDi h\u1EA1n \u0111\u1ED5i m\u1EADt kh\u1EA9u \u0111\u1ECBnh k\u1EF3 (CWE-262).",
90
+ file: file.path,
91
+ range: { line: methodLine, column: 1 },
92
+ severity: "warning",
93
+ confidence: 80,
94
+ suggestion: "So s\xE1nh ng\xE0y c\u1EADp nh\u1EADt m\u1EADt kh\u1EA9u g\u1EA7n nh\u1EA5t (`passwordChangedAt`) v\u1EDBi ng\u01B0\u1EE1ng 90 ng\xE0y \u0111\u1EC3 bu\u1ED9c ng\u01B0\u1EDDi d\xF9ng \u0111\u1ED5i m\u1EADt kh\u1EA9u \u0111\u1ECBnh k\u1EF3."
95
+ });
96
+ }
97
+ }
98
+ return findings;
99
+ }
100
+ };
101
+
102
+ export { rule };
103
+ //# sourceMappingURL=password-expiration-policy.rule.js.map
104
+ //# sourceMappingURL=password-expiration-policy.rule.js.map