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

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 +24115 -20069
  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 +24114 -20068
  30. package/node_modules/@code-sentinel/parsers/index.js +527 -6
  31. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ import { DOCKERFILE_RE, auditDockerfileContent } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/dockerfile-no-root-user.rule.ts
4
+ var rule = {
5
+ id: "general/dockerfile-no-root-user",
6
+ version: 2,
7
+ kind: "static-ts",
8
+ title: "Khai b\xE1o ch\u1EC9 th\u1ECB USER non-root trong Dockerfile (CWE-250)",
9
+ description: "Ph\xE1t hi\u1EC7n Dockerfile kh\xF4ng khai b\xE1o ch\u1EC9 th\u1ECB USER non-root khi\u1EBFn container ch\u1EA1y v\u1EDBi quy\u1EC1n root (UID 0) m\u1EB7c \u0111\u1ECBnh. Vi ph\u1EA1m nguy\xEAn t\u1EAFc \u0111\u1EB7c quy\u1EC1n t\u1ED1i thi\u1EC3u (CWE-250) v\xE0 t\u0103ng nguy c\u01A1 container escape.",
10
+ severity: "error",
11
+ category: "security",
12
+ languages: ["text"],
13
+ scope: "general",
14
+ requires: "text",
15
+ usesParser: false,
16
+ baseConfidence: 90,
17
+ check(ctx) {
18
+ const file = ctx.file;
19
+ if (!DOCKERFILE_RE.test(file.path)) return [];
20
+ const result = auditDockerfileContent(file.content, file.path);
21
+ if (!result.isRoot || result.reason.includes("kh\xF4ng ch\u1EE9a ch\u1EC9 th\u1ECB FROM")) return [];
22
+ return [
23
+ {
24
+ message: result.reason,
25
+ file: file.path,
26
+ range: { line: result.line, column: 1 },
27
+ severity: "error",
28
+ confidence: 90,
29
+ suggestion: result.user ? "Chuy\u1EC3n sang ng\u01B0\u1EDDi d\xF9ng kh\xF4ng c\xF3 \u0111\u1EB7c quy\u1EC1n (v\xED d\u1EE5: `USER appuser` ho\u1EB7c `USER 10001`)." : "T\u1EA1o v\xE0 chuy\u1EC3n sang ng\u01B0\u1EDDi d\xF9ng kh\xF4ng c\xF3 \u0111\u1EB7c quy\u1EC1n tr\u01B0\u1EDBc l\u1EC7nh ENTRYPOINT/CMD (v\xED d\u1EE5: `RUN useradd -u 10001 appuser && USER appuser`)."
30
+ }
31
+ ];
32
+ }
33
+ };
34
+
35
+ export { rule };
36
+ //# sourceMappingURL=dockerfile-no-root-user.rule.js.map
37
+ //# sourceMappingURL=dockerfile-no-root-user.rule.js.map
@@ -0,0 +1,34 @@
1
+ import { HTML_TEMPLATE_FILE_RE, auditPasswordAutocompleteContent } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/html-password-autocomplete-off.rule.ts
4
+ var rule = {
5
+ id: "general/html-password-autocomplete-off",
6
+ version: 2,
7
+ kind: "static-ts",
8
+ title: 'Khai b\xE1o thu\u1ED9c t\xEDnh autocomplete="off" cho \xF4 nh\u1EADp m\u1EADt kh\u1EA9u (CWE-522)',
9
+ description: 'Ph\xE1t hi\u1EC7n th\u1EBB <input type="password"> kh\xF4ng khai b\xE1o thu\u1ED9c t\xEDnh autocomplete="off" ho\u1EB7c "new-password", khi\u1EBFn tr\xECnh duy\u1EC7t t\u1EF1 \u0111\u1ED9ng l\u01B0u ho\u1EB7c g\u1EE3i \xFD m\u1EADt kh\u1EA9u, t\u1EA1o nguy c\u01A1 l\u1ED9 th\xF4ng tin tr\xEAn thi\u1EBFt b\u1ECB d\xF9ng chung (CWE-522 / WSTG-ATHN-07).',
10
+ severity: "error",
11
+ category: "security",
12
+ languages: ["html"],
13
+ scope: "general",
14
+ requires: "text",
15
+ usesParser: false,
16
+ baseConfidence: 85,
17
+ check(ctx) {
18
+ const file = ctx.file;
19
+ if (!HTML_TEMPLATE_FILE_RE.test(file.path)) return [];
20
+ const findings = auditPasswordAutocompleteContent(file.content, file.path);
21
+ return findings.map((f) => ({
22
+ message: f.reason,
23
+ file: file.path,
24
+ range: { line: f.line, column: 1 },
25
+ severity: "error",
26
+ confidence: 85,
27
+ suggestion: 'Th\xEAm thu\u1ED9c t\xEDnh autocomplete="off" ho\u1EB7c autocomplete="new-password" v\xE0o th\u1EBB <input type="password">.'
28
+ }));
29
+ }
30
+ };
31
+
32
+ export { rule };
33
+ //# sourceMappingURL=html-password-autocomplete-off.rule.js.map
34
+ //# sourceMappingURL=html-password-autocomplete-off.rule.js.map
@@ -0,0 +1,47 @@
1
+ import { maskJsComments } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-client-identity-header.rule.ts
4
+ var IDENTITY_HEADER_RE = /^(?:x-)?(?:[a-z0-9-]*)(?:user[-_]?id|userid|tenant[-_]?id|tenantid|account[-_]?id|accountid|role)$/i;
5
+ var SET_HEADER_RE = /\.\s*setHeader\s*\(\s*(['"])([^'"\r\n]+)\1\s*,/g;
6
+ var NAMED_HEADERS_RE = /\b(?:this\s*\.\s*)?(?:headers|httpHeaders|requestHeaders)\s*\.\s*(?:set|append)\s*\(\s*(['"])([^'"\r\n]+)\1\s*,/g;
7
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
8
+ var rule = {
9
+ id: "general/no-client-identity-header",
10
+ version: 1,
11
+ kind: "static-ts",
12
+ title: "Kh\xF4ng g\u1EAFn \u0111\u1ECBnh danh ho\u1EB7c quy\u1EC1n t\u1EEB HTTP header ph\xEDa client",
13
+ description: "Ph\xE1t hi\u1EC7n client g\u1EAFn custom HTTP header mang user/tenant/account/role identity. Header do browser t\u1EA1o c\xF3 th\u1EC3 b\u1ECB s\u1EEDa v\xE0 server ph\u1EA3i suy ra identity t\u1EEB token/session \u0111\xE3 x\xE1c th\u1EF1c (Fortify Header Manipulation).",
14
+ severity: "warning",
15
+ category: "security",
16
+ languages: ["typescript", "javascript"],
17
+ scope: "general",
18
+ requires: "syntactic",
19
+ usesParser: false,
20
+ baseConfidence: 85,
21
+ check(ctx) {
22
+ const content = maskJsComments(ctx.file.content);
23
+ const findings = [];
24
+ const seen = /* @__PURE__ */ new Set();
25
+ for (const pattern of [SET_HEADER_RE, NAMED_HEADERS_RE]) {
26
+ pattern.lastIndex = 0;
27
+ for (const match of content.matchAll(pattern)) {
28
+ const header = match[2] ?? "";
29
+ const index = match.index ?? 0;
30
+ if (!IDENTITY_HEADER_RE.test(header) || seen.has(index)) continue;
31
+ seen.add(index);
32
+ findings.push({
33
+ file: ctx.file.path,
34
+ range: { line: lineOf(content, index), column: 1 },
35
+ confidence: 85,
36
+ message: `Client g\u1EAFn header \u0111\u1ECBnh danh/quy\u1EC1n \`${header}\`; gi\xE1 tr\u1ECB n\xE0y c\xF3 th\u1EC3 b\u1ECB s\u1EEDa tr\u01B0\u1EDBc khi \u0111\u1EBFn server (Header Manipulation).`,
37
+ suggestion: "B\u1ECF header user/tenant/account/role do client t\u1EF1 g\u1EAFn. X\xE1c th\u1EF1c token/session \u1EDF server v\xE0 l\u1EA5y identity, tenant, role t\u1EEB claims ho\u1EB7c session \u0111\xE3 ki\u1EC3m ch\u1EE9ng; ch\u1EC9 ch\u1EA5p nh\u1EADn header khi gateway k\xFD/x\xE1c minh n\xF3."
38
+ });
39
+ }
40
+ }
41
+ return findings.sort((a, b) => a.range.line - b.range.line);
42
+ }
43
+ };
44
+
45
+ export { rule };
46
+ //# sourceMappingURL=no-client-identity-header.rule.js.map
47
+ //# sourceMappingURL=no-client-identity-header.rule.js.map
@@ -0,0 +1,79 @@
1
+ // builtin-rules/static/general/no-empty-encryption-key.rule.ts
2
+ var CONFIG_FILE_RE = /\.(?:ya?ml|properties)$/i;
3
+ var JAVA_OR_TS_RE = /\.(?:java|ts|js|mjs|cjs)$/i;
4
+ var EMPTY_KEY_VAR_RE = /\b(?:String|byte\[\]|const|let|var)\s+([a-zA-Z0-9_]*(?:secret(?:key)?|encryptionkey|aeskey|deskey|jwtsecret|privatekey|cipherkey)[a-zA-Z0-9_]*)\s*=\s*(?:""|''|`\s*`|new\s+byte\[0\]|new\s+byte\[\]\s*\{\s*\}|\{\s*\})/i;
5
+ var EMPTY_SECRET_KEY_SPEC_RE = /new\s+SecretKeySpec\s*\(\s*(?:""\s*\.getBytes\([^)]*\)|new\s+byte\[0\]|new\s+byte\[\]\s*\{\s*\}|\{\s*\})/i;
6
+ var CONFIG_EMPTY_KEY_RE = /^[^\S\n]*([a-zA-Z0-9_.-]*(?:jwt[._-]secret|secret[._-]key|encryption[._-]key|aes[._-]key|cipher[._-]key|private[._-]key)[a-zA-Z0-9_.-]*)\s*[:=]\s*(?:""|''|\s*)$/i;
7
+ var rule = {
8
+ id: "general/no-empty-encryption-key",
9
+ version: 1,
10
+ kind: "static-ts",
11
+ title: "Kh\xF4ng s\u1EED d\u1EE5ng kh\xF3a m\xE3 h\xF3a r\u1ED7ng (Empty Encryption Key / Secret)",
12
+ description: 'Ph\xE1t hi\u1EC7n vi\u1EC7c kh\u1EDFi t\u1EA1o SecretKeySpec ho\u1EB7c g\xE1n bi\u1EBFn/c\u1EA5u h\xECnh kh\xF3a m\xE3 h\xF3a (AES, DES, JWT, Cipher) v\u1EDBi gi\xE1 tr\u1ECB r\u1ED7ng ("" ho\u1EB7c new byte[0]). Vi\u1EC7c s\u1EED d\u1EE5ng kh\xF3a r\u1ED7ng khi\u1EBFn thu\u1EADt to\xE1n m\u1EADt m\xE3 m\u1EA5t ho\xE0n to\xE0n t\xEDnh b\u1EA3o m\u1EADt, cho ph\xE9p k\u1EBB t\u1EA5n c\xF4ng d\u1EC5 d\xE0ng gi\u1EA3i m\xE3 d\u1EEF li\u1EC7u ho\u1EB7c gi\u1EA3 m\u1EA1o token (CWE-321/CWE-547).',
13
+ severity: "error",
14
+ category: "security",
15
+ languages: ["java", "typescript", "javascript", "yaml", "text"],
16
+ scope: "general",
17
+ requires: "text",
18
+ usesParser: false,
19
+ baseConfidence: 95,
20
+ check(ctx) {
21
+ const file = ctx.file;
22
+ const isCode = JAVA_OR_TS_RE.test(file.path);
23
+ const isConfig = CONFIG_FILE_RE.test(file.path);
24
+ if (!isCode && !isConfig) return [];
25
+ const findings = [];
26
+ const lines = file.content.split("\n");
27
+ for (let i = 0; i < lines.length; i++) {
28
+ const line = lines[i] ?? "";
29
+ const trimmed = line.trim();
30
+ if (!trimmed || trimmed.startsWith("#") || trimmed.startsWith("//") || trimmed.startsWith("*")) {
31
+ continue;
32
+ }
33
+ if (isCode) {
34
+ if (EMPTY_SECRET_KEY_SPEC_RE.test(trimmed)) {
35
+ findings.push({
36
+ message: "Kh\u1EDFi t\u1EA1o SecretKeySpec v\u1EDBi kh\xF3a r\u1ED7ng (chu\u1ED7i r\u1ED7ng ho\u1EB7c m\u1EA3ng byte \u0111\u1ED9 d\xE0i 0) \u2014 CWE-321/CWE-547.",
37
+ file: file.path,
38
+ range: { line: i + 1, column: 1 },
39
+ severity: "error",
40
+ confidence: 95,
41
+ suggestion: "T\u1EA1o kh\xF3a m\xE3 h\xF3a an to\xE0n b\u1EB1ng KeyGenerator ho\u1EB7c n\u1EA1p kh\xF3a m\u1EADt m\xE3 c\xF3 \u0111\u1ED9 d\xE0i h\u1EE3p l\u1EC7 t\u1EEB bi\u1EBFn m\xF4i tr\u01B0\u1EDDng/Vault."
42
+ });
43
+ continue;
44
+ }
45
+ const varMatch = trimmed.match(EMPTY_KEY_VAR_RE);
46
+ if (varMatch) {
47
+ const varName = varMatch[1];
48
+ findings.push({
49
+ message: `Bi\u1EBFn kh\xF3a m\xE3 h\xF3a \`${varName}\` \u0111\u01B0\u1EE3c g\xE1n gi\xE1 tr\u1ECB r\u1ED7ng \u2014 CWE-321/CWE-547.`,
50
+ file: file.path,
51
+ range: { line: i + 1, column: 1 },
52
+ severity: "error",
53
+ confidence: 90,
54
+ suggestion: "Kh\xF4ng g\xE1n gi\xE1 tr\u1ECB r\u1ED7ng cho bi\u1EBFn kh\xF3a m\u1EADt m\xE3. N\u1EA1p kh\xF3a an to\xE0n t\u1EEB c\u1EA5u h\xECnh b\u1EA3o m\u1EADt ho\u1EB7c KeyManagementService."
55
+ });
56
+ }
57
+ }
58
+ if (isConfig) {
59
+ const configMatch = trimmed.match(CONFIG_EMPTY_KEY_RE);
60
+ if (configMatch) {
61
+ const propName = configMatch[1];
62
+ findings.push({
63
+ message: `Thu\u1ED9c t\xEDnh b\u1EA3o m\u1EADt \`${propName}\` trong c\u1EA5u h\xECnh mang gi\xE1 tr\u1ECB r\u1ED7ng \u2014 CWE-321/CWE-547.`,
64
+ file: file.path,
65
+ range: { line: i + 1, column: 1 },
66
+ severity: "error",
67
+ confidence: 90,
68
+ suggestion: "Cung c\u1EA5p gi\xE1 tr\u1ECB kh\xF3a b\xED m\u1EADt h\u1EE3p l\u1EC7 qua bi\u1EBFn m\xF4i tr\u01B0\u1EDDng (v\xED d\u1EE5: `${JWT_SECRET}`)."
69
+ });
70
+ }
71
+ }
72
+ }
73
+ return findings;
74
+ }
75
+ };
76
+
77
+ export { rule };
78
+ //# sourceMappingURL=no-empty-encryption-key.rule.js.map
79
+ //# sourceMappingURL=no-empty-encryption-key.rule.js.map
@@ -0,0 +1,39 @@
1
+ import { maskJsComments } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-guessable-websql-database-name.rule.ts
4
+ var OPEN_DATABASE_LITERAL_RE = /\b(?:(?:[A-Za-z_$][\w$]*\s*\.\s*)*)openDatabase\s*\(\s*(['"])([^'"\r\n]+)\1/g;
5
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
6
+ var rule = {
7
+ id: "general/no-guessable-websql-database-name",
8
+ version: 2,
9
+ kind: "static-ts",
10
+ title: "Kh\xF4ng d\xF9ng t\xEAn Web SQL c\xF3 th\u1EC3 \u0111o\xE1n t\u1EEB bundle",
11
+ description: "Ph\xE1t hi\u1EC7n g\u1ECDi openDatabase() (k\u1EC3 c\u1EA3 qua namespace) d\xF9ng t\xEAn literal trong m\xE3 client. T\xEAn database hi\u1EC7n r\xF5 trong bundle n\xEAn kh\xF4ng \u0111\u01B0\u1EE3c xem l\xE0 l\u1EDBp b\u1EA3o v\u1EC7 d\u1EEF li\u1EC7u (Fortify HTML5: Easy-to-Guess Database Name).",
12
+ severity: "warning",
13
+ category: "security",
14
+ languages: ["typescript", "javascript"],
15
+ scope: "general",
16
+ requires: "syntactic",
17
+ usesParser: false,
18
+ baseConfidence: 80,
19
+ check(ctx) {
20
+ const content = maskJsComments(ctx.file.content);
21
+ const findings = [];
22
+ OPEN_DATABASE_LITERAL_RE.lastIndex = 0;
23
+ for (const match of content.matchAll(OPEN_DATABASE_LITERAL_RE)) {
24
+ const name = match[2] ?? "database";
25
+ findings.push({
26
+ file: ctx.file.path,
27
+ range: { line: lineOf(content, match.index ?? 0), column: 1 },
28
+ confidence: 80,
29
+ message: `Web SQL database name \`${name}\` \u0111\u01B0\u1EE3c hard-code trong client v\xE0 d\u1EC5 \u0111o\xE1n (HTML5: Easy-to-Guess Database Name).`,
30
+ suggestion: "Kh\xF4ng l\u01B0u secret/PII trong Web SQL v\xE0 kh\xF4ng coi t\xEAn database l\xE0 ki\u1EC3m so\xE1t truy c\u1EADp. \u01AFu ti\xEAn b\u1ECF Web SQL \u0111\xE3 deprecated; n\u1EBFu ph\u1EA3i t\u01B0\u01A1ng th\xEDch legacy, d\xF9ng t\xEAn opaque \u0111\u01B0\u1EE3c c\u1EA5u h\xECnh/generate v\xE0 v\u1EABn b\u1EA3o v\u1EC7 d\u1EEF li\u1EC7u b\u1EB1ng ki\u1EC3m so\xE1t ph\xEDa server."
31
+ });
32
+ }
33
+ return findings;
34
+ }
35
+ };
36
+
37
+ export { rule };
38
+ //# sourceMappingURL=no-guessable-websql-database-name.rule.js.map
39
+ //# sourceMappingURL=no-guessable-websql-database-name.rule.js.map
@@ -315,6 +315,18 @@ var GENERIC_PATTERNS = [
315
315
  message: "Hard-coded password assignment detected.",
316
316
  payloadGroup: 1
317
317
  },
318
+ {
319
+ name: "empty-password-assignment",
320
+ regex: /\b(?:[A-Za-z_$][\w$]*(?:password|passwd|pwd)|password|passwd|pwd)\s*[:=]\s*["']\s*["']/gi,
321
+ confidence: 85,
322
+ message: "Empty password assignment detected (CWE-258 / CWE-798). Passwords must not be empty."
323
+ },
324
+ {
325
+ name: "empty-password-method-call",
326
+ regex: /\b(?:setPassword|withPassword|updatePassword)\s*\(\s*["']\s*["']\s*\)/gi,
327
+ confidence: 85,
328
+ message: "Empty password passed to setter method (CWE-258 / CWE-798)."
329
+ },
318
330
  {
319
331
  name: "generic-api-key-assignment",
320
332
  regex: /\b(?:api[_-]?key|apikey|access[_-]?token|auth[_-]?token)\s*[:=]\s*["']([A-Za-z0-9_\-./+=]{16,})["']/gi,
@@ -337,6 +349,12 @@ var CONFIG_SECRET_PATTERNS = [
337
349
  confidence: 75,
338
350
  message: "Config file secret value detected.",
339
351
  payloadGroup: 1
352
+ },
353
+ {
354
+ name: "config-empty-password",
355
+ regex: /^\s*(?:[-\w.]+\.)?(?:password|passwd|pwd)\s*[:=]\s*(?:["']\s*["']\s*$|\s*$)/gim,
356
+ confidence: 85,
357
+ message: "Empty password in configuration file (CWE-258 / CWE-798)."
340
358
  }
341
359
  ];
342
360
  var BUILTIN_PATTERNS = [
@@ -403,7 +421,7 @@ var looksExternalized = (payload) => {
403
421
  const lower = trimmed.toLowerCase();
404
422
  return trimmed.startsWith("${") || lower.startsWith("enc(") || lower.startsWith("{cipher}") || lower.startsWith("vault://") || lower.startsWith("optional:vault://");
405
423
  };
406
- var isConfigLanguage = (language) => language === "yaml" || language === "text";
424
+ var isConfigLanguage = (language) => language === "yaml" || language === "text" || language === "shell";
407
425
  var lineColAt = (content, offset) => {
408
426
  let line = 1;
409
427
  let lastNl = -1;
@@ -446,6 +464,7 @@ var isOwnTestFile = (filePath) => {
446
464
  };
447
465
  var rule = {
448
466
  id: "general/no-hardcoded-secret",
467
+ // v5: added empty-password-assignment and config-empty-password patterns (CWE-258/798).
449
468
  // v4: source-only execution + YAML/text support for Spring Boot application
450
469
  // config files. `.properties` is classified as `text`.
451
470
  // v3: generic password assignment also catches suffixed identifiers such as
@@ -453,14 +472,14 @@ var rule = {
453
472
  // v2 (1.2.1): added FIELD_NAME_ECHOES filter for enum-value / label-dict
454
473
  // FPs (e.g. `PASSWORD = 'password'`). Bumped so the rule cache invalidates
455
474
  // stale v1 findings — Phase 9 cache key is (id, version, file.hash).
456
- version: 4,
475
+ version: 5,
457
476
  kind: "static-ts",
458
477
  title: "Kh\xF4ng hardcode secrets / API keys / private keys v\xE0o source",
459
478
  description: "Qu\xE9t credentials, API keys, tokens, private keys committed v\xE0o code. H\u1ED7 tr\u1EE3 AWS / GitHub / GitLab / Slack / Stripe / Google / Azure / Twilio / SendGrid / Mailgun / NPM / PyPI / Discord / Telegram / DataDog / New Relic / Cloudflare / DigitalOcean / Docker Hub + PEM private keys + connection strings c\xF3 inline credentials + JWT + generic password/secret/apiKey assignments. Severity = error (CI gate). Confidence t\u1EEB 65 (generic, c\xF3 false positive) t\u1EDBi 95 (provider-prefixed, near-zero false positive). Tune qua options.disabledPatterns + options.extraPatterns.",
460
479
  severity: "error",
461
480
  category: "security",
462
481
  // Pure content scan: can run on YAML and text-classified config files.
463
- languages: ["typescript", "javascript", "java", "yaml", "text"],
482
+ languages: ["typescript", "javascript", "java", "yaml", "text", "shell"],
464
483
  scope: "general",
465
484
  usesParser: false,
466
485
  baseConfidence: 80,
@@ -0,0 +1,52 @@
1
+ import { isExcludedHost } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-insecure-external-link.rule.ts
4
+ var HTML_FILE_RE = /\.(?:html|xhtml|jsp|ftl)$/i;
5
+ var LINK_TAG_RE = /<(?:a|script|link|img|iframe|video|source|embed)\b[^>]*?\b(?:href|src)\s*=\s*["'](http:\/\/[^"'>\s]+)["'][^>]*?>/gi;
6
+ var rule = {
7
+ id: "general/no-insecure-external-link",
8
+ version: 2,
9
+ kind: "static-ts",
10
+ title: "Kh\xF4ng s\u1EED d\u1EE5ng li\xEAn k\u1EBFt ngo\u1EA1i b\u1ED9 qua HTTP cleartext (CWE-319)",
11
+ description: "Ph\xE1t hi\u1EC7n li\xEAn k\u1EBFt ho\u1EB7c t\xE0i nguy\xEAn ngo\u1EA1i b\u1ED9 (<a href>, <script src>, <link href>) s\u1EED d\u1EE5ng giao th\u1EE9c cleartext http:// thay v\xEC https://. D\u1EEF li\u1EC7u truy\u1EC1n t\u1EA3i c\xF3 nguy c\u01A1 b\u1ECB nghe l\xE9n, gi\u1EA3 m\u1EA1o ho\u1EB7c t\u1EA5n c\xF4ng Man-In-The-Middle (CWE-319).",
12
+ severity: "warning",
13
+ category: "security",
14
+ languages: ["html"],
15
+ scope: "general",
16
+ requires: "text",
17
+ usesParser: false,
18
+ baseConfidence: 80,
19
+ check(ctx) {
20
+ const file = ctx.file;
21
+ if (!HTML_FILE_RE.test(file.path)) return [];
22
+ const content = file.content.replace(/<!--[\s\S]*?-->/g, (m) => " ".repeat(m.length));
23
+ LINK_TAG_RE.lastIndex = 0;
24
+ let match = LINK_TAG_RE.exec(content);
25
+ const findings = [];
26
+ while (match !== null) {
27
+ const url = match[1] ?? "";
28
+ const hostMatch = url.match(/^http:\/\/([A-Za-z0-9._\-]+(?::\d+)?)/i);
29
+ const host = hostMatch ? hostMatch[1] ?? "" : "";
30
+ if (host && !isExcludedHost(host)) {
31
+ const before = content.slice(0, match.index);
32
+ const lines = before.split("\n");
33
+ const line = lines.length;
34
+ const column = (lines.at(-1)?.length ?? 0) + 1;
35
+ findings.push({
36
+ message: `Li\xEAn k\u1EBFt ngo\u1EA1i b\u1ED9 s\u1EED d\u1EE5ng HTTP cleartext: '${url}' \u2014 d\u1EEF li\u1EC7u truy\u1EC1n kh\xF4ng \u0111\u01B0\u1EE3c m\xE3 ho\xE1 (CWE-319).`,
37
+ file: file.path,
38
+ range: { line, column },
39
+ severity: "warning",
40
+ confidence: 80,
41
+ suggestion: `Chuy\u1EC3n \u0111\u01B0\u1EDDng d\u1EABn sang giao th\u1EE9c an to\xE0n HTTPS (v\xED d\u1EE5: '${url.replace(/^http:/i, "https:")}').`
42
+ });
43
+ }
44
+ match = LINK_TAG_RE.exec(content);
45
+ }
46
+ return findings;
47
+ }
48
+ };
49
+
50
+ export { rule };
51
+ //# sourceMappingURL=no-insecure-external-link.rule.js.map
52
+ //# sourceMappingURL=no-insecure-external-link.rule.js.map
@@ -0,0 +1,75 @@
1
+ import { isExcludedHost } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-insecure-password-submission.rule.ts
4
+ var HTML_FILE_RE = /\.(?:html|htm|jsp|xhtml|ftl)$/i;
5
+ var lineColumnAt = (content, index) => {
6
+ const safeIndex = Math.max(0, Math.min(index, content.length));
7
+ const before = content.slice(0, safeIndex);
8
+ const lines = before.split(/\r?\n/);
9
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
10
+ };
11
+ var rule = {
12
+ id: "general/no-insecure-password-submission",
13
+ version: 2,
14
+ kind: "static-ts",
15
+ title: "Kh\xF4ng submit m\u1EADt kh\u1EA9u qua HTTP cleartext ho\u1EB7c method GET",
16
+ description: 'Form nh\u1EADp m\u1EADt kh\u1EA9u g\u1EEDi d\u1EEF li\u1EC7u qua HTTP kh\xF4ng m\xE3 h\xF3a (CWE-319, WSTG-ATHN-01) ho\u1EB7c d\xF9ng method="GET" (CWE-598) khi\u1EBFn th\xF4ng tin x\xE1c th\u1EF1c b\u1ECB l\u1ED9 tr\xEAn \u0111\u01B0\u1EDDng truy\u1EC1n m\u1EA1ng, query string v\xE0 log m\xE1y ch\u1EE7.',
17
+ severity: "error",
18
+ category: "security",
19
+ languages: ["html", "text"],
20
+ scope: "general",
21
+ requires: "text",
22
+ usesParser: false,
23
+ baseConfidence: 85,
24
+ check(ctx) {
25
+ const file = ctx.file;
26
+ if (!HTML_FILE_RE.test(file.path)) return [];
27
+ const content = file.content.replace(/<!--[\s\S]*?-->/g, (m2) => " ".repeat(m2.length));
28
+ const findings = [];
29
+ const formRe = /<form\b([^>]*)>([\s\S]*?)<\/form>/gi;
30
+ let m = formRe.exec(content);
31
+ while (m !== null) {
32
+ const formAttrs = m[1] ?? "";
33
+ const formBody = m[2] ?? "";
34
+ const matchIndex = m.index;
35
+ const hasPassword = /<input\b[^>]*\btype\s*=\s*["']password["']/i.test(formBody) || /<input\b[^>]*\[type\]\s*=\s*["'](?:'password'|"password")["']/i.test(formBody);
36
+ if (hasPassword) {
37
+ const actionMatch = formAttrs.match(/\baction\s*=\s*["'](http:\/\/[^"'\s>]+)["']/i);
38
+ if (actionMatch) {
39
+ const url = actionMatch[1] ?? "";
40
+ const hostMatch = url.match(/^http:\/\/([A-Za-z0-9._\-]+(?::\d+)?)/i);
41
+ const host = hostMatch?.[1] ?? "";
42
+ if (!isExcludedHost(host)) {
43
+ const { line, column } = lineColumnAt(content, matchIndex);
44
+ findings.push({
45
+ message: `Form \u0111\u0103ng nh\u1EADp ch\u1EE9a password submit t\u1EDBi endpoint HTTP cleartext: ${url} (CWE-319, WSTG-ATHN-01).`,
46
+ file: file.path,
47
+ range: { line, column },
48
+ severity: "error",
49
+ confidence: 85,
50
+ suggestion: "Chuy\u1EC3n action c\u1EE7a form sang giao th\u1EE9c HTTPS an to\xE0n (v\xED d\u1EE5: `https://...`) c\xF3 ch\u1EE9ng ch\u1EC9 CA h\u1EE3p l\u1EC7."
51
+ });
52
+ }
53
+ }
54
+ const methodMatch = formAttrs.match(/\bmethod\s*=\s*["']get["']/i);
55
+ if (methodMatch) {
56
+ const { line, column } = lineColumnAt(content, matchIndex);
57
+ findings.push({
58
+ message: 'Form \u0111\u0103ng nh\u1EADp ch\u1EE9a password s\u1EED d\u1EE5ng method="GET" \u2192 l\u1ED9 th\xF4ng tin x\xE1c th\u1EF1c tr\xEAn URL query string v\xE0 server logs (CWE-598).',
59
+ file: file.path,
60
+ range: { line, column },
61
+ severity: "error",
62
+ confidence: 90,
63
+ suggestion: 'S\u1EED d\u1EE5ng method="POST" \u0111\u1EC3 truy\u1EC1n th\xF4ng tin x\xE1c th\u1EF1c trong request body.'
64
+ });
65
+ }
66
+ }
67
+ m = formRe.exec(content);
68
+ }
69
+ return findings;
70
+ }
71
+ };
72
+
73
+ export { rule };
74
+ //# sourceMappingURL=no-insecure-password-submission.rule.js.map
75
+ //# sourceMappingURL=no-insecure-password-submission.rule.js.map
@@ -0,0 +1,50 @@
1
+ import { maskJavaFiles } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-reflective-access-override.rule.ts
4
+ var INSTANCE_SET_ACCESSIBLE_RE = /\b[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*\.\s*setAccessible\s*\(\s*true\s*\)/g;
5
+ var TRY_SET_ACCESSIBLE_RE = /\b[A-Za-z_$][\w$]*(?:\s*\.\s*[A-Za-z_$][\w$]*)*\s*\.\s*trySetAccessible\s*\(\s*\)/g;
6
+ var STATIC_SET_ACCESSIBLE_RE = /\bAccessibleObject\s*\.\s*setAccessible\s*\(\s*[^,;\n]+\s*,\s*true\s*\)/g;
7
+ var maskStringLiterals = (content) => content.replace(/"(?:[^"\\]|\\.)*"/g, (literal) => literal.replace(/[^\n]/g, " "));
8
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
9
+ var finding = (file, line, api) => ({
10
+ file,
11
+ range: { line, column: 1 },
12
+ confidence: 80,
13
+ message: `Reflection ${api} v\u01B0\u1EE3t ki\u1EC3m so\xE1t private/protected c\u1EE7a Java (Access Specifier Manipulation).`,
14
+ suggestion: "\u01AFu ti\xEAn getter/setter ho\u1EB7c mapper c\xF3 allowlist. N\u1EBFu b\u1EAFt bu\u1ED9c reflection, gi\u1EDBi h\u1EA1n class/field c\u1ED1 \u0111\u1ECBnh, kh\xF4ng nh\u1EADn t\xEAn field hay object t\u1EEB request/config kh\xF4ng tin c\u1EADy, v\xE0 ghi suppression k\xE8m l\xFD do."
15
+ });
16
+ var rule = {
17
+ id: "general/no-reflective-access-override",
18
+ version: 1,
19
+ kind: "static-ts",
20
+ title: "Kh\xF4ng v\u01B0\u1EE3t access modifier b\u1EB1ng Java reflection",
21
+ description: "Ph\xE1t hi\u1EC7n Field/Method/AccessibleObject g\u1ECDi setAccessible(true) ho\u1EB7c trySetAccessible(), c\xF3 th\u1EC3 v\u01B0\u1EE3t private/protected access control.",
22
+ severity: "warning",
23
+ category: "security",
24
+ languages: ["java"],
25
+ scope: "general",
26
+ requires: "syntactic",
27
+ usesParser: false,
28
+ baseConfidence: 80,
29
+ check(ctx) {
30
+ const source = maskJavaFiles([ctx.file])[0] ?? ctx.file;
31
+ const content = maskStringLiterals(source.content);
32
+ const findings = [];
33
+ const patterns = [
34
+ { re: INSTANCE_SET_ACCESSIBLE_RE, api: "setAccessible(true)" },
35
+ { re: TRY_SET_ACCESSIBLE_RE, api: "trySetAccessible()" },
36
+ { re: STATIC_SET_ACCESSIBLE_RE, api: "AccessibleObject.setAccessible(..., true)" }
37
+ ];
38
+ for (const { re, api } of patterns) {
39
+ re.lastIndex = 0;
40
+ for (const match of content.matchAll(re)) {
41
+ findings.push(finding(source.path, lineOf(content, match.index ?? 0), api));
42
+ }
43
+ }
44
+ return findings.sort((a, b) => a.range.line - b.range.line);
45
+ }
46
+ };
47
+
48
+ export { rule };
49
+ //# sourceMappingURL=no-reflective-access-override.rule.js.map
50
+ //# sourceMappingURL=no-reflective-access-override.rule.js.map
@@ -0,0 +1,124 @@
1
+ import { maskJavaFiles, asTreeSitterTree } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-sensitive-string-materialization.rule.ts
4
+ var STRING_CONSTRUCTOR_RE = /\bnew\s+String\s*\(\s*([^;\n]{0,300}?)(?:\)|$)/g;
5
+ var SENSITIVE_PRODUCER_RE = /\bdecrypt\w*\s*\(|\bget(?:Password|Passwd|Pwd|Secret|Token|Key)\s*\(/i;
6
+ var SENSITIVE_IDENTIFIER_RE = /\b\w*(?:password|passwd|pwd|secret|token|privatekey|apikey|credential|accesskey|signingkey|encryptionkey)\w*\b/i;
7
+ var CRYPTO_OPERATION_RE = /^(?:encrypt|decrypt|sign|verify|cipher|mac)/i;
8
+ var METHOD_NODE_TYPES = /* @__PURE__ */ new Set(["method_declaration", "constructor_declaration"]);
9
+ var maskStringLiterals = (content) => content.replace(/"(?:[^"\\]|\\.)*"/g, (literal) => literal.replace(/[^\n]/g, " "));
10
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
11
+ var isSensitiveMaterial = (argument) => SENSITIVE_PRODUCER_RE.test(argument) || SENSITIVE_IDENTIFIER_RE.test(argument);
12
+ function* walk(node) {
13
+ const stack = [node];
14
+ while (stack.length > 0) {
15
+ const current = stack.pop();
16
+ if (!current) continue;
17
+ yield current;
18
+ for (let index = current.namedChildCount - 1; index >= 0; index--) {
19
+ const child = current.namedChild(index);
20
+ if (child) stack.push(child);
21
+ }
22
+ }
23
+ }
24
+ var enclosingMethod = (node) => {
25
+ let current = node.parent;
26
+ while (current) {
27
+ if (METHOD_NODE_TYPES.has(current.type)) return current;
28
+ current = current.parent;
29
+ }
30
+ return null;
31
+ };
32
+ var declaredByteArrays = (method) => {
33
+ const names = /* @__PURE__ */ new Set();
34
+ for (const node of walk(method)) {
35
+ if (node.type !== "formal_parameter" && node.type !== "local_variable_declaration") continue;
36
+ const type = node.childForFieldName("type");
37
+ if (type?.text.replace(/\s/g, "") !== "byte[]") continue;
38
+ if (node.type === "formal_parameter") {
39
+ const name = node.childForFieldName("name");
40
+ if (name) names.add(name.text);
41
+ continue;
42
+ }
43
+ for (const child of walk(node)) {
44
+ if (child.type !== "variable_declarator") continue;
45
+ const name = child.childForFieldName("name");
46
+ if (name) names.add(name.text);
47
+ }
48
+ }
49
+ return names;
50
+ };
51
+ var hasCryptoKeyContext = (method) => {
52
+ let hasCryptoOperation = false;
53
+ let hasSensitiveKeyIdentifier = false;
54
+ for (const node of walk(method)) {
55
+ if (node.type === "method_invocation") {
56
+ const name = node.childForFieldName("name")?.text;
57
+ if (name && CRYPTO_OPERATION_RE.test(name)) hasCryptoOperation = true;
58
+ }
59
+ if (node.type === "identifier" && SENSITIVE_IDENTIFIER_RE.test(node.text)) {
60
+ hasSensitiveKeyIdentifier = true;
61
+ }
62
+ }
63
+ return hasCryptoOperation && hasSensitiveKeyIdentifier;
64
+ };
65
+ var firstConstructorArgument = (node) => {
66
+ const argumentsNode = node.childForFieldName("arguments");
67
+ return argumentsNode?.namedChild(0) ?? null;
68
+ };
69
+ var isStringConstructor = (node) => node.type === "object_creation_expression" && node.childForFieldName("type")?.text === "String";
70
+ var rule = {
71
+ id: "general/no-sensitive-string-materialization",
72
+ version: 2,
73
+ kind: "static-ts",
74
+ title: "Kh\xF4ng chuy\u1EC3n d\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m sang Java String",
75
+ description: "Ph\xE1t hi\u1EC7n password/secret/token/key ho\u1EB7c k\u1EBFt qu\u1EA3 decrypt \u0111\u01B0\u1EE3c t\u1EA1o th\xE0nh immutable String, v\xE0 byte[] trong ng\u1EEF c\u1EA3nh crypto/key b\u1ECB chuy\u1EC3n sang String (Fortify Weak Encryption: Byte Array to String Conversion).",
76
+ severity: "warning",
77
+ category: "security",
78
+ languages: ["java"],
79
+ scope: "general",
80
+ requires: "syntactic",
81
+ baseConfidence: 80,
82
+ check(ctx) {
83
+ const source = maskJavaFiles([ctx.file])[0] ?? ctx.file;
84
+ const content = maskStringLiterals(source.content);
85
+ const findings = [];
86
+ const seenLines = /* @__PURE__ */ new Set();
87
+ for (const match of content.matchAll(STRING_CONSTRUCTOR_RE)) {
88
+ const argument = match[1] ?? "";
89
+ if (!isSensitiveMaterial(argument)) continue;
90
+ const line = lineOf(content, match.index ?? 0);
91
+ seenLines.add(line);
92
+ findings.push({
93
+ file: source.path,
94
+ range: { line, column: 1 },
95
+ confidence: 80,
96
+ message: "D\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m \u0111\u01B0\u1EE3c materialize th\xE0nh immutable Java String (Privacy Violation: Heap Inspection).",
97
+ suggestion: "Gi\u1EEF d\u1EEF li\u1EC7u \u1EDF byte[]/char[] trong ph\u1EA1m vi ng\u1EAFn nh\u1EA5t, x\xF3a buffer b\u1EB1ng Arrays.fill(...) sau khi d\xF9ng v\xE0 \u01B0u ti\xEAn API nh\u1EADn byte[]/char[] thay v\xEC String."
98
+ });
99
+ }
100
+ const tree = asTreeSitterTree(ctx.parsed);
101
+ for (const node of walk(tree.rootNode)) {
102
+ if (!isStringConstructor(node)) continue;
103
+ const argument = firstConstructorArgument(node);
104
+ if (argument?.type !== "identifier") continue;
105
+ const method = enclosingMethod(node);
106
+ if (!method || !declaredByteArrays(method).has(argument.text)) continue;
107
+ if (!hasCryptoKeyContext(method)) continue;
108
+ const line = node.startPosition.row + 1;
109
+ if (seenLines.has(line)) continue;
110
+ findings.push({
111
+ file: ctx.file.path,
112
+ range: { line, column: node.startPosition.column + 1 },
113
+ confidence: 75,
114
+ message: "Byte array trong ng\u1EEF c\u1EA3nh crypto/key \u0111\u01B0\u1EE3c chuy\u1EC3n th\xE0nh Java String (Weak Encryption: Byte Array to String Conversion).",
115
+ suggestion: "Kh\xF4ng chuy\u1EC3n crypto key ho\u1EB7c d\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m sang String. Gi\u1EEF \u1EDF byte[]/char[] trong ph\u1EA1m vi ng\u1EAFn nh\u1EA5t, x\xF3a buffer b\u1EB1ng Arrays.fill(...) sau khi d\xF9ng v\xE0 d\xF9ng API nh\u1EADn byte[]/char[] thay v\xEC String."
116
+ });
117
+ }
118
+ return findings.sort((left, right) => left.range.line - right.range.line);
119
+ }
120
+ };
121
+
122
+ export { rule };
123
+ //# sourceMappingURL=no-sensitive-string-materialization.rule.js.map
124
+ //# sourceMappingURL=no-sensitive-string-materialization.rule.js.map