@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.
Files changed (50) hide show
  1. package/dist/bin.js +41568 -30374
  2. package/dist/builtin-rules/{ai → fortify/ai}/angular/cross-feature-route-permission-drift.rule.yaml +4 -0
  3. package/dist/builtin-rules/{ai → fortify/ai}/angular/route-permission-flow.rule.yaml +4 -0
  4. package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/io-boundary-risk.rule.yaml +4 -0
  5. package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-redirect-risk.rule.yaml +4 -0
  6. package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-sensitive-data-risk.rule.yaml +4 -0
  7. package/dist/builtin-rules/{static → fortify/static}/angular/sensitive-input-masking.rule.js +5 -1
  8. package/dist/builtin-rules/fortify/static/general/java-weak-randomness.rule.js +45 -0
  9. package/dist/builtin-rules/{static → fortify/static}/general/no-client-identity-header.rule.js +5 -1
  10. package/dist/builtin-rules/{static → fortify/static}/general/no-guessable-websql-database-name.rule.js +5 -1
  11. package/dist/builtin-rules/fortify/static/general/no-reflective-access-override.rule.js +37 -0
  12. package/dist/builtin-rules/{static → fortify/static}/general/no-sensitive-string-materialization.rule.js +5 -1
  13. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-command-injection.rule.js +12 -2
  14. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-path-traversal.rule.js +12 -2
  15. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-servlet-xss.rule.js +12 -2
  16. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-spel-injection.rule.js +12 -2
  17. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-sql-string-concat.rule.js +12 -2
  18. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-ssrf.rule.js +28 -4
  19. package/dist/builtin-rules/{static → fortify/static}/spring-boot/no-weak-tls-protocol.rule.js +5 -1
  20. package/dist/builtin-rules/performance/static/spring-boot/http-client-without-timeout.rule.js +83 -0
  21. package/dist/builtin-rules/performance/static/spring-boot/open-in-view-enabled.rule.js +89 -0
  22. package/dist/builtin-rules/performance/static/spring-boot/transaction-holds-remote-call.rule.js +323 -0
  23. package/dist/builtin-rules/performance/static/spring-boot/unbounded-repository-fetch.rule.js +125 -0
  24. package/dist/builtin-rules/performance/static/spring-boot/xssf-workbook-for-export.rule.js +81 -0
  25. package/dist/builtin-rules/static/general/dockerfile-dependency-confusion.rule.js +27 -2
  26. package/dist/builtin-rules/static/general/kubernetes-pod-security.rule.js +90 -0
  27. package/dist/builtin-rules/static/general/no-circular-import.rule.js +12 -2
  28. package/dist/builtin-rules/static/general/no-dynamic-code-eval.rule.js +84 -0
  29. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +179 -13
  30. package/dist/builtin-rules/static/general/no-open-redirect.rule.js +7 -3
  31. package/dist/builtin-rules/static/general/no-unsafe-html-sink.rule.js +50 -7
  32. package/dist/builtin-rules/static/general/openapi-https-credentials.rule.js +90 -0
  33. package/dist/builtin-rules/static/general/sensitive-exception-response.rule.js +44 -0
  34. package/dist/builtin-rules/static/general/sensitive-output-exposure.rule.js +1 -1
  35. package/dist/builtin-rules/static/spring-boot/explicit-csp-required.rule.js +37 -0
  36. package/dist/builtin-rules/static/spring-boot/no-devtools-in-production.rule.js +13 -16
  37. package/dist/builtin-rules/static/spring-boot/no-global-permit-all.rule.js +50 -0
  38. package/dist/builtin-rules/static/spring-boot/no-negative-sensitive-input.rule.js +91 -0
  39. package/dist/builtin-rules/static/spring-boot/password-reset-without-proof.rule.js +84 -0
  40. package/dist/builtin-rules/static/spring-boot/stored-content-without-sanitization.rule.js +93 -0
  41. package/dist/index.d.ts +384 -76
  42. package/dist/index.js +41570 -30376
  43. package/node_modules/@code-sentinel/parsers/index.js +330 -198
  44. package/package.json +1 -1
  45. package/dist/builtin-rules/static/general/no-reflective-access-override.rule.js +0 -50
  46. /package/dist/builtin-rules/{ai → fortify/ai}/angular/cross-feature-route-permission-drift.prompt.md +0 -0
  47. /package/dist/builtin-rules/{ai → fortify/ai}/angular/route-permission-flow.prompt.md +0 -0
  48. /package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/io-boundary-risk.prompt.md +0 -0
  49. /package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-redirect-risk.prompt.md +0 -0
  50. /package/dist/builtin-rules/{ai → fortify/ai}/spring-boot/security-sensitive-data-risk.prompt.md +0 -0
@@ -0,0 +1,44 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/sensitive-exception-response.rule.ts
4
+ var SENSITIVE = /password|passwd|secret|token|credential|\bpin\b|\botp\b|get(?:Localized)?Message\s*\(|getStackTrace\s*\(/i;
5
+ var rule = {
6
+ id: "general/sensitive-exception-response",
7
+ version: 1,
8
+ kind: "static-ts",
9
+ title: "Ki\u1EC3m tra th\xF4ng tin nh\u1EA1y c\u1EA3m qua exception/response",
10
+ severity: "warning",
11
+ category: "security",
12
+ languages: ["java"],
13
+ scope: "general",
14
+ usesParser: false,
15
+ baseConfidence: 65,
16
+ check: (ctx) => {
17
+ const masked = maskJavaFiles([ctx.file])[0]?.content ?? ctx.file.content;
18
+ const source = masked.replace(
19
+ /"(?:[^"\\]|\\.)*"/g,
20
+ (literal) => literal.replace(/[^\r\n]/g, " ")
21
+ );
22
+ const sinks = /\bthrow\s+new\s+[\w$.]*Exception\s*\((\s*)([^;]*?)\)\s*;|\bResponseEntity\s*\.\s*[^;\n]*?\bbody\s*\((\s*)([^;]*?)\)\s*;/g;
23
+ return [...source.matchAll(sinks)].flatMap((match) => {
24
+ const argument = match[2] ?? match[4] ?? "";
25
+ if (!SENSITIVE.test(argument)) return [];
26
+ const metadataOnly = /^\s*(?:[\w$.]+\.)?[A-Z][A-Z_0-9]+(?:\s*,\s*\w+)*\s*$/.test(argument);
27
+ const argumentStart = (match.index ?? 0) + match[0].indexOf(argument);
28
+ return [
29
+ {
30
+ file: ctx.file.path,
31
+ range: { line: source.slice(0, argumentStart).split("\n").length, column: 1 },
32
+ confidence: metadataOnly ? 40 : 65,
33
+ severity: metadataOnly ? "info" : "warning",
34
+ message: metadataOnly ? "Sensitive validation/error metadata reaches an exception sink; review HTTP mapping and enumeration risk. No raw credential disclosure is proven. [control=sensitive-error-metadata]" : "Sensitive value or exception detail reaches an exception/response sink; inspect serialization and HTTP exposure. [control=sensitive-exception-value]",
35
+ suggestion: "Verify the global exception handler and response body; redact sensitive values and assess whether error distinctions reveal protected information."
36
+ }
37
+ ];
38
+ });
39
+ }
40
+ };
41
+
42
+ export { rule };
43
+ //# sourceMappingURL=sensitive-exception-response.rule.js.map
44
+ //# sourceMappingURL=sensitive-exception-response.rule.js.map
@@ -3,7 +3,7 @@ import { findSensitiveOutput } from '@code-sentinel/parsers';
3
3
  // builtin-rules/static/general/sensitive-output-exposure.rule.ts
4
4
  var rule = {
5
5
  id: "general/sensitive-output-exposure",
6
- version: 1,
6
+ version: 2,
7
7
  kind: "static-ts",
8
8
  title: "Kh\xF4ng ghi d\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m ra log ho\u1EB7c console",
9
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).",
@@ -0,0 +1,37 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/explicit-csp-required.rule.ts
4
+ var SECURITY_CONFIG = /@EnableWebSecurity\b|\bSecurityFilterChain\b|extends\s+WebSecurityConfigurerAdapter\b/;
5
+ var CSP = /\bcontentSecurityPolicy\s*\(|["']Content-Security-Policy["']/i;
6
+ var rule = {
7
+ id: "spring-boot/explicit-csp-required",
8
+ version: 1,
9
+ kind: "static-ts",
10
+ title: "Spring Security c\u1EA7n CSP t\u01B0\u1EDDng minh",
11
+ description: "Spring Security kh\xF4ng th\xEAm Content-Security-Policy m\u1EB7c \u0111\u1ECBnh. C\u1EA3nh b\xE1o khi source c\xF3 SecurityFilterChain nh\u01B0ng kh\xF4ng khai b\xE1o CSP.",
12
+ severity: "warning",
13
+ category: "security",
14
+ languages: ["java"],
15
+ scope: "spring-boot",
16
+ requires: "text",
17
+ usesParser: false,
18
+ baseConfidence: 80,
19
+ check(ctx) {
20
+ const source = maskJavaFiles([ctx.file])[0]?.content ?? ctx.file.content;
21
+ if (!SECURITY_CONFIG.test(source) || CSP.test(source)) return [];
22
+ const index = source.search(SECURITY_CONFIG);
23
+ return [
24
+ {
25
+ file: ctx.file.path,
26
+ range: { line: source.slice(0, index).split("\n").length, column: 1 },
27
+ confidence: 80,
28
+ message: "Spring Security config kh\xF4ng khai b\xE1o Content-Security-Policy; CSP kh\xF4ng n\u1EB1m trong default header c\u1EE7a Spring. [control=missing-explicit-csp]",
29
+ suggestion: "Khai b\xE1o contentSecurityPolicy(...) v\u1EDBi policy ph\xF9 h\u1EE3p. N\u1EBFu CSP do gateway/reverse-proxy \u0111\u1EB7t, suppress finding v\xE0 d\u1EABn chi\u1EBFu c\u1EA5u h\xECnh/runtime probe."
30
+ }
31
+ ];
32
+ }
33
+ };
34
+
35
+ export { rule };
36
+ //# sourceMappingURL=explicit-csp-required.rule.js.map
37
+ //# sourceMappingURL=explicit-csp-required.rule.js.map
@@ -1,12 +1,12 @@
1
- import { DEVTOOLS_BUILD_FILE_RE, auditBuildFile } from '@code-sentinel/parsers';
1
+ import { DEVTOOLS_BUILD_FILE_RE, findDevToolsDeclarations } from '@code-sentinel/parsers';
2
2
 
3
3
  // builtin-rules/static/spring-boot/no-devtools-in-production.rule.ts
4
4
  var rule = {
5
5
  id: "spring-boot/no-devtools-in-production",
6
- version: 2,
6
+ version: 4,
7
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.",
8
+ title: "Ki\u1EC3m tra DevTools trong c\u1EA5u h\xECnh build v\xE0 s\u1EA3n ph\u1EA9m production (CWE-489)",
9
+ description: "Ki\u1EC3m tra dependency spring-boot-devtools. Profile pentest ghi nh\u1EADn c\u1EA3 optional/developmentOnly \u0111\u1EC3 review profile build, JAR/WAR v\xE0 runtime; khai b\xE1o dependency ch\u01B0a ch\u1EE9ng minh DevTools \u0111ang b\u1EADt production.",
10
10
  severity: "error",
11
11
  category: "security",
12
12
  languages: ["xml", "text"],
@@ -14,21 +14,18 @@ var rule = {
14
14
  requires: "text",
15
15
  usesParser: false,
16
16
  baseConfidence: 90,
17
+ defaultOptions: { reportDeclaredDependency: true },
17
18
  check(ctx) {
18
19
  const file = ctx.file;
19
20
  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
- ];
21
+ return findDevToolsDeclarations(file.content, file.path).filter((finding) => finding.isVulnerable || ctx.options.reportDeclaredDependency).map((finding) => ({
22
+ file: finding.file,
23
+ range: { line: finding.line, column: 1 },
24
+ severity: finding.isVulnerable ? "error" : "warning",
25
+ confidence: finding.isVulnerable ? 90 : 60,
26
+ message: finding.reason,
27
+ suggestion: "Inspect the production build profile, packaged JAR/WAR and runtime configuration; verify DevTools is excluded/disabled."
28
+ }));
32
29
  }
33
30
  };
34
31
 
@@ -0,0 +1,50 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/no-global-permit-all.rule.ts
4
+ var GLOBAL_PERMIT_PATTERNS = [
5
+ /\banyRequest\s*\(\s*\)\s*\.\s*permitAll\s*\(\s*\)/g,
6
+ /\brequestMatchers\s*\(\s*(?:[\w$.]+\s*\.\s*pattern\s*\(\s*)?["'](?:\/\*\*|\*\*)["'][^;]{0,160}?\)\s*\)?\s*\.\s*permitAll\s*\(\s*\)/g
7
+ ];
8
+ var isTestPath = (path) => /(?:^|[/\\])(?:test|tests|fixtures|mock)(?:[/\\]|$)/i.test(path) || /[._-](?:test|tests|spec)\.java$/i.test(path);
9
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
10
+ var rule = {
11
+ id: "spring-boot/no-global-permit-all",
12
+ version: 1,
13
+ kind: "static-ts",
14
+ title: "Kh\xF4ng m\u1EDF c\xF4ng khai to\xE0n b\u1ED9 Spring Security filter chain",
15
+ description: 'Ph\xE1t hi\u1EC7n anyRequest().permitAll() ho\u1EB7c requestMatchers("/**").permitAll(). \u0110\xE2y l\xE0 grant c\xF4ng khai to\xE0n c\u1EE5c \u1EDF t\u1EA7ng Spring Security; gateway ho\u1EB7c method security c\xF3 th\u1EC3 v\u1EABn b\u1EA3o v\u1EC7 n\xEAn finding y\xEAu c\u1EA7u review thay v\xEC t\u1EF1 kh\u1EB3ng \u0111\u1ECBnh khai th\xE1c.',
16
+ severity: "warning",
17
+ category: "security",
18
+ languages: ["java"],
19
+ scope: "spring-boot",
20
+ requires: "text",
21
+ usesParser: false,
22
+ baseConfidence: 90,
23
+ check(ctx) {
24
+ if (isTestPath(ctx.file.path)) return [];
25
+ const source = maskJavaFiles([ctx.file])[0]?.content ?? ctx.file.content;
26
+ if (!/\b(?:SecurityFilterChain|HttpSecurity)\b/.test(source)) return [];
27
+ const findings = [];
28
+ const seen = /* @__PURE__ */ new Set();
29
+ for (const pattern of GLOBAL_PERMIT_PATTERNS) {
30
+ pattern.lastIndex = 0;
31
+ for (const match of source.matchAll(pattern)) {
32
+ const index = match.index ?? 0;
33
+ if (seen.has(index)) continue;
34
+ seen.add(index);
35
+ findings.push({
36
+ file: ctx.file.path,
37
+ range: { line: lineOf(source, index), column: 1 },
38
+ confidence: 90,
39
+ message: "Spring Security c\u1EA5p permitAll cho to\xE0n b\u1ED9 request; m\u1ECDi endpoint ph\u1EE5 thu\u1ED9c ho\xE0n to\xE0n v\xE0o gateway ho\u1EB7c method-level security. [control=global-permit-all]",
40
+ suggestion: "\u0110\u1ED5i catch-all th\xE0nh authenticated()/denyAll() v\xE0 allowlist ri\xEAng endpoint public. N\u1EBFu ch\u1EE7 \xFD \u1EE7y quy\u1EC1n cho gateway/method interceptor, b\u1ED5 sung test b\u1EAFt bu\u1ED9c ch\u1EE9ng minh m\u1ECDi endpoint nh\u1EA1y c\u1EA3m \u0111\u1EC1u \u0111\u01B0\u1EE3c l\u1EDBp \u0111\xF3 b\u1EA3o v\u1EC7."
41
+ });
42
+ }
43
+ }
44
+ return findings.sort((a, b) => a.range.line - b.range.line);
45
+ }
46
+ };
47
+
48
+ export { rule };
49
+ //# sourceMappingURL=no-global-permit-all.rule.js.map
50
+ //# sourceMappingURL=no-global-permit-all.rule.js.map
@@ -0,0 +1,91 @@
1
+ import { asTreeSitterTree } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/no-negative-sensitive-input.rule.ts
4
+ var REQUEST_TYPE_SUFFIX = /(?:DTO|Dto|VM|Request|Command|Payload|Form)$/;
5
+ var SENSITIVE_NUMBER_PREFIX = /^(?:amount|price|cost|fee|dues|payment|money|balance|quantity|total|count|number|value)(?:[A-Z_]|$)/i;
6
+ var SENSITIVE_NUMBER_SUFFIX = /(?:amount|price|cost|fee|dues|payment|money|balance|quantity|total|count|number|value)$/i;
7
+ var NUMERIC_TYPE = /* @__PURE__ */ new Set([
8
+ "byte",
9
+ "short",
10
+ "int",
11
+ "long",
12
+ "float",
13
+ "double",
14
+ "Byte",
15
+ "Short",
16
+ "Integer",
17
+ "Long",
18
+ "Float",
19
+ "Double",
20
+ "BigDecimal",
21
+ "BigInteger"
22
+ ]);
23
+ var NON_NEGATIVE_ANNOTATION = /@(?:Positive|PositiveOrZero|NonNegative)\b|@Min\s*\(\s*(?:value\s*=\s*)?0\s*\)|@DecimalMin\s*\(\s*(?:value\s*=\s*)?["']?(?:0+(?:\.0+)?)["']?|@Range\s*\([^)]*\bmin\s*=\s*0\b/i;
24
+ function* walk(node, type) {
25
+ const stack = [node];
26
+ while (stack.length > 0) {
27
+ const current = stack.pop();
28
+ if (!current) continue;
29
+ if (current.type === type) yield current;
30
+ for (let i = current.namedChildCount - 1; i >= 0; i--) {
31
+ const child = current.namedChild(i);
32
+ if (child) stack.push(child);
33
+ }
34
+ }
35
+ }
36
+ var isRequestDto = (node) => {
37
+ const name = node.childForFieldName("name")?.text ?? "";
38
+ return REQUEST_TYPE_SUFFIX.test(name);
39
+ };
40
+ var modifiersText = (node) => {
41
+ for (let i = 0; i < node.namedChildCount; i++) {
42
+ const child = node.namedChild(i);
43
+ if (child?.type === "modifiers") return child.text;
44
+ }
45
+ return "";
46
+ };
47
+ var simpleType = (type) => type.replace(/^.*\./, "").trim();
48
+ var rule = {
49
+ id: "spring-boot/no-negative-sensitive-input",
50
+ version: 1,
51
+ kind: "static-ts",
52
+ title: "DTO request c\xF3 s\u1ED1 nh\u1EA1y c\u1EA3m c\u1EA7n ch\u1EB7n gi\xE1 tr\u1ECB \xE2m",
53
+ description: "Ph\xE1t hi\u1EC7n field s\u1ED1 d\u1EA1ng amount/fee/quantity/... trong DTO request kh\xF4ng c\xF3 r\xE0ng bu\u1ED9c kh\xF4ng \xE2m. \u0110\xE2y l\xE0 review nghi\u1EC7p v\u1EE5: m\u1ED9t s\u1ED1 lu\u1ED3ng ho\xE0n ti\u1EC1n/\u0111i\u1EC1u ch\u1EC9nh c\xF3 th\u1EC3 cho ph\xE9p gi\xE1 tr\u1ECB \xE2m.",
54
+ severity: "warning",
55
+ category: "security",
56
+ languages: ["java"],
57
+ scope: "spring-boot",
58
+ requires: "syntactic",
59
+ baseConfidence: 75,
60
+ check(ctx) {
61
+ const tree = asTreeSitterTree(ctx.parsed);
62
+ const findings = [];
63
+ for (const declaration of walk(tree.rootNode, "class_declaration")) {
64
+ if (!isRequestDto(declaration)) continue;
65
+ for (const field of walk(declaration, "field_declaration")) {
66
+ const type = simpleType(field.childForFieldName("type")?.text ?? "");
67
+ if (!NUMERIC_TYPE.has(type)) continue;
68
+ if (NON_NEGATIVE_ANNOTATION.test(modifiersText(field))) continue;
69
+ for (let i = 0; i < field.namedChildCount; i++) {
70
+ const child = field.namedChild(i);
71
+ if (child?.type !== "variable_declarator") continue;
72
+ const name = child.childForFieldName("name");
73
+ if (!name || !SENSITIVE_NUMBER_PREFIX.test(name.text) && !SENSITIVE_NUMBER_SUFFIX.test(name.text))
74
+ continue;
75
+ findings.push({
76
+ file: ctx.file.path,
77
+ range: { line: name.startPosition.row + 1, column: name.startPosition.column + 1 },
78
+ confidence: 75,
79
+ message: "Numeric request field c\xF3 \xFD ngh\u0129a ti\u1EC1n/s\u1ED1 l\u01B0\u1EE3ng kh\xF4ng c\xF3 r\xE0ng bu\u1ED9c ch\u1EB7n gi\xE1 tr\u1ECB \xE2m. [control=numeric-input-lower-bound-review]",
80
+ suggestion: 'N\u1EBFu gi\xE1 tr\u1ECB \xE2m kh\xF4ng h\u1EE3p l\u1EC7, th\xEAm @Positive, @PositiveOrZero, @Min(0), ho\u1EB7c @DecimalMin("0") v\xE0o DTO. N\u1EBFu nghi\u1EC7p v\u1EE5 cho ph\xE9p ho\xE0n ti\u1EC1n/\u0111i\u1EC1u ch\u1EC9nh \xE2m, suppress finding k\xE8m l\xFD do.'
81
+ });
82
+ }
83
+ }
84
+ }
85
+ return findings;
86
+ }
87
+ };
88
+
89
+ export { rule };
90
+ //# sourceMappingURL=no-negative-sensitive-input.rule.js.map
91
+ //# sourceMappingURL=no-negative-sensitive-input.rule.js.map
@@ -0,0 +1,84 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/password-reset-without-proof.rule.ts
4
+ var RESET_MAPPING_RE = /@(?:Post|Put|Patch|Request)Mapping\s*\(\s*(?:value\s*=\s*)?["'][^"']*(?:(?:reset|forgot|recover)[^"']*(?:password|credential)|(?:password|credential)[^"']*(?:reset|forgot|recover))[^"']*["'][^)]*\)/gi;
5
+ var METHOD_HEAD_RE = /(?:public|protected)\s+(?:[\w$.[\]?,<>]+\s+)+([A-Za-z_$][\w$]*)\s*\(([\s\S]{0,1200}?)\)\s*(?:throws\s+[^\{]+)?\{/;
6
+ var AUTHENTICATED_CONTEXT_RE = /@(?:PreAuthorize|PostAuthorize|Secured|RolesAllowed|DenyAll)\b|\b(?:Authentication|Principal)\s+[A-Za-z_$][\w$]*/i;
7
+ var PROOF_INPUT_RE = /\b(?:reset|recovery|verification|oneTime|one_time|otp|nonce|challenge)?(?:Token|Code)\b|\b(?:otp|nonce|challenge)\b/i;
8
+ var PROOF_USE_RE = /\b(?:verify|validate|consume|redeem|decode|authenticate|check)[A-Za-z0-9_$]*(?:Token|Code|Otp|Nonce|Challenge|Reset)[A-Za-z0-9_$]*\s*\(|\b(?:token|code|otp|nonce|challenge)\s*\.\s*(?:verify|validate|consume|redeem)\s*\(/i;
9
+ var isTestPath = (path) => /(?:^|[/\\])(?:test|tests|fixtures|mock)(?:[/\\]|$)/i.test(path) || /[._-](?:test|tests|spec)\.java$/i.test(path);
10
+ var closingBrace = (source, open) => {
11
+ let depth = 0;
12
+ let quote = null;
13
+ let escaped = false;
14
+ for (let i = open; i < source.length; i++) {
15
+ const ch = source[i];
16
+ if (quote) {
17
+ if (escaped) escaped = false;
18
+ else if (ch === "\\") escaped = true;
19
+ else if (ch === quote) quote = null;
20
+ continue;
21
+ }
22
+ if (ch === '"' || ch === "'") {
23
+ quote = ch;
24
+ continue;
25
+ }
26
+ if (ch === "{") depth++;
27
+ else if (ch === "}" && --depth === 0) return i;
28
+ }
29
+ return source.length;
30
+ };
31
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
32
+ var rule = {
33
+ id: "spring-boot/password-reset-without-proof",
34
+ version: 1,
35
+ kind: "static-ts",
36
+ title: "Reset m\u1EADt kh\u1EA9u ph\u1EA3i ti\xEAu th\u1EE5 recovery proof",
37
+ description: "Ph\xE1t hi\u1EC7n endpoint reset/forgot/recover password kh\xF4ng nh\u1EADn ho\u1EB7c kh\xF4ng verify token, OTP, code, nonce hay challenge trong HTTP handler. Finding l\xE0 \u0111i\u1EC3m review li\xEAn file; service \u0111\u01B0\u1EE3c g\u1ECDi c\xF3 th\u1EC3 th\u1EF1c hi\u1EC7n ki\u1EC3m tra m\xE0 file controller kh\xF4ng th\u1EC3 hi\u1EC7n.",
38
+ severity: "warning",
39
+ category: "security",
40
+ languages: ["java"],
41
+ scope: "spring-boot",
42
+ requires: "text",
43
+ usesParser: false,
44
+ baseConfidence: 82,
45
+ check(ctx) {
46
+ if (isTestPath(ctx.file.path)) return [];
47
+ const source = maskJavaFiles([ctx.file])[0]?.content ?? ctx.file.content;
48
+ if (!/@(?:RestController|Controller)\b/.test(source)) return [];
49
+ const findings = [];
50
+ RESET_MAPPING_RE.lastIndex = 0;
51
+ for (const mapping of source.matchAll(RESET_MAPPING_RE)) {
52
+ const mappingIndex = mapping.index ?? 0;
53
+ const tail = source.slice(mappingIndex + mapping[0].length, mappingIndex + 4e3);
54
+ const method = METHOD_HEAD_RE.exec(tail);
55
+ if (!method || method.index > 900) continue;
56
+ const methodName = method[1] ?? "";
57
+ if (/verify|validate|check/i.test(`${mapping[0]} ${methodName}`)) continue;
58
+ const open = mappingIndex + mapping[0].length + method.index + method[0].length - 1;
59
+ const end = closingBrace(source, open);
60
+ const previousClose = source.lastIndexOf("}", mappingIndex);
61
+ const previousOpen = source.lastIndexOf("{", mappingIndex);
62
+ const annotationStart = Math.max(previousClose, previousOpen) + 1;
63
+ const annotationAndHead = source.slice(annotationStart, open);
64
+ const parameters = method[2] ?? "";
65
+ const body = source.slice(open + 1, end);
66
+ const hasAuthenticatedContext = AUTHENTICATED_CONTEXT_RE.test(annotationAndHead);
67
+ const hasProofInput = PROOF_INPUT_RE.test(parameters) || PROOF_INPUT_RE.test(body);
68
+ const verifiesProof = PROOF_USE_RE.test(body);
69
+ if (hasAuthenticatedContext || hasProofInput && verifiesProof) continue;
70
+ findings.push({
71
+ file: ctx.file.path,
72
+ range: { line: lineOf(source, mappingIndex), column: 1 },
73
+ confidence: hasProofInput ? 72 : 82,
74
+ message: "Endpoint kh\xF4i ph\u1EE5c m\u1EADt kh\u1EA9u kh\xF4ng ti\xEAu th\u1EE5 v\xE0 verify recovery proof trong handler; c\u1EA7n l\u1EA7n theo service \u0111\u1EC3 lo\u1EA1i tr\u1EEB reset ch\u1EC9 b\u1EB1ng \u0111\u1ECBnh danh ng\u01B0\u1EDDi d\xF9ng. [control=password-reset-proof-review]",
75
+ suggestion: "Y\xEAu c\u1EA7u token/OTP m\u1ED9t l\u1EA7n, c\xF3 h\u1EA1n d\xF9ng v\xE0 r\xE0ng bu\u1ED9c \u0111\xFAng user; consume token atomically tr\u01B0\u1EDBc khi \u0111\u1ED5i m\u1EADt kh\u1EA9u. Kh\xF4ng t\xE1ch endpoint \u201Cverify token\u201D kh\u1ECFi endpoint reset n\u1EBFu reset kh\xF4ng bu\u1ED9c tr\xECnh l\u1EA1i proof."
76
+ });
77
+ }
78
+ return findings;
79
+ }
80
+ };
81
+
82
+ export { rule };
83
+ //# sourceMappingURL=password-reset-without-proof.rule.js.map
84
+ //# sourceMappingURL=password-reset-without-proof.rule.js.map
@@ -0,0 +1,93 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/spring-boot/stored-content-without-sanitization.rule.ts
4
+ var MUTATING_MAPPING_RE = /@(?:Post|Put|Patch)Mapping\s*\([^)]*\)/g;
5
+ var METHOD_HEAD_RE = /(?:public|protected)\s+(?:[\w$.[\]?,<>]+\s+)+([A-Za-z_$][\w$]*)\s*\(([\s\S]{0,1600}?)\)\s*(?:throws\s+[^\{]+)?\{/;
6
+ var REQUEST_BODY_RE = /@RequestBody(?:\s*\([^)]*\))?\s+(?:final\s+)?([\w$.<>?,]+)\s+([A-Za-z_$][\w$]*)/i;
7
+ var CONTENT_SURFACE_RE = /(?:notification|announcement|message|template|article|content|rich.?text|html|email|mail|page|post|description|reason)/i;
8
+ var SANITIZER_RE = /\b(?:sanitize|sanitise|cleanHtml|stripTags|escapeHtml|htmlEscape|encodeForHTML|encodeForHtml|Jsoup\s*\.\s*clean)\s*\(/i;
9
+ var isTestPath = (path) => /(?:^|[/\\])(?:test|tests|fixtures|mock)(?:[/\\]|$)/i.test(path) || /[._-](?:test|tests|spec)\.java$/i.test(path);
10
+ var closingBrace = (source, open) => {
11
+ let depth = 0;
12
+ let quote = null;
13
+ let escaped = false;
14
+ for (let i = open; i < source.length; i++) {
15
+ const ch = source[i];
16
+ if (quote) {
17
+ if (escaped) escaped = false;
18
+ else if (ch === "\\") escaped = true;
19
+ else if (ch === quote) quote = null;
20
+ continue;
21
+ }
22
+ if (ch === '"' || ch === "'") {
23
+ quote = ch;
24
+ continue;
25
+ }
26
+ if (ch === "{") depth++;
27
+ else if (ch === "}" && --depth === 0) return i;
28
+ }
29
+ return source.length;
30
+ };
31
+ var escapeRegex = (value) => value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
32
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
33
+ var hasSanitizedRequestBody = (body, variable) => new RegExp(
34
+ `${SANITIZER_RE.source.slice(0, -2)}\\s*\\([^;)]{0,300}\\b${escapeRegex(variable)}\\b`,
35
+ "i"
36
+ ).test(body);
37
+ var rule = {
38
+ id: "spring-boot/stored-content-without-sanitization",
39
+ version: 1,
40
+ kind: "static-ts",
41
+ title: "Review n\u1ED9i dung c\xF3 th\u1EC3 ch\u1EE9a HTML tr\u01B0\u1EDBc khi l\u01B0u",
42
+ description: "Ph\xE1t hi\u1EC7n endpoint qu\u1EA3n l\xFD notification/message/template/article/content nh\u1EADn @RequestBody r\u1ED3i save/update/persist m\xE0 kh\xF4ng c\xF3 sanitizer/encoder r\xF5 r\xE0ng. \u0110\xE2y l\xE0 candidate Stored XSS/HTML Injection; c\u1EA7n n\u1ED1i ti\u1EBFp t\u1EDBi sink render \u0111\u1EC3 x\xE1c nh\u1EADn.",
43
+ severity: "warning",
44
+ category: "security",
45
+ languages: ["java"],
46
+ scope: "spring-boot",
47
+ requires: "text",
48
+ usesParser: false,
49
+ baseConfidence: 72,
50
+ check(ctx) {
51
+ if (isTestPath(ctx.file.path)) return [];
52
+ const source = maskJavaFiles([ctx.file])[0]?.content ?? ctx.file.content;
53
+ if (!/@RestController\b/.test(source)) return [];
54
+ const className = /\bclass\s+([A-Za-z_$][\w$]*)/.exec(source)?.[1] ?? "";
55
+ const findings = [];
56
+ MUTATING_MAPPING_RE.lastIndex = 0;
57
+ for (const mapping of source.matchAll(MUTATING_MAPPING_RE)) {
58
+ const mappingIndex = mapping.index ?? 0;
59
+ const tail = source.slice(mappingIndex + mapping[0].length, mappingIndex + 5e3);
60
+ const method = METHOD_HEAD_RE.exec(tail);
61
+ if (!method || method.index > 1200) continue;
62
+ const parameters = method[2] ?? "";
63
+ const requestBody = REQUEST_BODY_RE.exec(parameters);
64
+ if (!requestBody) continue;
65
+ const dtoType = requestBody[1] ?? "";
66
+ const variable = requestBody[2] ?? "";
67
+ const methodName = method[1] ?? "";
68
+ const mappingPath = mapping[0].replace(/^@(?:Post|Put|Patch)Mapping/i, "");
69
+ const surface = `${className} ${methodName} ${dtoType} ${mappingPath}`;
70
+ if (!CONTENT_SURFACE_RE.test(surface)) continue;
71
+ const open = mappingIndex + mapping[0].length + method.index + method[0].length - 1;
72
+ const end = closingBrace(source, open);
73
+ const body = source.slice(open + 1, end);
74
+ const persisted = new RegExp(
75
+ `\\.\\s*(?:save|update|persist|upsert|store|create)\\s*\\([^;)]{0,300}\\b${escapeRegex(variable)}\\b[^;)]*\\)`,
76
+ "i"
77
+ ).test(body);
78
+ if (!persisted || hasSanitizedRequestBody(body, variable)) continue;
79
+ findings.push({
80
+ file: ctx.file.path,
81
+ range: { line: lineOf(source, mappingIndex), column: 1 },
82
+ confidence: 72,
83
+ message: "Request body c\u1EE7a b\u1EC1 m\u1EB7t qu\u1EA3n l\xFD n\u1ED9i dung \u0111\u01B0\u1EE3c l\u01B0u khi ch\u01B0a th\u1EA5y HTML sanitization/encoding; \u0111\xE2y l\xE0 candidate Stored XSS/HTML Injection c\u1EA7n n\u1ED1i t\u1EDBi sink render. [control=stored-html-review]",
84
+ suggestion: "X\xE1c \u0111\u1ECBnh field cho ph\xE9p rich text. N\u1EBFu kh\xF4ng c\u1EA7n HTML, reject tag/markup; n\u1EBFu c\u1EA7n, sanitize b\u1EB1ng allowlist \u1EDF server tr\u01B0\u1EDBc khi l\u01B0u v\xE0 output-encode \u0111\xFAng context khi render. Th\xEAm test payload qua c\u1EA3 create v\xE0 update."
85
+ });
86
+ }
87
+ return findings;
88
+ }
89
+ };
90
+
91
+ export { rule };
92
+ //# sourceMappingURL=stored-content-without-sanitization.rule.js.map
93
+ //# sourceMappingURL=stored-content-without-sanitization.rule.js.map