@code-sentinel-cli/code-sentinel-cli 3.0.3 → 3.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +1 -1
  2. package/dist/bin.js +1184 -809
  3. package/dist/builtin-rules/ai/angular/api-service-contract-risk.prompt.md +71 -0
  4. package/dist/builtin-rules/ai/angular/api-service-contract-risk.rule.yaml +22 -0
  5. package/dist/builtin-rules/ai/angular/component-state-flow.prompt.md +79 -0
  6. package/dist/builtin-rules/ai/angular/component-state-flow.rule.yaml +26 -0
  7. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.prompt.md +70 -0
  8. package/dist/builtin-rules/ai/angular/cross-feature-api-drift.rule.yaml +42 -0
  9. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.prompt.md +73 -0
  10. package/dist/builtin-rules/ai/angular/cross-feature-route-permission-drift.rule.yaml +50 -0
  11. package/dist/builtin-rules/ai/angular/reactive-form-flow.prompt.md +82 -0
  12. package/dist/builtin-rules/ai/angular/reactive-form-flow.rule.yaml +23 -0
  13. package/dist/builtin-rules/ai/angular/route-permission-flow.prompt.md +80 -0
  14. package/dist/builtin-rules/ai/angular/route-permission-flow.rule.yaml +23 -0
  15. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.prompt.md +82 -0
  16. package/dist/builtin-rules/ai/angular/rxjs-flow-risk.rule.yaml +24 -0
  17. package/dist/builtin-rules/ai/angular/template-contract-risk.prompt.md +80 -0
  18. package/dist/builtin-rules/ai/angular/template-contract-risk.rule.yaml +25 -0
  19. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.prompt.md +55 -0
  20. package/dist/builtin-rules/ai/flutter/dynamic-content-risk.rule.yaml +18 -0
  21. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.prompt.md +58 -0
  22. package/dist/builtin-rules/ai/flutter/feature-state-flow-risk.rule.yaml +18 -0
  23. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.prompt.md +56 -0
  24. package/dist/builtin-rules/ai/flutter/native-platform-consistency-risk.rule.yaml +18 -0
  25. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.prompt.md +57 -0
  26. package/dist/builtin-rules/ai/flutter/network-auth-flow-risk.rule.yaml +19 -0
  27. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.prompt.md +60 -0
  28. package/dist/builtin-rules/ai/flutter/ui-responsive-accessibility-risk.rule.yaml +18 -0
  29. package/dist/builtin-rules/ai/general/code-clarity.prompt.md +57 -0
  30. package/dist/builtin-rules/ai/general/code-clarity.rule.yaml +20 -0
  31. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.prompt.md +86 -0
  32. package/dist/builtin-rules/ai/spring-boot/business-invariant-risk.rule.yaml +25 -0
  33. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.prompt.md +80 -0
  34. package/dist/builtin-rules/ai/spring-boot/cache-consistency-risk.rule.yaml +25 -0
  35. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.prompt.md +76 -0
  36. package/dist/builtin-rules/ai/spring-boot/cross-feature-error-handling-drift.rule.yaml +63 -0
  37. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.prompt.md +85 -0
  38. package/dist/builtin-rules/ai/spring-boot/cross-feature-transaction-boundary-drift.rule.yaml +68 -0
  39. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.prompt.md +121 -0
  40. package/dist/builtin-rules/ai/spring-boot/error-handling-completeness.rule.yaml +84 -0
  41. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.prompt.md +80 -0
  42. package/dist/builtin-rules/ai/spring-boot/event-publishing-risk.rule.yaml +25 -0
  43. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.prompt.md +78 -0
  44. package/dist/builtin-rules/ai/spring-boot/io-boundary-risk.rule.yaml +25 -0
  45. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.prompt.md +83 -0
  46. package/dist/builtin-rules/ai/spring-boot/ownership-scope-risk.rule.yaml +25 -0
  47. package/dist/builtin-rules/ai/spring-boot/pagination-risk.prompt.md +81 -0
  48. package/dist/builtin-rules/ai/spring-boot/pagination-risk.rule.yaml +25 -0
  49. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.prompt.md +75 -0
  50. package/dist/builtin-rules/ai/spring-boot/security-authorization-risk.rule.yaml +26 -0
  51. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.prompt.md +75 -0
  52. package/dist/builtin-rules/ai/spring-boot/security-mass-assignment-risk.rule.yaml +24 -0
  53. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.prompt.md +74 -0
  54. package/dist/builtin-rules/ai/spring-boot/security-redirect-risk.rule.yaml +24 -0
  55. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.prompt.md +75 -0
  56. package/dist/builtin-rules/ai/spring-boot/security-sensitive-data-risk.rule.yaml +25 -0
  57. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.prompt.md +78 -0
  58. package/dist/builtin-rules/ai/spring-boot/transaction-loop-risk.rule.yaml +25 -0
  59. package/dist/builtin-rules/static/angular/component-prefix.rule.js +78 -0
  60. package/dist/builtin-rules/static/angular/image-control-alt-required.rule.js +105 -0
  61. package/dist/builtin-rules/static/angular/img-alt-required.rule.js +96 -0
  62. package/dist/builtin-rules/static/angular/inject-pattern.rule.js +47 -0
  63. package/dist/builtin-rules/static/angular/lifecycle-method-required.rule.js +59 -0
  64. package/dist/builtin-rules/static/angular/no-any-type.rule.yaml +55 -0
  65. package/dist/builtin-rules/static/angular/no-direct-dom-access.rule.js +191 -0
  66. package/dist/builtin-rules/static/angular/no-dom-xss.rule.js +48 -0
  67. package/dist/builtin-rules/static/angular/no-leaky-subscription.rule.js +197 -0
  68. package/dist/builtin-rules/static/angular/no-ngmodule.rule.yaml +44 -0
  69. package/dist/builtin-rules/static/angular/no-non-null-asserted-optional-chain.rule.js +53 -0
  70. package/dist/builtin-rules/static/angular/no-uncalled-signal-in-condition.rule.js +112 -0
  71. package/dist/builtin-rules/static/angular/observable-naming.rule.js +85 -0
  72. package/dist/builtin-rules/static/angular/onpush-required.rule.js +70 -0
  73. package/dist/builtin-rules/static/angular/standalone-component-required.rule.js +65 -0
  74. package/dist/builtin-rules/static/angular/template-dom-xss.rule.js +112 -0
  75. package/dist/builtin-rules/static/angular/template-syntax-modern.rule.js +154 -0
  76. package/dist/builtin-rules/static/angular/trackby-required.rule.js +66 -0
  77. package/dist/builtin-rules/static/flutter/android-exported-component.rule.js +75 -0
  78. package/dist/builtin-rules/static/flutter/android-manifest-hardening.rule.js +117 -0
  79. package/dist/builtin-rules/static/flutter/android-sensitive-permissions.rule.js +87 -0
  80. package/dist/builtin-rules/static/flutter/debug-tooling-release-risk.rule.js +90 -0
  81. package/dist/builtin-rules/static/flutter/dynamic-archive-risk.rule.js +96 -0
  82. package/dist/builtin-rules/static/flutter/hive-sensitive-storage.rule.js +77 -0
  83. package/dist/builtin-rules/static/flutter/ios-privacy-hardening.rule.js +119 -0
  84. package/dist/builtin-rules/static/flutter/packaged-env-risk.rule.js +95 -0
  85. package/dist/builtin-rules/static/flutter/sensitive-log-leak.rule.js +94 -0
  86. package/dist/builtin-rules/static/flutter/webview-bridge-guard.rule.js +102 -0
  87. package/dist/builtin-rules/static/general/file-too-long.rule.js +41 -0
  88. package/dist/builtin-rules/static/general/function-too-long.rule.js +72 -0
  89. package/dist/builtin-rules/static/general/no-circular-import.rule.js +39 -0
  90. package/dist/builtin-rules/static/general/no-code-injection.rule.js +48 -0
  91. package/dist/builtin-rules/static/general/no-console-log.rule.js +110 -0
  92. package/dist/builtin-rules/static/general/no-empty-catch.rule.yaml +56 -0
  93. package/dist/builtin-rules/static/general/no-hardcoded-secret.rule.js +517 -0
  94. package/dist/builtin-rules/static/general/no-magic-number.rule.js +78 -0
  95. package/dist/builtin-rules/static/general/no-open-redirect.rule.js +46 -0
  96. package/dist/builtin-rules/static/general/no-todo-comment.rule.yaml +30 -0
  97. package/dist/builtin-rules/static/general/no-unresolved-import-symbol.rule.js +80 -0
  98. package/dist/builtin-rules/static/general/no-unused-export.rule.js +140 -0
  99. package/dist/builtin-rules/static/spring-boot/no-autowired-field.rule.js +162 -0
  100. package/dist/builtin-rules/static/spring-boot/no-business-logic-in-controller.rule.js +94 -0
  101. package/dist/builtin-rules/static/spring-boot/no-command-injection.rule.js +47 -0
  102. package/dist/builtin-rules/static/spring-boot/no-entity-in-controller.rule.yaml +52 -0
  103. package/dist/builtin-rules/static/spring-boot/no-nplus1-query-in-loop.rule.js +106 -0
  104. package/dist/builtin-rules/static/spring-boot/no-path-traversal.rule.js +47 -0
  105. package/dist/builtin-rules/static/spring-boot/no-spel-injection.rule.js +41 -0
  106. package/dist/builtin-rules/static/spring-boot/no-sql-string-concat.rule.js +194 -0
  107. package/dist/builtin-rules/static/spring-boot/no-ssrf.rule.js +49 -0
  108. package/dist/builtin-rules/static/spring-boot/no-transactional-self-invocation.rule.js +142 -0
  109. package/dist/builtin-rules/static/spring-boot/no-unclosed-resource.rule.js +108 -0
  110. package/dist/builtin-rules/static/spring-boot/no-unsafe-shared-formatter.rule.js +118 -0
  111. package/dist/builtin-rules/static/spring-boot/repository-naming.rule.yaml +42 -0
  112. package/dist/builtin-rules/static/spring-boot/restful-naming.rule.yaml +39 -0
  113. package/dist/builtin-rules/static/spring-boot/transaction-on-service.rule.yaml +58 -0
  114. package/dist/builtin-rules/static/spring-boot/validate-input.rule.js +123 -0
  115. package/dist/builtin-rules/vauthz/static/spring-boot/require-authz-check.rule.js +101 -0
  116. package/dist/index.d.ts +224 -47
  117. package/dist/index.js +1183 -808
  118. package/package.json +3 -2
  119. package/src/migrations/0000_initial.sql +62 -0
  120. package/src/migrations/0001_add_confidence.sql +7 -0
  121. package/src/migrations/0002_add_ai_stats.sql +21 -0
  122. package/src/migrations/0003_add_fix_recipe.sql +29 -0
  123. package/src/migrations/0004_add_ast_graph.sql +61 -0
  124. package/src/migrations/0005_add_project_id.sql +1 -0
  125. package/src/migrations/0006_add_ai_model.sql +5 -0
  126. package/src/migrations/0006_add_rule_results.sql +1 -0
  127. package/src/migrations/0007_add_finding_metadata.sql +4 -0
  128. package/src/migrations/0008_add_coverage.sql +2 -0
  129. package/src/migrations/0009_run_provenance.sql +5 -0
@@ -0,0 +1,90 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+
24
+ // builtin-rules/static/flutter/debug-tooling-release-risk.rule.ts
25
+ var RISK_PATTERNS = [
26
+ /RequestsInspector\b/,
27
+ /DevicePreview\b/,
28
+ /InAppDebugConsoleManager\b/,
29
+ /AndroidWebViewController\.enableDebugging\(\s*true\s*\)/,
30
+ /WebView\.setWebContentsDebuggingEnabled\(\s*true\s*\)/,
31
+ /setWebContentsDebuggingEnabled\(\s*true\s*\)/
32
+ ];
33
+ var hasCompileTimeDebugGuard = (windowText) => /\bkDebugMode\b|\bBuildConfig\.DEBUG\b|\bDEBUG\b|#if\s+DEBUG|assert\s*\(/.test(windowText);
34
+ var rule = {
35
+ id: "flutter/debug-tooling-release-risk",
36
+ version: 2,
37
+ kind: "static-ts",
38
+ title: "Debug tooling kh\xF4ng \u0111\u01B0\u1EE3c b\u1EADt ngo\xE0i debug build",
39
+ description: "Ph\xE1t hi\u1EC7n RequestsInspector, DevicePreview, WebView debugging ho\u1EB7c in-app debug console c\xF3 nguy c\u01A1 xu\u1EA5t hi\u1EC7n \u1EDF dev/staging/release.",
40
+ severity: "warning",
41
+ category: "mobile-security",
42
+ languages: ["dart", "kotlin", "swift", "java", "objective-c"],
43
+ scope: "flutter",
44
+ requires: "text",
45
+ baseConfidence: 76,
46
+ defaultOptions: {
47
+ targetProfile: "prod-release"
48
+ },
49
+ check(ctx) {
50
+ const targetProfile = ctx.options.targetProfile ?? "prod-release";
51
+ if (targetProfile === "dev-debug") return [];
52
+ const lines = ctx.file.content.split(/\r?\n/);
53
+ const out = [];
54
+ let offset = 0;
55
+ for (let i = 0; i < lines.length; i += 1) {
56
+ const line = lines[i] ?? "";
57
+ const matched = RISK_PATTERNS.some((pattern) => pattern.test(line));
58
+ if (!matched) {
59
+ offset += line.length + 1;
60
+ continue;
61
+ }
62
+ const windowText = lines.slice(Math.max(0, i - 4), Math.min(lines.length, i + 5)).join("\n");
63
+ if (hasCompileTimeDebugGuard(windowText) && !/isDebugMode|isDev|isStaging/.test(windowText)) {
64
+ offset += line.length + 1;
65
+ continue;
66
+ }
67
+ out.push(
68
+ finding(
69
+ ctx.file,
70
+ offset,
71
+ "Debug tooling ho\u1EB7c WebView debugging c\xF3 th\u1EC3 b\u1EADt ngo\xE0i debug build.",
72
+ "B\u1ECDc b\u1EB1ng compile-time debug guard (`kDebugMode`, `BuildConfig.DEBUG`, DEBUG flag) v\xE0 \u0111\u1EA3m b\u1EA3o dev/staging flag kh\xF4ng \u0111i v\xE0o release.",
73
+ {
74
+ confidence: /isStaging|isDev|isDebugMode/.test(windowText) ? 82 : 76,
75
+ snippet: line.trim(),
76
+ rootCauseKey: "debug-tooling-release-profile",
77
+ tags: ["debug-tooling", "release-profile"],
78
+ profileApplicability: targetProfile
79
+ }
80
+ )
81
+ );
82
+ offset += line.length + 1;
83
+ }
84
+ return out;
85
+ }
86
+ };
87
+
88
+ export { rule };
89
+ //# sourceMappingURL=debug-tooling-release-risk.rule.js.map
90
+ //# sourceMappingURL=debug-tooling-release-risk.rule.js.map
@@ -0,0 +1,96 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+
29
+ // builtin-rules/static/flutter/dynamic-archive-risk.rule.ts
30
+ var ARCHIVE_RE = /ZipDecoder|ZipFile|decodeBytes|extract(File|Archive)?/i;
31
+ var ENTRY_NAME_RE = /\b(?:entry|file|archiveFile|archiveEntry)\.name\b/;
32
+ var FILE_WRITE_SINK_RE = /\bFile\s*\(|\.writeAs(?:Bytes|String)(?:Sync)?\s*\(|\.create(?:Sync)?\s*\(|\.copy(?:Sync)?\s*\(/;
33
+ var TRAVERSAL_GUARD_RE = /basename|normalize|canonicalize|isWithin|startsWith\s*\([^)]*(?:target|dest|extract|directory)|realpath|resolveSymbolicLinks/i;
34
+ var ALLOWLIST_RE = /allow(ed)?(Files|Extensions|List)|whitelist|extension/i;
35
+ var SIZE_OR_INTEGRITY_RE = /sha256|sha-256|checksum|digest|signature|hash|max(Size|Bytes)?|lengthInBytes|contentLength|uncompressedSize/i;
36
+ var rule = {
37
+ id: "flutter/dynamic-archive-risk",
38
+ version: 2,
39
+ kind: "static-ts",
40
+ title: "Downloaded ZIP/archive ph\u1EA3i ch\u1ED1ng traversal v\xE0 ki\u1EC3m so\xE1t integrity",
41
+ description: "Ph\xE1t hi\u1EC7n download/extract ZIP ho\u1EB7c remote asset thi\u1EBFu path traversal guard, file allowlist, size ho\u1EB7c integrity check.",
42
+ severity: "warning",
43
+ category: "mobile-security",
44
+ languages: ["dart", "kotlin", "swift", "java"],
45
+ scope: "flutter",
46
+ requires: "text",
47
+ baseConfidence: 82,
48
+ check(ctx) {
49
+ const content = ctx.file.content;
50
+ const archiveIndex = firstIndex(content, ARCHIVE_RE);
51
+ if (archiveIndex < 0 || !ENTRY_NAME_RE.test(content) || !FILE_WRITE_SINK_RE.test(content)) {
52
+ return [];
53
+ }
54
+ const index = firstIndex(content, FILE_WRITE_SINK_RE);
55
+ const out = [];
56
+ const hasTraversalGuard = TRAVERSAL_GUARD_RE.test(content);
57
+ const hasAllowlist = ALLOWLIST_RE.test(content);
58
+ const hasSizeOrIntegrity = SIZE_OR_INTEGRITY_RE.test(content);
59
+ if (!hasTraversalGuard) {
60
+ out.push(
61
+ finding(
62
+ ctx.file,
63
+ index,
64
+ "Archive/ZIP extraction ch\u01B0a th\u1EA5y guard ch\u1ED1ng path traversal (`../`).",
65
+ "Chu\u1EA9n h\xF3a path, reject absolute/parent traversal, v\xE0 x\xE1c nh\u1EADn file \u0111\xEDch v\u1EABn n\u1EB1m trong th\u01B0 m\u1EE5c extract.",
66
+ {
67
+ severity: /\.\.\//.test(content) ? "error" : "warning",
68
+ confidence: /\.\.\//.test(content) ? 90 : 82,
69
+ rootCauseKey: "archive-extract-path-traversal",
70
+ tags: ["archive", "path-traversal"]
71
+ }
72
+ )
73
+ );
74
+ }
75
+ if (!hasAllowlist || !hasSizeOrIntegrity) {
76
+ out.push(
77
+ finding(
78
+ ctx.file,
79
+ index,
80
+ "Downloaded archive thi\u1EBFu file allowlist, size limit ho\u1EB7c integrity/hash check r\xF5 r\xE0ng.",
81
+ "Gi\u1EDBi h\u1EA1n lo\u1EA1i file \u0111\u01B0\u1EE3c extract, \u0111\u1EB7t max size/uncompressed size v\xE0 ki\u1EC3m tra checksum/signature khi t\u1EA3i remote asset.",
82
+ {
83
+ confidence: 78,
84
+ rootCauseKey: "archive-extract-integrity-bounds",
85
+ tags: ["archive", "integrity"]
86
+ }
87
+ )
88
+ );
89
+ }
90
+ return out;
91
+ }
92
+ };
93
+
94
+ export { rule };
95
+ //# sourceMappingURL=dynamic-archive-risk.rule.js.map
96
+ //# sourceMappingURL=dynamic-archive-risk.rule.js.map
@@ -0,0 +1,77 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+
29
+ // builtin-rules/static/flutter/hive-sensitive-storage.rule.ts
30
+ var SENSITIVE_RE = /\b(auth|token|accessToken|refreshToken|password|credential|session|pin|otp)\b/i;
31
+ var ENCRYPTED_RE = /openBoxWithDefaultEncrypt|HiveAesCipher|encryptionCipher|FlutterSecureStorage|secureStorage/i;
32
+ var rule = {
33
+ id: "flutter/hive-sensitive-storage",
34
+ version: 1,
35
+ kind: "static-ts",
36
+ title: "Hive auth/token storage ph\u1EA3i \u0111\u01B0\u1EE3c m\xE3 h\xF3a",
37
+ description: "D\u1EEF li\u1EC7u auth/token/password kh\xF4ng n\xEAn l\u01B0u trong Hive plaintext; d\xF9ng encrypted Hive ho\u1EB7c secure storage.",
38
+ severity: "warning",
39
+ category: "mobile-security",
40
+ languages: ["dart"],
41
+ scope: "flutter",
42
+ requires: "text",
43
+ baseConfidence: 84,
44
+ check(ctx) {
45
+ const content = ctx.file.content;
46
+ const sensitiveContext = SENSITIVE_RE.test(content) || SENSITIVE_RE.test(ctx.file.path);
47
+ if (!sensitiveContext) return [];
48
+ const hiveIndex = firstIndex(content, /Hive\.openBox\s*\(|Hive\.box\s*\(/);
49
+ if (hiveIndex >= 0 && !ENCRYPTED_RE.test(content)) {
50
+ return [
51
+ finding(
52
+ ctx.file,
53
+ hiveIndex,
54
+ "Hive box ch\u1EE9a d\u1EEF li\u1EC7u nh\u1EA1y c\u1EA3m nh\u01B0ng ch\u01B0a th\u1EA5y encryption cipher/secure storage.",
55
+ "D\xF9ng encrypted Hive (`HiveAesCipher` v\u1EDBi key t\u1EEB FlutterSecureStorage) ho\u1EB7c chuy\u1EC3n token/password sang secure storage."
56
+ )
57
+ ];
58
+ }
59
+ const sharedPrefsIndex = firstIndex(content, /SharedPreferences/);
60
+ if (sharedPrefsIndex >= 0) {
61
+ return [
62
+ finding(
63
+ ctx.file,
64
+ sharedPrefsIndex,
65
+ "SharedPreferences xu\u1EA5t hi\u1EC7n trong ng\u1EEF c\u1EA3nh auth/token nh\u1EA1y c\u1EA3m.",
66
+ "Kh\xF4ng l\u01B0u token/password trong SharedPreferences plaintext; d\xF9ng FlutterSecureStorage ho\u1EB7c encrypted storage.",
67
+ { confidence: 78 }
68
+ )
69
+ ];
70
+ }
71
+ return [];
72
+ }
73
+ };
74
+
75
+ export { rule };
76
+ //# sourceMappingURL=hive-sensitive-storage.rule.js.map
77
+ //# sourceMappingURL=hive-sensitive-storage.rule.js.map
@@ -0,0 +1,119 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+ var isPath = (file, suffix) => file.path.replace(/\\/g, "/").toLowerCase().endsWith(suffix.toLowerCase());
29
+
30
+ // builtin-rules/static/flutter/ios-privacy-hardening.rule.ts
31
+ var PRIVACY_KEYS = [
32
+ "NSCameraUsageDescription",
33
+ "NSMicrophoneUsageDescription",
34
+ "NSLocationWhenInUseUsageDescription",
35
+ "NSLocationAlwaysAndWhenInUseUsageDescription",
36
+ "NSPhotoLibraryUsageDescription",
37
+ "NSPhotoLibraryAddUsageDescription",
38
+ "NSContactsUsageDescription",
39
+ "NSSpeechRecognitionUsageDescription",
40
+ "NSFaceIDUsageDescription"
41
+ ];
42
+ var boolKeyIndex = (content, key, value) => firstIndex(content, new RegExp(`<key>\\s*${key}\\s*<\\/key>\\s*<${value}\\s*\\/>`, "i"));
43
+ var emptyStringKeyIndex = (content, key) => firstIndex(content, new RegExp(`<key>\\s*${key}\\s*<\\/key>\\s*<string>\\s*<\\/string>`, "i"));
44
+ var rule = {
45
+ id: "flutter/ios-privacy-hardening",
46
+ version: 1,
47
+ kind: "static-ts",
48
+ title: "iOS Info.plist privacy hardening",
49
+ description: "Ki\u1EC3m tra Info.plist v\u1EC1 file sharing/document opening, ATS v\xE0 privacy usage descriptions.",
50
+ severity: "warning",
51
+ category: "mobile-privacy",
52
+ languages: ["plist"],
53
+ scope: "flutter",
54
+ requires: "text",
55
+ baseConfidence: 80,
56
+ check(ctx) {
57
+ if (!isPath(ctx.file, "info.plist")) return [];
58
+ const content = ctx.file.content;
59
+ const out = [];
60
+ for (const key of ["UIFileSharingEnabled", "LSSupportsOpeningDocumentsInPlace"]) {
61
+ const index = boolKeyIndex(content, key, "true");
62
+ if (index >= 0) {
63
+ out.push(
64
+ finding(
65
+ ctx.file,
66
+ index,
67
+ `Info.plist b\u1EADt ${key}; d\u1EEF li\u1EC7u document/app container c\xF3 th\u1EC3 l\u1ED9 qua Files/iTunes.`,
68
+ "Ch\u1EC9 b\u1EADt khi c\xF3 y\xEAu c\u1EA7u s\u1EA3n ph\u1EA9m r\xF5 r\xE0ng, v\xE0 \u0111\u1EA3m b\u1EA3o file nh\u1EA1y c\u1EA3m kh\xF4ng n\u1EB1m trong Documents ho\u1EB7c \u0111\u01B0\u1EE3c m\xE3 h\xF3a."
69
+ )
70
+ );
71
+ }
72
+ }
73
+ for (const key of ["NSAllowsArbitraryLoads", "NSExceptionAllowsInsecureHTTPLoads"]) {
74
+ const index = boolKeyIndex(content, key, "true");
75
+ if (index >= 0) {
76
+ out.push(
77
+ finding(
78
+ ctx.file,
79
+ index,
80
+ `ATS cho ph\xE9p k\u1EBFt n\u1ED1i kh\xF4ng an to\xE0n qua ${key}.`,
81
+ "Gi\u1EEF ATS m\u1EB7c \u0111\u1ECBnh, ch\u1EC9 exception theo domain th\u1EADt s\u1EF1 c\u1EA7n v\xE0 c\xF3 k\u1EBF ho\u1EA1ch lo\u1EA1i b\u1ECF HTTP.",
82
+ { severity: "error", confidence: 90 }
83
+ )
84
+ );
85
+ }
86
+ }
87
+ for (const key of PRIVACY_KEYS) {
88
+ const emptyIndex = emptyStringKeyIndex(content, key);
89
+ if (emptyIndex >= 0) {
90
+ out.push(
91
+ finding(
92
+ ctx.file,
93
+ emptyIndex,
94
+ `${key} \u0111ang \u0111\u1EC3 tr\u1ED1ng.`,
95
+ "\u0110i\u1EC1n m\xF4 t\u1EA3 permission c\u1EE5 th\u1EC3 theo t\xEDnh n\u0103ng \u0111\u1EC3 Apple review v\xE0 ng\u01B0\u1EDDi d\xF9ng hi\u1EC3u v\xEC sao c\u1EA7n quy\u1EC1n."
96
+ )
97
+ );
98
+ continue;
99
+ }
100
+ const index = firstIndex(content, `<key>${key}</key>`);
101
+ if (index >= 0) {
102
+ out.push(
103
+ finding(
104
+ ctx.file,
105
+ index,
106
+ `${key} xu\u1EA5t hi\u1EC7n trong Info.plist; c\u1EA7n \u0111\u1ED1i chi\u1EBFu t\xEDnh n\u0103ng d\xF9ng quy\u1EC1n t\u01B0\u01A1ng \u1EE9ng.`,
107
+ "X\xE1c nh\u1EADn Dart/native code th\u1EADt s\u1EF1 d\xF9ng quy\u1EC1n n\xE0y, copy gi\u1EA3i th\xEDch \u0111\xFAng t\xEDnh n\u0103ng, v\xE0 b\u1ECF key n\u1EBFu kh\xF4ng c\u1EA7n.",
108
+ { severity: "info", confidence: 65 }
109
+ )
110
+ );
111
+ }
112
+ }
113
+ return out;
114
+ }
115
+ };
116
+
117
+ export { rule };
118
+ //# sourceMappingURL=ios-privacy-hardening.rule.js.map
119
+ //# sourceMappingURL=ios-privacy-hardening.rule.js.map
@@ -0,0 +1,95 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+
29
+ // builtin-rules/static/flutter/packaged-env-risk.rule.ts
30
+ var SECRET_KEY_RE = /^\s*[A-Z0-9_]*(SECRET|TOKEN|PASSWORD|API[_-]?KEY|PRIVATE[_-]?KEY|CLIENT[_-]?SECRET)[A-Z0-9_]*\s*=/i;
31
+ var URL_ENV_RE = /^\s*[A-Z0-9_]+\s*=\s*['"]?https?:\/\//i;
32
+ var rule = {
33
+ id: "flutter/packaged-env-risk",
34
+ version: 1,
35
+ kind: "static-ts",
36
+ title: "Kh\xF4ng \u0111\xF3ng g\xF3i env secret/endpoint nh\u1EA1y c\u1EA3m trong Flutter assets",
37
+ description: "C\u1EA3nh b\xE1o .env.* trong assets ho\u1EB7c ch\u1EE9a endpoint/secret c\u1EA7n ki\u1EC3m so\xE1t tr\u01B0\u1EDBc khi \u0111\xF3ng g\xF3i app.",
38
+ severity: "warning",
39
+ category: "mobile-security",
40
+ languages: ["yaml", "text", "shell"],
41
+ scope: "flutter",
42
+ requires: "text",
43
+ baseConfidence: 80,
44
+ check(ctx) {
45
+ const path = ctx.file.path.replace(/\\/g, "/").toLowerCase();
46
+ const content = ctx.file.content;
47
+ const out = [];
48
+ if (path.endsWith("pubspec.yaml")) {
49
+ const envAssetIndex = firstIndex(content, /assets:[\s\S]*(\.env|config\/env)/i);
50
+ if (envAssetIndex >= 0) {
51
+ out.push(
52
+ finding(
53
+ ctx.file,
54
+ envAssetIndex,
55
+ "pubspec.yaml c\xF3 v\u1EBB \u0111\xF3ng g\xF3i `.env`/`config/env` v\xE0o Flutter assets.",
56
+ "Kh\xF4ng \u0111\xF3ng g\xF3i secret v\xE0o app; n\u1EBFu ch\u1EC9 l\xE0 endpoint public, t\xE1ch theo flavor v\xE0 ki\u1EC3m so\xE1t r\xF5 m\xF4i tr\u01B0\u1EDDng build."
57
+ )
58
+ );
59
+ }
60
+ }
61
+ if (/(^|\/)\.env(\.|$)|config\/env\/\.env/.test(path)) {
62
+ const lines = content.split(/\r?\n/);
63
+ let offset = 0;
64
+ for (const line of lines) {
65
+ if (SECRET_KEY_RE.test(line)) {
66
+ out.push(
67
+ finding(
68
+ ctx.file,
69
+ offset,
70
+ "File .env ch\u1EE9a key c\xF3 v\u1EBB l\xE0 secret/token/password.",
71
+ "Kh\xF4ng commit/\u0111\xF3ng g\xF3i secret th\u1EADt v\xE0o mobile app; chuy\u1EC3n sang server-side config ho\u1EB7c secret manager.",
72
+ { severity: "error", confidence: 88 }
73
+ )
74
+ );
75
+ } else if (URL_ENV_RE.test(line)) {
76
+ out.push(
77
+ finding(
78
+ ctx.file,
79
+ offset,
80
+ "File .env ch\u1EE9a endpoint runtime c\u1EA7n ki\u1EC3m so\xE1t theo flavor/m\xF4i tr\u01B0\u1EDDng.",
81
+ "X\xE1c nh\u1EADn endpoint kh\xF4ng tr\u1ECF nh\u1EA7m dev/staging trong release v\xE0 kh\xF4ng ch\u1EE9a credential trong URL.",
82
+ { severity: "info", confidence: 68 }
83
+ )
84
+ );
85
+ }
86
+ offset += line.length + 1;
87
+ }
88
+ }
89
+ return out;
90
+ }
91
+ };
92
+
93
+ export { rule };
94
+ //# sourceMappingURL=packaged-env-risk.rule.js.map
95
+ //# sourceMappingURL=packaged-env-risk.rule.js.map
@@ -0,0 +1,94 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+
29
+ // builtin-rules/static/flutter/sensitive-log-leak.rule.ts
30
+ var LOG_CALL_RE = /\b(print|debugPrint|log|AppLogger\.\w+|logger\.\w+|LogInterceptor|InAppDebugConsoleManager)\b/;
31
+ var DEBUG_CONSOLE_RE = /\bInAppDebugConsoleManager\b/;
32
+ var SENSITIVE_RE = /\b(authorization|access[_-]?token|refresh[_-]?token|password|secret|cookie|headers?|body|response\.data|requestOptions\.data|curlCommand)\b/i;
33
+ var MASK_RE = /\b(mask|masked|redact|redacted|sanitize|sanitized|hideSensitive)\b/i;
34
+ var rule = {
35
+ id: "flutter/sensitive-log-leak",
36
+ version: 2,
37
+ kind: "static-ts",
38
+ title: "Log kh\xF4ng \u0111\u01B0\u1EE3c r\xF2 token/header/body nh\u1EA1y c\u1EA3m",
39
+ description: "Ph\xE1t hi\u1EC7n log request/response/cURL/header/body/token ch\u01B0a c\xF3 d\u1EA5u hi\u1EC7u mask ho\u1EB7c sanitize r\xF5 r\xE0ng.",
40
+ severity: "warning",
41
+ category: "mobile-security",
42
+ languages: ["dart", "kotlin", "swift", "java", "objective-c"],
43
+ scope: "flutter",
44
+ requires: "text",
45
+ baseConfidence: 78,
46
+ check(ctx) {
47
+ const lines = ctx.file.content.split(/\r?\n/);
48
+ const out = [];
49
+ let offset = 0;
50
+ for (let i = 0; i < lines.length; i += 1) {
51
+ const line = lines[i] ?? "";
52
+ const windowText = lines.slice(Math.max(0, i - 3), Math.min(lines.length, i + 4)).join("\n");
53
+ const lineHasMaskedSink = MASK_RE.test(line);
54
+ const debugConsoleRawMessage = DEBUG_CONSOLE_RE.test(line) && /\bmessage\b/.test(line) && MASK_RE.test(windowText);
55
+ if (LOG_CALL_RE.test(line) && (SENSITIVE_RE.test(windowText) || debugConsoleRawMessage) && !lineHasMaskedSink) {
56
+ out.push(
57
+ finding(
58
+ ctx.file,
59
+ offset,
60
+ "Log/debug console c\xF3 th\u1EC3 ghi header/body/token nh\u1EA1y c\u1EA3m ch\u01B0a \u0111\u01B0\u1EE3c mask.",
61
+ "Mask Authorization/Cookie/token/password tr\u01B0\u1EDBc khi log; kh\xF4ng l\u01B0u cURL/body response \u0111\u1EA7y \u0111\u1EE7 trong release ho\u1EB7c debug console persistent.",
62
+ {
63
+ snippet: line.trim(),
64
+ rootCauseKey: DEBUG_CONSOLE_RE.test(line) ? "debug-console-raw-sensitive-message" : "sensitive-log-sink-unmasked",
65
+ tags: ["logging", "sensitive-data"]
66
+ }
67
+ )
68
+ );
69
+ }
70
+ offset += line.length + 1;
71
+ }
72
+ const curlIndex = firstIndex(ctx.file.content, /curlCommand|_generateCurlCommand|curl -X/i);
73
+ if (curlIndex >= 0 && /headers?|body|data|Authorization|token/i.test(ctx.file.content) && !MASK_RE.test(ctx.file.content.slice(Math.max(0, curlIndex - 500), curlIndex + 800))) {
74
+ out.push(
75
+ finding(
76
+ ctx.file,
77
+ curlIndex,
78
+ "Code t\u1EA1o/log cURL c\xF3 th\u1EC3 ch\u1EE9a header ho\u1EB7c body nh\u1EA1y c\u1EA3m.",
79
+ "Ch\u1EC9 log cURL sau khi redact header nh\u1EA1y c\u1EA3m v\xE0 gi\u1EDBi h\u1EA1n body; c\xE2n nh\u1EAFc t\u1EAFt ho\xE0n to\xE0n \u1EDF non-debug build.",
80
+ {
81
+ confidence: 82,
82
+ rootCauseKey: "curl-log-sensitive-data",
83
+ tags: ["logging", "sensitive-data", "curl"]
84
+ }
85
+ )
86
+ );
87
+ }
88
+ return out;
89
+ }
90
+ };
91
+
92
+ export { rule };
93
+ //# sourceMappingURL=sensitive-log-leak.rule.js.map
94
+ //# sourceMappingURL=sensitive-log-leak.rule.js.map
@@ -0,0 +1,102 @@
1
+ // builtin-rules/static/flutter/utils.js
2
+ var lineColumnAt = (content, index) => {
3
+ const safeIndex = Math.max(0, Math.min(index, content.length));
4
+ const before = content.slice(0, safeIndex);
5
+ const lines = before.split(/\r?\n/);
6
+ return { line: lines.length, column: lines.at(-1)?.length ?? 0 };
7
+ };
8
+ var finding = (file, index, message, suggestion, opts = {}) => {
9
+ const range = lineColumnAt(file.content, index);
10
+ return {
11
+ message,
12
+ file: file.path,
13
+ range,
14
+ suggestion,
15
+ ...opts.confidence !== void 0 ? { confidence: opts.confidence } : {},
16
+ ...opts.severity !== void 0 ? { severity: opts.severity } : {},
17
+ ...opts.snippet !== void 0 ? { snippet: opts.snippet } : {},
18
+ ...opts.rootCauseKey !== void 0 ? { rootCauseKey: opts.rootCauseKey } : {},
19
+ ...opts.tags !== void 0 ? { tags: opts.tags } : {},
20
+ ...opts.profileApplicability !== void 0 ? { profileApplicability: opts.profileApplicability } : {}
21
+ };
22
+ };
23
+ var firstIndex = (content, pattern) => {
24
+ if (typeof pattern === "string") return content.indexOf(pattern);
25
+ const match = pattern.exec(content);
26
+ return match?.index ?? -1;
27
+ };
28
+
29
+ // builtin-rules/static/flutter/webview-bridge-guard.rule.ts
30
+ var hasNavigationGuard = (content) => /NavigationDelegate|onNavigationRequest|shouldOverrideUrlLoading|NavigationDecision\.prevent/i.test(
31
+ content
32
+ );
33
+ var hasHttpsGuard = (content) => /https:|https:\/\/|\.scheme\s*(?:==|!=)\s*['"]https['"]|isScheme\s*\(\s*['"]https['"]|Uri\.https/i.test(
34
+ content
35
+ );
36
+ var hasHostAllowlist = (content) => /allowedHosts|allowedDomains|allow(?:ed)?(?:Host|Domain|Origin|Url|List|list)|trusted(?:Host|Domain|Origin)|\.host\b[\s\S]{0,120}\.contains\s*\(|contains\s*\([^)]*\.host|_isAllowedNavigation/i.test(
37
+ content
38
+ );
39
+ var hasBridgeOriginGuard = (content) => /currentUrl|getUrl\s*\(|Uri\.parse|origin|\.host\b|allowed|trusted|mainFrame|_isAllowedNavigation/i.test(
40
+ content
41
+ );
42
+ var rule = {
43
+ id: "flutter/webview-bridge-guard",
44
+ version: 2,
45
+ kind: "static-ts",
46
+ title: "Flutter WebView JavaScript c\u1EA7n allowlist v\xE0 navigation guard",
47
+ description: "WebView b\u1EADt JavaScript ph\u1EA3i c\xF3 HTTPS allowlist, navigation guard v\xE0 origin validation cho bridge/channel.",
48
+ severity: "warning",
49
+ category: "mobile-security",
50
+ languages: ["dart"],
51
+ scope: "flutter",
52
+ requires: "text",
53
+ baseConfidence: 82,
54
+ check(ctx) {
55
+ const content = ctx.file.content;
56
+ const out = [];
57
+ const jsIndex = firstIndex(
58
+ content,
59
+ /JavaScriptMode\.unrestricted|JavascriptMode\.unrestricted/
60
+ );
61
+ if (jsIndex >= 0) {
62
+ if (!hasNavigationGuard(content) || !hasHttpsGuard(content) || !hasHostAllowlist(content)) {
63
+ out.push(
64
+ finding(
65
+ ctx.file,
66
+ jsIndex,
67
+ "WebView b\u1EADt JavaScript unrestricted nh\u01B0ng thi\u1EBFu guard HTTPS/host allowlist/navigation r\xF5 r\xE0ng.",
68
+ "Th\xEAm NavigationDelegate, ch\u1EC9 cho HTTPS host allowlist, ch\u1EB7n external/custom scheme v\xE0 validate origin tr\u01B0\u1EDBc m\u1ECDi bridge/channel.",
69
+ {
70
+ rootCauseKey: "webview-unrestricted-js-missing-navigation-guard",
71
+ tags: ["webview", "javascript-bridge"]
72
+ }
73
+ )
74
+ );
75
+ }
76
+ }
77
+ const channelIndex = firstIndex(
78
+ content,
79
+ /JavaScriptChannel|addJavaScriptChannel|JavascriptChannel/
80
+ );
81
+ if (channelIndex >= 0 && !hasBridgeOriginGuard(content)) {
82
+ out.push(
83
+ finding(
84
+ ctx.file,
85
+ channelIndex,
86
+ "JavaScript bridge/channel ch\u01B0a th\u1EA5y origin validation r\xF5 r\xE0ng.",
87
+ "Tr\u01B0\u1EDBc khi x\u1EED l\xFD message t\u1EEB WebView bridge, x\xE1c th\u1EF1c URL/origin hi\u1EC7n t\u1EA1i thu\u1ED9c allowlist HTTPS.",
88
+ {
89
+ confidence: 78,
90
+ rootCauseKey: "webview-js-channel-missing-origin-check",
91
+ tags: ["webview", "javascript-bridge"]
92
+ }
93
+ )
94
+ );
95
+ }
96
+ return out;
97
+ }
98
+ };
99
+
100
+ export { rule };
101
+ //# sourceMappingURL=webview-bridge-guard.rule.js.map
102
+ //# sourceMappingURL=webview-bridge-guard.rule.js.map