@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
@@ -2,6 +2,16 @@ import { findDirectedCycles } from '@code-sentinel/core';
2
2
 
3
3
  // builtin-rules/static/general/no-circular-import.rule.ts
4
4
  var importLikeKinds = ["import", "re-export"];
5
+ var cyclesByGraph = /* @__PURE__ */ new WeakMap();
6
+ var cyclesForGraph = (graph) => {
7
+ const cachedCycles = cyclesByGraph.get(graph);
8
+ if (cachedCycles) {
9
+ return cachedCycles;
10
+ }
11
+ const cycles = findDirectedCycles(graph, { edgeKinds: importLikeKinds });
12
+ cyclesByGraph.set(graph, cycles);
13
+ return cycles;
14
+ };
5
15
  var formatCycle = (paths) => paths.join(" -> ");
6
16
  var rule = {
7
17
  id: "general/no-circular-import",
@@ -18,7 +28,7 @@ var rule = {
18
28
  baseConfidence: 95,
19
29
  check(ctx) {
20
30
  if (!ctx.astGraph) return [];
21
- const cycles = findDirectedCycles(ctx.astGraph, { edgeKinds: importLikeKinds });
31
+ const cycles = cyclesForGraph(ctx.astGraph);
22
32
  const findings = [];
23
33
  for (const cycle of cycles) {
24
34
  const primaryPath = cycle.paths[0];
@@ -34,6 +44,6 @@ var rule = {
34
44
  }
35
45
  };
36
46
 
37
- export { rule };
47
+ export { cyclesForGraph, rule };
38
48
  //# sourceMappingURL=no-circular-import.rule.js.map
39
49
  //# sourceMappingURL=no-circular-import.rule.js.map
@@ -0,0 +1,84 @@
1
+ import { isThirdPartyAsset, maskJsComments } from '@code-sentinel/parsers';
2
+
3
+ // builtin-rules/static/general/no-dynamic-code-eval.rule.ts
4
+ var EVAL_CALL_RE = /(?<![\w$.])(?:(?:window|globalThis|self)\s*\.\s*)?eval\s*\(/g;
5
+ var NEW_FUNCTION_RE = /(?<![\w$.])new\s+Function\s*\(/g;
6
+ var STRING_CONSTANT_RE = /^\s*(?:'(?:[^'\\\n]|\\.)*'|"(?:[^"\\\n]|\\.)*"|`(?:[^`\\$]|\\.|\$(?!\{))*`)\s*$/;
7
+ var WRAP_PAREN_RE = /^\s*(['"`])\s*\(\s*\1\s*\+/;
8
+ var callArguments = (src, open) => {
9
+ const args = [];
10
+ let depth = 0;
11
+ let start = open + 1;
12
+ for (let i = open; i < src.length; i++) {
13
+ const ch = src[i];
14
+ if (ch === "'" || ch === '"' || ch === "`") {
15
+ for (i++; i < src.length && src[i] !== ch; i++) if (src[i] === "\\") i++;
16
+ continue;
17
+ }
18
+ if (ch === "(" || ch === "[" || ch === "{") depth++;
19
+ else if (ch === ")" || ch === "]" || ch === "}") {
20
+ depth--;
21
+ if (depth === 0) {
22
+ args.push(src.slice(start, i));
23
+ return args.map((a) => a.trim()).filter((a, _idx, all) => a !== "" || all.length > 1);
24
+ }
25
+ } else if (ch === "," && depth === 1) {
26
+ args.push(src.slice(start, i));
27
+ start = i + 1;
28
+ }
29
+ }
30
+ return null;
31
+ };
32
+ var lineOf = (content, index) => content.slice(0, index).split("\n").length;
33
+ var shorten = (s) => {
34
+ const one = s.replace(/\s+/g, " ").trim();
35
+ return one.length > 80 ? `${one.slice(0, 77)}...` : one;
36
+ };
37
+ var rule = {
38
+ id: "general/no-dynamic-code-eval",
39
+ version: 1,
40
+ kind: "static-ts",
41
+ title: "Kh\xF4ng \u0111\xE1nh gi\xE1 chu\u1ED7i \u0111\u1ED9ng th\xE0nh m\xE3 (eval / new Function)",
42
+ description: "Ph\xE1t hi\u1EC7n eval(x) v\xE0 new Function(..., x) khi x kh\xF4ng ph\u1EA3i chu\u1ED7i h\u1EB1ng (CWE-95). N\u1EBFu chu\u1ED7i l\u1EA5y t\u1EEB server, c\u1EA5u h\xECnh ho\u1EB7c ng\u01B0\u1EDDi d\xF9ng, ai ki\u1EC3m so\xE1t \u0111\u01B0\u1EE3c chu\u1ED7i \u0111\xF3 s\u1EBD ch\u1EA1y \u0111\u01B0\u1EE3c JavaScript tr\xEAn tr\xECnh duy\u1EC7t c\u1EE7a m\u1ECDi ng\u01B0\u1EDDi d\xF9ng.",
43
+ severity: "warning",
44
+ category: "security",
45
+ languages: ["typescript", "javascript"],
46
+ scope: "general",
47
+ requires: "syntactic",
48
+ usesParser: false,
49
+ baseConfidence: 70,
50
+ check(ctx) {
51
+ if (isThirdPartyAsset(ctx.file.path, ctx.file.content)) return [];
52
+ const content = maskJsComments(ctx.file.content);
53
+ const findings = [];
54
+ const report = (index, api, arg) => {
55
+ const wrap = WRAP_PAREN_RE.test(arg);
56
+ findings.push({
57
+ file: ctx.file.path,
58
+ range: { line: lineOf(content, index), column: 1 },
59
+ confidence: 70,
60
+ message: wrap ? `${api} d\u1EF1ng object/h\xE0m t\u1EEB chu\u1ED7i \u0111\u1ED9ng \`${shorten(arg)}\` (idiom \`'(' + x + ')'\`). N\u1EBFu chu\u1ED7i l\u1EA5y t\u1EEB server ho\u1EB7c c\u1EA5u h\xECnh, ai ghi \u0111\u01B0\u1EE3c n\xF3 s\u1EBD ch\u1EA1y \u0111\u01B0\u1EE3c JavaScript tr\xEAn tr\xECnh duy\u1EC7t ng\u01B0\u1EDDi d\xF9ng (CWE-95).` : `${api} \u0111\xE1nh gi\xE1 chu\u1ED7i \u0111\u1ED9ng \`${shorten(arg)}\` th\xE0nh m\xE3 (CWE-95). N\u1EBFu chu\u1ED7i c\xF3 ngu\u1ED3n ngo\xE0i m\xE3 ngu\u1ED3n, \u0111\xE2y l\xE0 \u0111i\u1EC3m ch\xE8n m\xE3.`,
61
+ suggestion: wrap ? "D\u1EEF li\u1EC7u th\xEC d\xF9ng JSON.parse; h\xE0nh vi (h\xE0m created/methods, c\xF4ng th\u1EE9c) th\xEC ch\u1ECDn t\u1EEB m\u1ED9t b\u1EA3ng h\xE0m \u0111\u1ECBnh s\u1EB5n theo t\xEAn, kh\xF4ng \u0111\xE1nh gi\xE1 m\xE3 l\u1EA5y t\u1EEB server." : "B\u1ECF eval/new Function: d\xF9ng JSON.parse cho d\u1EEF li\u1EC7u, m\u1ED9t b\u1EA3ng h\xE0m \u0111\u1ECBnh s\u1EB5n cho h\xE0nh vi, ho\u1EB7c new RegExp(escape(x)) cho bi\u1EC3u th\u1EE9c ch\xEDnh quy."
62
+ });
63
+ };
64
+ EVAL_CALL_RE.lastIndex = 0;
65
+ for (const m of content.matchAll(EVAL_CALL_RE)) {
66
+ const args = callArguments(content, m.index + m[0].length - 1);
67
+ const first = args?.[0];
68
+ if (first === void 0 || STRING_CONSTANT_RE.test(first)) continue;
69
+ report(m.index, "eval()", first);
70
+ }
71
+ NEW_FUNCTION_RE.lastIndex = 0;
72
+ for (const m of content.matchAll(NEW_FUNCTION_RE)) {
73
+ const args = callArguments(content, m.index + m[0].length - 1);
74
+ const body = args?.[args.length - 1];
75
+ if (body === void 0 || STRING_CONSTANT_RE.test(body)) continue;
76
+ report(m.index, "new Function()", body);
77
+ }
78
+ return findings.sort((a, b) => a.range.line - b.range.line);
79
+ }
80
+ };
81
+
82
+ export { rule };
83
+ //# sourceMappingURL=no-dynamic-code-eval.rule.js.map
84
+ //# sourceMappingURL=no-dynamic-code-eval.rule.js.map
@@ -1,3 +1,5 @@
1
+ import { maskJavaComments, maskJsComments } from '@code-sentinel/parsers';
2
+
1
3
  // builtin-rules/static/general/no-hardcoded-secret.rule.ts
2
4
  var PROVIDER_PATTERNS = [
3
5
  // ---- AWS ----
@@ -345,18 +347,34 @@ var GENERIC_PATTERNS = [
345
347
  var CONFIG_SECRET_PATTERNS = [
346
348
  {
347
349
  name: "config-secret-assignment",
348
- regex: /^\s*(?:[-\w.]+\.)?(?:password|passwd|pwd|secret|client[_-]?secret|api[_-]?key|apikey|access[_-]?token|auth[_-]?token)\s*[:=]\s*([^\s#'"][^\r\n#]*)/gim,
350
+ regex: /^[\t ]*(?:export[\t ]+)?[\w.-]*?(?:password|passwd|pwd|secret|api[_-]?key|access[_-]?token|auth[_-]?token)[\t ]*[:=][\t ]*["']?([^"'\r\n#]+)["']?/gim,
349
351
  confidence: 75,
350
352
  message: "Config file secret value detected.",
351
353
  payloadGroup: 1
352
354
  },
353
355
  {
354
356
  name: "config-empty-password",
355
- regex: /^\s*(?:[-\w.]+\.)?(?:password|passwd|pwd)\s*[:=]\s*(?:["']\s*["']\s*$|\s*$)/gim,
357
+ regex: /^[\t ]*[\w.-]*?(?:password|passwd|pwd)[\t ]*[:=][\t ]*(?:["'][\t ]*["']|null|~)?[\t ]*$/gim,
356
358
  confidence: 85,
357
359
  message: "Empty password in configuration file (CWE-258 / CWE-798)."
358
360
  }
359
361
  ];
362
+ var HTTP_URL_SECRET_PATTERN = {
363
+ name: "http-url-credentials",
364
+ regex: /\bhttps?:\/\/[^\s:/@'"<>]+:([^\s/@'"<>]+)@[^\s'"<>]+/gi,
365
+ confidence: 75,
366
+ message: "Inline credential in an HTTP/HTTPS URL detected.",
367
+ payloadGroup: 1
368
+ };
369
+ var XML_SECRET_PATTERNS = [
370
+ {
371
+ name: "xml-secret-element",
372
+ regex: /<([\w.-]*?(?:password|passwd|pwd|secret|api[_-]?key|access[_-]?token))\b[^>]*>([^<\r\n]+)<\/\1[\t ]*>/gi,
373
+ confidence: 75,
374
+ message: "Plaintext credential in XML configuration detected.",
375
+ payloadGroup: 2
376
+ }
377
+ ];
360
378
  var BUILTIN_PATTERNS = [
361
379
  ...PROVIDER_PATTERNS,
362
380
  ...PEM_PATTERNS,
@@ -419,9 +437,35 @@ var isFieldNameEcho = (payload) => FIELD_NAME_ECHOES.includes(payload.toLowerCas
419
437
  var looksExternalized = (payload) => {
420
438
  const trimmed = payload.trim();
421
439
  const lower = trimmed.toLowerCase();
422
- return trimmed.startsWith("${") || lower.startsWith("enc(") || lower.startsWith("{cipher}") || lower.startsWith("vault://") || lower.startsWith("optional:vault://");
440
+ return trimmed.startsWith("${") || /^\$[A-Z_][A-Z0-9_]*$/i.test(trimmed) || lower.startsWith("enc(") || lower.startsWith("{cipher}") || lower.startsWith("vault://") || lower.startsWith("optional:vault://");
423
441
  };
424
442
  var isConfigLanguage = (language) => language === "yaml" || language === "text" || language === "shell";
443
+ var maskConfigComments = (content) => content.split("\n").map((line) => {
444
+ let quote = "";
445
+ for (let i = 0; i < line.length; i++) {
446
+ const char = line[i];
447
+ if (quote) {
448
+ if (char === "\\" && quote === '"') {
449
+ i++;
450
+ continue;
451
+ }
452
+ if (char === quote) quote = "";
453
+ } else if (char === '"' || char === "'") {
454
+ quote = char;
455
+ } else if (char === "#" && (i === 0 || /[\t ]/.test(line[i - 1] ?? ""))) {
456
+ return line.slice(0, i) + " ".repeat(line.length - i);
457
+ }
458
+ }
459
+ return line;
460
+ }).join("\n");
461
+ var maskSecretComments = (content, language) => {
462
+ if (language === "java") return maskJavaComments(content);
463
+ if (language === "typescript" || language === "javascript") return maskJsComments(content);
464
+ if (language === "xml") {
465
+ return content.replace(/<!--[\s\S]*?(?:-->|$)/g, (comment) => comment.replace(/[^\r\n]/g, " "));
466
+ }
467
+ return isConfigLanguage(language) ? maskConfigComments(content) : content;
468
+ };
425
469
  var lineColAt = (content, offset) => {
426
470
  let line = 1;
427
471
  let lastNl = -1;
@@ -458,12 +502,111 @@ var compileExtra = (extras, logger) => {
458
502
  }
459
503
  return out;
460
504
  };
505
+ var PASSWORD_SINK_CALL_RE = /\b(?:setPassword|updatePassword|changePassword|resetPassword|withPassword|setNewPassword|addUser|addUserWithWorkflow)\s*\(/g;
506
+ var POSITIONAL_PASSWORD_SINKS = /* @__PURE__ */ new Map([
507
+ ["addUser", [3, 4]],
508
+ ["addUserWithWorkflow", [3, 4]]
509
+ ]);
510
+ var LIFERAY_ADD_USER_MIN_ARGS = 10;
511
+ var MIN_SINK_PASSWORD_LENGTH = 4;
512
+ var callArguments = (content, open) => {
513
+ const args = [];
514
+ let depth = 0;
515
+ let start = open + 1;
516
+ let quote = null;
517
+ for (let i = open; i < content.length; i++) {
518
+ const ch = content[i];
519
+ if (quote) {
520
+ if (ch === "\\") i++;
521
+ else if (ch === quote) quote = null;
522
+ continue;
523
+ }
524
+ if (ch === '"' || ch === "'") quote = ch;
525
+ else if (ch === "(") depth++;
526
+ else if (ch === ")") {
527
+ depth--;
528
+ if (depth === 0) {
529
+ args.push(content.slice(start, i));
530
+ return args;
531
+ }
532
+ } else if (ch === "," && depth === 1) {
533
+ args.push(content.slice(start, i));
534
+ start = i + 1;
535
+ } else if (ch === ";" && depth === 1) return null;
536
+ }
537
+ return null;
538
+ };
539
+ var acceptableSinkPassword = (value) => value.trim().length >= MIN_SINK_PASSWORD_LENGTH && // A mask like "******" is a display value, not a password (measured: tcct-be-base portal).
540
+ !/^(.)\1+$/.test(value) && !looksLikePlaceholder(value) && !isFieldNameEcho(value) && !looksExternalized(value);
541
+ var findPasswordSinkLiterals = (content) => {
542
+ const out = [];
543
+ PASSWORD_SINK_CALL_RE.lastIndex = 0;
544
+ let call;
545
+ while ((call = PASSWORD_SINK_CALL_RE.exec(content)) !== null) {
546
+ const open = call.index + call[0].length - 1;
547
+ const allArgs = callArguments(content, open);
548
+ if (!allArgs) continue;
549
+ const name = /^\w+/.exec(call[0])?.[0] ?? "";
550
+ const positions = POSITIONAL_PASSWORD_SINKS.get(name);
551
+ let args = allArgs;
552
+ if (positions) {
553
+ if (allArgs.length < LIFERAY_ADD_USER_MIN_ARGS) continue;
554
+ args = positions.map((i) => allArgs[i] ?? "");
555
+ }
556
+ const seen = /* @__PURE__ */ new Set();
557
+ for (const raw of args) {
558
+ const arg = raw.trim();
559
+ const literal = /^["']([^"'\\]*)["']$/.exec(arg)?.[1];
560
+ if (literal !== void 0) {
561
+ if (acceptableSinkPassword(literal) && !seen.has(literal)) {
562
+ seen.add(literal);
563
+ out.push({ offset: call.index, value: literal, via: null });
564
+ }
565
+ continue;
566
+ }
567
+ if (!/^[A-Za-z_$][\w$]*$/.test(arg)) continue;
568
+ const escaped = arg.replace(/\$/g, "\\$");
569
+ const assignRe = new RegExp(`\\b${escaped}\\s*=\\s*["']([^"'\\\\\\n]*)["']\\s*;`, "g");
570
+ let assign;
571
+ let nearest = null;
572
+ while ((assign = assignRe.exec(content)) !== null && assign.index < call.index) {
573
+ nearest = assign;
574
+ }
575
+ const value = nearest?.[1];
576
+ if (nearest && value !== void 0 && acceptableSinkPassword(value) && !seen.has(value)) {
577
+ seen.add(value);
578
+ out.push({ offset: nearest.index, value, via: arg });
579
+ }
580
+ }
581
+ }
582
+ return out;
583
+ };
461
584
  var isOwnTestFile = (filePath) => {
462
585
  const basename = filePath.split(/[/\\]/).pop() ?? filePath;
463
586
  return basename === "no-hardcoded-secret.test.ts" || basename === "no-hardcoded-secret.rule.ts";
464
587
  };
588
+ var EMPTY_PASSWORD_PATTERNS = /* @__PURE__ */ new Set([
589
+ "empty-password-assignment",
590
+ "empty-password-method-call"
591
+ ]);
465
592
  var rule = {
466
593
  id: "general/no-hardcoded-secret",
594
+ // v11: skip the EMPTY-password patterns in a Vue SFC ([ADR-0093]). A `.vue` component only ever
595
+ // runs in the browser, so `passWord: ''` in its `data()` is a form field being reset, never a
596
+ // credential a server authenticates with. Measured on mcdt_bqp: 54 of 54 hits were exactly that
597
+ // idiom, all at severity error (CI-blocking), while the same frontend's .js files had 0.
598
+ // Non-empty literals still fire — a real password committed in client code is still a leak.
599
+ // v10: MERGE of two independent lines of work. The password-literal-to-setter patterns (a
600
+ // literal reaching setPassword/updatePassword/... directly or via one local assignment,
601
+ // regardless of name or length — mcdt_bqp SR BUG-52784) were authored as "v6" on a branch while
602
+ // v6-v9 below shipped on main, so the number is taken fresh rather than reused.
603
+ // v9: ignore comments across source/config languages, preserving finding positions.
604
+ // v8: HTTP URL credentials, including comments and literal default passwords.
605
+ // v7: scan committed credentials in comments; optional encrypted-value review.
606
+ // v6: prefixed/short config credentials, XML elements, comment-aware empty passwords.
607
+ // v9: ignore comments across source/config languages, preserving finding positions.
608
+ // v8: HTTP URL credentials, including comments and literal default passwords.
609
+ // v7: scan committed credentials in comments; optional encrypted-value review.
467
610
  // v5: added empty-password-assignment and config-empty-password patterns (CWE-258/798).
468
611
  // v4: source-only execution + YAML/text support for Spring Boot application
469
612
  // config files. `.properties` is classified as `text`.
@@ -472,31 +615,37 @@ var rule = {
472
615
  // v2 (1.2.1): added FIELD_NAME_ECHOES filter for enum-value / label-dict
473
616
  // FPs (e.g. `PASSWORD = 'password'`). Bumped so the rule cache invalidates
474
617
  // stale v1 findings — Phase 9 cache key is (id, version, file.hash).
475
- version: 5,
618
+ version: 11,
476
619
  kind: "static-ts",
477
620
  title: "Kh\xF4ng hardcode secrets / API keys / private keys v\xE0o source",
478
621
  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.",
479
622
  severity: "error",
480
623
  category: "security",
481
624
  // Pure content scan: can run on YAML and text-classified config files.
482
- languages: ["typescript", "javascript", "java", "yaml", "text", "shell"],
625
+ languages: ["typescript", "javascript", "java", "xml", "yaml", "text", "shell"],
483
626
  scope: "general",
484
627
  usesParser: false,
485
628
  baseConfidence: 80,
486
629
  defaultOptions: {
487
630
  disabledPatterns: [],
488
- extraPatterns: []
631
+ extraPatterns: [],
632
+ inspectEncryptedValues: false
489
633
  },
490
634
  check(ctx) {
491
635
  if (isOwnTestFile(ctx.file.path)) return [];
492
636
  const disabled = new Set(ctx.options.disabledPatterns);
493
637
  const extras = compileExtra(ctx.options.extraPatterns, ctx.logger);
638
+ const clientOnly = ctx.file.path.toLowerCase().endsWith(".vue");
494
639
  const patterns = [
495
- ...BUILTIN_PATTERNS.filter((p) => !disabled.has(p.name)),
640
+ ...BUILTIN_PATTERNS.filter(
641
+ (p) => !disabled.has(p.name) && !(clientOnly && EMPTY_PASSWORD_PATTERNS.has(p.name))
642
+ ),
643
+ ...!disabled.has(HTTP_URL_SECRET_PATTERN.name) ? [HTTP_URL_SECRET_PATTERN] : [],
496
644
  ...isConfigLanguage(ctx.file.language) ? CONFIG_SECRET_PATTERNS.filter((p) => !disabled.has(p.name)) : [],
645
+ ...ctx.file.language === "xml" ? XML_SECRET_PATTERNS.filter((p) => !disabled.has(p.name)) : [],
497
646
  ...extras
498
647
  ];
499
- const content = ctx.file.content;
648
+ const content = maskSecretComments(ctx.file.content, ctx.file.language);
500
649
  const findings = [];
501
650
  const reportedRanges = [];
502
651
  const overlapsReported = (start, end) => {
@@ -507,26 +656,43 @@ var rule = {
507
656
  };
508
657
  for (const pattern of patterns) {
509
658
  pattern.regex.lastIndex = 0;
510
- let match;
511
- while ((match = pattern.regex.exec(content)) !== null) {
659
+ for (const match of content.matchAll(pattern.regex)) {
512
660
  const matchStart = match.index;
513
661
  const matchEnd = matchStart + match[0].length;
514
662
  if (overlapsReported(matchStart, matchEnd)) continue;
515
663
  const payload = pattern.payloadGroup !== void 0 ? match[pattern.payloadGroup] : match[0];
516
- if (payload && (looksLikePlaceholder(payload) || isFieldNameEcho(payload) || looksExternalized(payload) || pattern.name === "config-secret-assignment" && payload.trim().length < 8)) {
664
+ const encrypted = payload !== void 0 && /^(?:ENC\(|\{cipher\})/i.test(payload.trim());
665
+ if (payload && (looksLikePlaceholder(payload) || isFieldNameEcho(payload) && pattern.name.startsWith("generic-") || looksExternalized(payload) && !(encrypted && ctx.options.inspectEncryptedValues) || pattern.name === "config-secret-assignment" && /^(?:true|false|null|~)?$/i.test(payload.trim()))) {
517
666
  continue;
518
667
  }
519
668
  const { line, column } = lineColAt(content, matchStart);
520
669
  findings.push({
521
- message: `${pattern.message} [pattern=${pattern.name}]`,
670
+ message: encrypted ? "Encrypted credential committed; review master-key separation and decryptability, not plaintext exposure. [control=encrypted-credential]" : `${pattern.message} [pattern=${pattern.name}]`,
522
671
  file: ctx.file.path,
523
672
  range: { line, column },
524
- confidence: pattern.confidence,
673
+ confidence: encrypted ? 60 : pattern.confidence,
674
+ ...encrypted ? { severity: "warning" } : {},
525
675
  suggestion: "Move the secret to an environment variable (vd `process.env.X`) v\xE0 rotate gi\xE1 tr\u1ECB \u0111\xE3 commit ngay. Th\xEAm `.env` v\xE0o `.gitignore`. N\u1EBFu l\xE0 test fixture, \u0111\u1EB7t file v\xE0o path \u0111\xE3 exclude ho\u1EB7c d\xF9ng `// code-sentinel-disable-next-line general/no-hardcoded-secret`."
526
676
  });
527
677
  reportedRanges.push({ start: matchStart, end: matchEnd });
528
678
  }
529
679
  }
680
+ if (!disabled.has("password-literal-to-setter") && !isConfigLanguage(ctx.file.language)) {
681
+ const masked = ctx.file.language === "java" ? maskJavaComments(content) : maskJsComments(content);
682
+ for (const hit of findPasswordSinkLiterals(masked)) {
683
+ const end = hit.offset + 1;
684
+ if (overlapsReported(hit.offset, end)) continue;
685
+ const { line, column } = lineColAt(content, hit.offset);
686
+ findings.push({
687
+ message: `${hit.via === null ? "Hard-coded password literal passed to a password-setting API" : `Hard-coded password literal assigned to \`${hit.via}\` and passed to a password-setting API`} (CWE-798 / CWE-259). [pattern=password-literal-to-setter]`,
688
+ file: ctx.file.path,
689
+ range: { line, column },
690
+ confidence: 85,
691
+ suggestion: "Kh\xF4ng \u0111\u1EB7t m\u1EADt kh\u1EA9u m\u1EB7c \u0111\u1ECBnh c\u1ED1 \u0111\u1ECBnh trong m\xE3: sinh m\u1EADt kh\u1EA9u ng\u1EABu nhi\xEAn (SecureRandom) v\xE0 bu\u1ED9c \u0111\u1ED5i \u1EDF l\u1EA7n \u0111\u0103ng nh\u1EADp \u0111\u1EA7u, ho\u1EB7c \u0111\u1ECDc t\u1EEB c\u1EA5u h\xECnh b\xED m\u1EADt. Rotate m\u1ECDi t\xE0i kho\u1EA3n \u0111\xE3 \u0111\u01B0\u1EE3c \u0111\u1EB7t gi\xE1 tr\u1ECB n\xE0y."
692
+ });
693
+ reportedRanges.push({ start: hit.offset, end });
694
+ }
695
+ }
530
696
  return findings;
531
697
  }
532
698
  };
@@ -1,15 +1,19 @@
1
1
  // builtin-rules/static/general/no-open-redirect.rule.ts
2
2
  var OPEN_REDIRECT_SINK_IDS = /* @__PURE__ */ new Set([
3
3
  "general/location-redirect",
4
- "angular/router-navigate"
4
+ "angular/router-navigate",
5
+ "angular/location-assign-replace",
6
+ "angular/window-open"
5
7
  ]);
6
8
  var SINK_LABEL = {
7
9
  "general/location-redirect": "location.href / window.location",
8
- "angular/router-navigate": "Router.navigateByUrl"
10
+ "angular/router-navigate": "Router.navigateByUrl",
11
+ "angular/location-assign-replace": "location.assign / replace",
12
+ "angular/window-open": "window.open"
9
13
  };
10
14
  var rule = {
11
15
  id: "general/no-open-redirect",
12
- version: 1,
16
+ version: 2,
13
17
  kind: "static-ts",
14
18
  title: "Kh\xF4ng \u0111i\u1EC1u h\u01B0\u1EDBng t\u1EDBi URL ch\u01B0a ki\u1EC3m so\xE1t (location.href / window.location / Router.navigateByUrl)",
15
19
  description: "D\u1EEF li\u1EC7u t\u1EEB URL/ng\u01B0\u1EDDi d\xF9ng (query params, ActivatedRoute, location.*, document.referrer, \u2026) ch\u1EA3y th\u1EB3ng v\xE0o \u0111\xEDch \u0111i\u1EC1u h\u01B0\u1EDBng (g\xE1n `location.href` / `window.location`, ho\u1EB7c `Router.navigateByUrl(...)`) m\xE0 kh\xF4ng ki\u1EC3m tra l\xE0 l\u1ED7 h\u1ED5ng Open Redirect \u2014 k\u1EBB t\u1EA5n c\xF4ng c\xF3 th\u1EC3 l\u1EEBa ng\u01B0\u1EDDi d\xF9ng chuy\u1EC3n sang site l\u1EEBa \u0111\u1EA3o. Rule d\xF9ng taint analysis (Tier-2 li\xEAn h\xE0m/li\xEAn file) \u0111\u1EC3 truy v\u1EBFt lu\u1ED3ng d\u1EEF li\u1EC7u. Kh\u1EAFc ph\u1EE5c: ki\u1EC3m tra URL v\u1EDBi allow-list (ch\u1EC9 cho ph\xE9p \u0111\u01B0\u1EDDng d\u1EABn n\u1ED9i b\u1ED9 / host tin c\u1EADy) tr\u01B0\u1EDBc khi \u0111i\u1EC1u h\u01B0\u1EDBng.",
@@ -1,4 +1,4 @@
1
- import { maskJsComments } from '@code-sentinel/parsers';
1
+ import { isThirdPartyAsset, maskJsComments } from '@code-sentinel/parsers';
2
2
 
3
3
  // builtin-rules/static/general/no-unsafe-html-sink.rule.ts
4
4
  var JQUERY_HTML_RE = /(?:\$|jQuery)\s*\([^\n)]{1,240}\)\s*\.\s*html\s*\(\s*([^;\n)]{1,240})\s*\)/g;
@@ -13,6 +13,20 @@ var isSafeStaticValue = (value) => {
13
13
  const trimmed = value.trim();
14
14
  return STATIC_LITERAL_RE.test(trimmed) || ENCODED_VALUE_RE.test(trimmed);
15
15
  };
16
+ var statementRhs = (content, start) => {
17
+ for (let i = start; i < content.length; i++) {
18
+ const ch = content[i];
19
+ if (ch === "'" || ch === '"' || ch === "`") {
20
+ for (i++; i < content.length && content[i] !== ch; i++) {
21
+ if (content[i] === "\\") i++;
22
+ else if (content[i] === "\n" && ch !== "`") return null;
23
+ }
24
+ continue;
25
+ }
26
+ if (ch === ";" || ch === "\n") return content.slice(start, i).trim();
27
+ }
28
+ return content.slice(start).trim();
29
+ };
16
30
  var matches = (content) => {
17
31
  const found = [];
18
32
  const add = (api, value, index) => {
@@ -22,8 +36,12 @@ var matches = (content) => {
22
36
  JQUERY_HTML_RE.lastIndex = 0;
23
37
  for (const match of content.matchAll(JQUERY_HTML_RE)) add("jQuery.html()", match[1], match.index);
24
38
  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);
39
+ for (const match of content.matchAll(INNER_HTML_RE)) {
40
+ const valueStart = match.index + match[0].length - (match[2]?.length ?? 0);
41
+ const whole = statementRhs(content, valueStart);
42
+ const value = whole !== null && isSafeStaticValue(whole) ? whole : match[2];
43
+ add(`${match[1] ?? "innerHTML"} assignment`, value, match.index);
44
+ }
27
45
  INSERT_ADJACENT_HTML_RE.lastIndex = 0;
28
46
  for (const match of content.matchAll(INSERT_ADJACENT_HTML_RE))
29
47
  add("insertAdjacentHTML()", match[1], match.index);
@@ -32,12 +50,32 @@ var matches = (content) => {
32
50
  add(`document.${match[1] ?? "write"}()`, match[2], match.index);
33
51
  return found.sort((a, b) => a.index - b.index);
34
52
  };
53
+ var V_HTML_RE = /\bv-html\s*=\s*(?:"([^"]*)"|'([^']*)')/g;
54
+ var QUOTED = String.raw`(?:'(?:[^'\\]|\\.)*'|"(?:[^"\\]|\\.)*"|\x60[^\x60$]*\x60)`;
55
+ var LITERAL_TERNARY_RE = new RegExp(String.raw`^[^?]+\?\s*${QUOTED}\s*:\s*${QUOTED}$`);
56
+ var LITERAL_RE = new RegExp(`^${QUOTED}$`);
57
+ var VUE_SAFE_RE = /sanitiz|dompurify|escapehtml|htmlencode|encodehtml|&lt;|^\$t\(|^\$i18n\b/i;
58
+ var isSafeVHtmlValue = (value) => {
59
+ const v = value.trim();
60
+ return v === "" || LITERAL_RE.test(v) || LITERAL_TERNARY_RE.test(v) || VUE_SAFE_RE.test(v);
61
+ };
62
+ var vHtmlMatches = (template) => {
63
+ const masked = template.replace(HTML_COMMENT_RE, (comment) => comment.replace(/[^\n]/g, " "));
64
+ const found = [];
65
+ V_HTML_RE.lastIndex = 0;
66
+ for (const match of masked.matchAll(V_HTML_RE)) {
67
+ const value = match[1] ?? match[2] ?? "";
68
+ if (isSafeVHtmlValue(value)) continue;
69
+ found.push({ api: "v-html", value: value.trim(), index: match.index });
70
+ }
71
+ return found;
72
+ };
35
73
  var rule = {
36
74
  id: "general/no-unsafe-html-sink",
37
- version: 1,
75
+ version: 4,
38
76
  kind: "static-ts",
39
77
  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.",
78
+ description: "Ph\xE1t hi\u1EC7n jQuery.html(), innerHTML/outerHTML, insertAdjacentHTML(), document.write() v\xE0 v-html c\u1EE7a Vue 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
79
  severity: "warning",
42
80
  category: "security",
43
81
  languages: ["typescript", "javascript", "html"],
@@ -46,16 +84,21 @@ var rule = {
46
84
  usesParser: false,
47
85
  baseConfidence: 80,
48
86
  check(ctx) {
87
+ if (isThirdPartyAsset(ctx.file.path, ctx.file.content)) return [];
49
88
  const content = maskJsComments(ctx.file.content).replace(
50
89
  HTML_COMMENT_RE,
51
90
  (comment) => comment.replace(/[^\n]/g, " ")
52
91
  );
53
- return matches(content).map((match) => ({
92
+ const template = ctx.file.vueTemplate;
93
+ const all = [...matches(content), ...template ? vHtmlMatches(template) : []].sort(
94
+ (a, b) => a.index - b.index
95
+ );
96
+ return all.map((match) => ({
54
97
  file: ctx.file.path,
55
98
  range: { line: lineOf(content, match.index), column: 1 },
56
99
  confidence: 80,
57
100
  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."
101
+ suggestion: (match.api === "v-html" ? "D\xF9ng n\u1ED9i suy {{ }} c\u1EE7a Vue (t\u1EF1 escape) \u0111\u1EC3 hi\u1EC3n th\u1ECB text." : "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
102
  }));
60
103
  }
61
104
  };
@@ -0,0 +1,90 @@
1
+ import { parseAllDocuments } from 'yaml';
2
+
3
+ // builtin-rules/static/general/infrastructure-config-audit.ts
4
+ var record = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : null;
5
+ var list = (value) => Array.isArray(value) ? value : [];
6
+ var auditInfrastructureConfig = (content) => {
7
+ const signals = [];
8
+ for (const doc of parseAllDocuments(content)) {
9
+ if (doc.errors.length) continue;
10
+ let root;
11
+ try {
12
+ root = record(doc.toJS());
13
+ } catch {
14
+ continue;
15
+ }
16
+ if (!root) continue;
17
+ const line = content.slice(0, doc.range?.[0] ?? 0).split("\n").length;
18
+ const spec = record(root.spec);
19
+ const workload = ["Deployment", "StatefulSet", "DaemonSet", "Job", "ReplicaSet"].includes(
20
+ String(root.kind)
21
+ );
22
+ const pod = root.kind === "Pod" ? spec : workload ? record(record(spec?.template)?.spec) : root.kind === "CronJob" ? record(record(record(record(spec?.jobTemplate)?.spec)?.template)?.spec) : null;
23
+ if (pod && list(pod.containers).length) {
24
+ const podProfile = record(record(pod.securityContext)?.seccompProfile);
25
+ const unconstrained = [...list(pod.containers), ...list(pod.initContainers)].some(
26
+ (container) => {
27
+ const profile = record(record(record(container)?.securityContext)?.seccompProfile) ?? podProfile;
28
+ return !(profile?.type === "RuntimeDefault" || profile?.type === "Localhost" && typeof profile.localhostProfile === "string" && profile.localhostProfile.length > 0);
29
+ }
30
+ );
31
+ if (unconstrained) signals.push({ line, control: "k8s-seccomp" });
32
+ if (pod.automountServiceAccountToken !== false)
33
+ signals.push({ line, control: "k8s-token-automount" });
34
+ }
35
+ if (typeof root.openapi === "string") {
36
+ const paths = record(root.paths);
37
+ let exposed = false;
38
+ for (const path of Object.values(paths ?? {})) {
39
+ const pathItem = record(path);
40
+ for (const method of [
41
+ "get",
42
+ "post",
43
+ "put",
44
+ "patch",
45
+ "delete",
46
+ "head",
47
+ "options",
48
+ "trace"
49
+ ]) {
50
+ const operation = record(pathItem?.[method]);
51
+ if (!operation) continue;
52
+ const security = operation.security ?? root.security;
53
+ const authenticated = list(security).some(
54
+ (entry) => Object.keys(record(entry) ?? {}).length > 0
55
+ );
56
+ const servers = operation.servers ?? pathItem?.servers ?? root.servers;
57
+ if (authenticated && list(servers).some((server) => /^http:\/\//i.test(String(record(server)?.url ?? ""))))
58
+ exposed = true;
59
+ }
60
+ }
61
+ if (exposed) signals.push({ line, control: "openapi-http-credentials" });
62
+ }
63
+ }
64
+ return signals;
65
+ };
66
+
67
+ // builtin-rules/static/general/openapi-https-credentials.rule.ts
68
+ var rule = {
69
+ id: "general/openapi-https-credentials",
70
+ version: 1,
71
+ kind: "static-ts",
72
+ title: "OpenAPI trao \u0111\u1ED5i credential qua HTTPS",
73
+ severity: "warning",
74
+ category: "security",
75
+ languages: ["yaml"],
76
+ scope: "general",
77
+ usesParser: false,
78
+ baseConfidence: 80,
79
+ check: (ctx) => auditInfrastructureConfig(ctx.file.content).filter((signal) => signal.control === "openapi-http-credentials").map((signal) => ({
80
+ file: ctx.file.path,
81
+ range: { line: signal.line, column: 1 },
82
+ confidence: 80,
83
+ message: "An authenticated OpenAPI operation inherits or declares an HTTP server. This is a source contract finding, not proof of deployed transport. [control=openapi-http-credentials]",
84
+ suggestion: "Use HTTPS for credential-bearing operations and verify effective operation/path/global servers and security overrides."
85
+ }))
86
+ };
87
+
88
+ export { rule };
89
+ //# sourceMappingURL=openapi-https-credentials.rule.js.map
90
+ //# sourceMappingURL=openapi-https-credentials.rule.js.map