slopbrick 0.28.0 → 0.30.0

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.
package/dist/index.cjs CHANGED
@@ -36,7 +36,7 @@ var VERSION;
36
36
  var init_header = __esm({
37
37
  "src/types/_header.ts"() {
38
38
  "use strict";
39
- VERSION = "0.28.0";
39
+ VERSION = "0.30.0";
40
40
  }
41
41
  });
42
42
 
@@ -30662,6 +30662,246 @@ var init_struct_tag_inconsistency = __esm({
30662
30662
  }
30663
30663
  });
30664
30664
 
30665
+ // src/rules/java/command-injection.ts
30666
+ var COMMAND_INVOCATION_REGEX, STRING_CONCAT_REGEX, javaCommandInjectionRule;
30667
+ var init_command_injection = __esm({
30668
+ "src/rules/java/command-injection.ts"() {
30669
+ "use strict";
30670
+ init_rule();
30671
+ COMMAND_INVOCATION_REGEX = /\b(?:Runtime\.exec|Runtime\.getRuntime\(\)\.exec|ProcessBuilder)\s*\(/;
30672
+ STRING_CONCAT_REGEX = /["'][^"']*["']\s*\+/;
30673
+ javaCommandInjectionRule = createRule({
30674
+ id: "java/command-injection",
30675
+ category: "security",
30676
+ severity: "high",
30677
+ aiSpecific: false,
30678
+ description: "Runtime.exec() or ProcessBuilder with string concat \u2014 use List<String> args + validation",
30679
+ create(_context) {
30680
+ return {};
30681
+ },
30682
+ analyze(_context, facts) {
30683
+ const issues = [];
30684
+ const source = facts.v2?._source;
30685
+ if (!source) return issues;
30686
+ if (!/\.java$/i.test(facts.filePath)) return issues;
30687
+ const lines = source.split("\n");
30688
+ for (let i = 0; i < lines.length; i++) {
30689
+ const line = lines[i];
30690
+ if (!COMMAND_INVOCATION_REGEX.test(line)) continue;
30691
+ if (!STRING_CONCAT_REGEX.test(line)) continue;
30692
+ issues.push({
30693
+ ruleId: "java/command-injection",
30694
+ category: "security",
30695
+ severity: "high",
30696
+ aiSpecific: false,
30697
+ message: `Command invocation with string concat at line ${i + 1}`,
30698
+ line: i + 1,
30699
+ column: 1,
30700
+ advice: "Use ProcessBuilder with a List<String> of args (no shell parsing) and validate each arg against a whitelist. For shell commands, use bash -c only with a fixed string (no concatenation). String concat into Runtime.exec() is the canonical command-injection pattern \u2014 attackers can break out with `; rm -rf /` or `$(...)`. Reference: java/command-injection v0.30 (OWASP A03:2021)."
30701
+ });
30702
+ }
30703
+ return issues;
30704
+ }
30705
+ });
30706
+ }
30707
+ });
30708
+
30709
+ // src/rules/java/hardcoded-credential.ts
30710
+ var KEY_REGEX, VALUE_REGEX, FALSE_POSITIVES, javaHardcodedCredentialRule;
30711
+ var init_hardcoded_credential = __esm({
30712
+ "src/rules/java/hardcoded-credential.ts"() {
30713
+ "use strict";
30714
+ init_rule();
30715
+ KEY_REGEX = /\b(api[_-]?key|apikey|secret|token|password|auth|access[_-]?key|client[_-]?secret|private[_-]?key)\b\s*[=:]/i;
30716
+ VALUE_REGEX = /["']([A-Za-z0-9_\-+/=.@*!]{16,})["']/;
30717
+ FALSE_POSITIVES = /* @__PURE__ */ new Set([
30718
+ "passwordless",
30719
+ "tokenize",
30720
+ "tokenizer",
30721
+ "authorizationrequired",
30722
+ "authenticated",
30723
+ "authenticatortoken",
30724
+ "authtoken",
30725
+ "placeholder",
30726
+ "changeme"
30727
+ ]);
30728
+ javaHardcodedCredentialRule = createRule({
30729
+ id: "java/hardcoded-credential",
30730
+ category: "security",
30731
+ severity: "high",
30732
+ aiSpecific: false,
30733
+ description: "Hardcoded credential literal \u2014 use env vars or a secrets manager",
30734
+ create(_context) {
30735
+ return {};
30736
+ },
30737
+ analyze(_context, facts) {
30738
+ const issues = [];
30739
+ const source = facts.v2?._source;
30740
+ if (!source) return issues;
30741
+ if (!/\.java$/i.test(facts.filePath)) return issues;
30742
+ if (/\/test\//i.test(facts.filePath) || /\/src\/test\//i.test(facts.filePath)) return issues;
30743
+ const lines = source.split("\n");
30744
+ for (let i = 0; i < lines.length; i++) {
30745
+ const line = lines[i];
30746
+ if (!KEY_REGEX.test(line)) continue;
30747
+ const valueMatch = VALUE_REGEX.exec(line);
30748
+ if (!valueMatch) continue;
30749
+ const value = valueMatch[1];
30750
+ if (FALSE_POSITIVES.has(value.toLowerCase())) continue;
30751
+ if (!/[a-zA-Z]/.test(value) || !/[0-9]/.test(value)) continue;
30752
+ if (value.startsWith("$")) continue;
30753
+ issues.push({
30754
+ ruleId: "java/hardcoded-credential",
30755
+ category: "security",
30756
+ severity: "high",
30757
+ aiSpecific: false,
30758
+ message: `Hardcoded credential at line ${i + 1}`,
30759
+ line: i + 1,
30760
+ column: 1,
30761
+ advice: "Move the credential to an environment variable, a .env file that is .gitignore'd, or a secrets manager (Vault, AWS Secrets Manager, GCP Secret Manager). Hardcoded credentials are the #1 source of secret leaks on GitHub. Reference: java/hardcoded-credential v0.30 (OWASP A07:2021 \u2014 Identification and Authentication Failures)."
30762
+ });
30763
+ }
30764
+ return issues;
30765
+ }
30766
+ });
30767
+ }
30768
+ });
30769
+
30770
+ // src/rules/java/sql-string-concat.ts
30771
+ var SQL_KEYWORD_REGEX, UNSAFE_REGEX, SAFE_REGEX, javaSqlStringConcatRule;
30772
+ var init_sql_string_concat = __esm({
30773
+ "src/rules/java/sql-string-concat.ts"() {
30774
+ "use strict";
30775
+ init_rule();
30776
+ SQL_KEYWORD_REGEX = /\b(?:SELECT|INSERT\s+INTO|UPDATE|DELETE\s+FROM|CREATE\s+TABLE|DROP\s+TABLE|ALTER\s+TABLE)\b/i;
30777
+ UNSAFE_REGEX = /\+/;
30778
+ SAFE_REGEX = /(?:PreparedStatement|setParameter|setString|setInt|setLong|createQuery.*:.*\b(?:set|bind)|:name\b|\?\s*,)/;
30779
+ javaSqlStringConcatRule = createRule({
30780
+ id: "java/sql-string-concat",
30781
+ category: "security",
30782
+ severity: "high",
30783
+ aiSpecific: false,
30784
+ description: "SQL query built via string concat \u2014 use PreparedStatement or setParameter()",
30785
+ create(_context) {
30786
+ return {};
30787
+ },
30788
+ analyze(_context, facts) {
30789
+ const issues = [];
30790
+ const source = facts.v2?._source;
30791
+ if (!source) return issues;
30792
+ if (!/\.java$/i.test(facts.filePath)) return issues;
30793
+ const lines = source.split("\n");
30794
+ for (let i = 0; i < lines.length; i++) {
30795
+ const line = lines[i];
30796
+ if (!SQL_KEYWORD_REGEX.test(line)) continue;
30797
+ if (!UNSAFE_REGEX.test(line)) continue;
30798
+ if (SAFE_REGEX.test(line)) continue;
30799
+ issues.push({
30800
+ ruleId: "java/sql-string-concat",
30801
+ category: "security",
30802
+ severity: "high",
30803
+ aiSpecific: false,
30804
+ message: `SQL query built via string concat at line ${i + 1}`,
30805
+ line: i + 1,
30806
+ column: 1,
30807
+ advice: 'Use a PreparedStatement (JDBC), setParameter (jOOQ), or an ORM (Hibernate, MyBatis with #{} binding). String concatenation into a SQL query is the canonical SQL-injection pattern \u2014 even "trusted" inputs (signed JWT, internal config) can be influenced by an attacker. Reference: java/sql-string-concat v0.30 (OWASP A03:2021).'
30808
+ });
30809
+ }
30810
+ return issues;
30811
+ }
30812
+ });
30813
+ }
30814
+ });
30815
+
30816
+ // src/rules/java/system-out-println.ts
30817
+ var SYSTEM_OUT_REGEX, REAL_LOGGING_IMPORT_REGEX, javaSystemOutPrintlnRule;
30818
+ var init_system_out_println = __esm({
30819
+ "src/rules/java/system-out-println.ts"() {
30820
+ "use strict";
30821
+ init_rule();
30822
+ SYSTEM_OUT_REGEX = /\bSystem\.out\.println\s*\(/g;
30823
+ REAL_LOGGING_IMPORT_REGEX = /\bimport\s+(?:org\.slf4j\.|org\.apache\.logging\.log4j|org\.apache\.log4j|java\.util\.logging|com\.google\.common\.logging|io\.github\.oshai\.kotlinlogging)/;
30824
+ javaSystemOutPrintlnRule = createRule({
30825
+ id: "java/system-out-println",
30826
+ category: "logic",
30827
+ severity: "low",
30828
+ aiSpecific: false,
30829
+ description: "System.out.println() used for logging \u2014 use SLF4J, Log4j2, or java.util.logging",
30830
+ create(_context) {
30831
+ return {};
30832
+ },
30833
+ analyze(_context, facts) {
30834
+ const issues = [];
30835
+ const source = facts.v2?._source;
30836
+ if (!source) return issues;
30837
+ if (!/\.java$/i.test(facts.filePath)) return issues;
30838
+ if (/\/test\//i.test(facts.filePath) || /\/src\/test\//i.test(facts.filePath)) return issues;
30839
+ if (REAL_LOGGING_IMPORT_REGEX.test(source)) return issues;
30840
+ let m;
30841
+ SYSTEM_OUT_REGEX.lastIndex = 0;
30842
+ while ((m = SYSTEM_OUT_REGEX.exec(source)) !== null) {
30843
+ const line = source.slice(0, m.index).split("\n").length;
30844
+ issues.push({
30845
+ ruleId: "java/system-out-println",
30846
+ category: "logic",
30847
+ severity: "low",
30848
+ aiSpecific: false,
30849
+ message: `System.out.println() at line ${line}`,
30850
+ line,
30851
+ column: 1,
30852
+ advice: "Use a real logging library: SLF4J (the standard facade), Log4j2, or java.util.logging. System.out has no log level, no timestamp, no correlation ID, and cannot be filtered. Migration: add `private static final Logger log = LoggerFactory.getLogger(MyClass.class);` and replace `System.out.println(x)` with `log.info(x)`. Reference: java/system-out-println v0.30."
30853
+ });
30854
+ }
30855
+ return issues;
30856
+ }
30857
+ });
30858
+ }
30859
+ });
30860
+
30861
+ // src/rules/java/thread-sleep-in-loop.ts
30862
+ var THREAD_SLEEP_REGEX, javaThreadSleepInLoopRule;
30863
+ var init_thread_sleep_in_loop = __esm({
30864
+ "src/rules/java/thread-sleep-in-loop.ts"() {
30865
+ "use strict";
30866
+ init_rule();
30867
+ THREAD_SLEEP_REGEX = /\bThread\.sleep\s*\(/g;
30868
+ javaThreadSleepInLoopRule = createRule({
30869
+ id: "java/thread-sleep-in-loop",
30870
+ category: "perf",
30871
+ severity: "medium",
30872
+ aiSpecific: false,
30873
+ description: "Thread.sleep() in a loop \u2014 use ScheduledExecutorService or BlockingQueue",
30874
+ create(_context) {
30875
+ return {};
30876
+ },
30877
+ analyze(_context, facts) {
30878
+ const issues = [];
30879
+ const source = facts.v2?._source;
30880
+ if (!source) return issues;
30881
+ if (!/\.java$/i.test(facts.filePath)) return issues;
30882
+ if (!/\bThread\.sleep\s*\(/.test(source)) return issues;
30883
+ if (!/\b(?:for|while|do)\b/.test(source)) return issues;
30884
+ let m;
30885
+ THREAD_SLEEP_REGEX.lastIndex = 0;
30886
+ while ((m = THREAD_SLEEP_REGEX.exec(source)) !== null) {
30887
+ const line = source.slice(0, m.index).split("\n").length;
30888
+ issues.push({
30889
+ ruleId: "java/thread-sleep-in-loop",
30890
+ category: "perf",
30891
+ severity: "medium",
30892
+ aiSpecific: false,
30893
+ message: `Thread.sleep() at line ${line}`,
30894
+ line,
30895
+ column: 1,
30896
+ advice: 'Use ScheduledExecutorService for periodic work, or BlockingQueue.take() for event-driven work. Thread.sleep in a loop is the classic "polling with sleep" anti-pattern \u2014 the thread blocks for the sleep duration each iteration. In server contexts this ties up Tomcat/Jetty/Netty threads. Reference: java/thread-sleep-in-loop v0.30.'
30897
+ });
30898
+ }
30899
+ return issues;
30900
+ }
30901
+ });
30902
+ }
30903
+ });
30904
+
30665
30905
  // src/rules/kotlin/coroutine-global-scope.ts
30666
30906
  var GLOBAL_SCOPE_REGEX, kotlinCoroutineGlobalScopeRule;
30667
30907
  var init_coroutine_global_scope = __esm({
@@ -30768,6 +31008,115 @@ var init_data_class_defaults_overuse = __esm({
30768
31008
  }
30769
31009
  });
30770
31010
 
31011
+ // src/rules/kotlin/force-unwrap.ts
31012
+ var FORCE_UNWRAP_REGEX, kotlinForceUnwrapRule;
31013
+ var init_force_unwrap = __esm({
31014
+ "src/rules/kotlin/force-unwrap.ts"() {
31015
+ "use strict";
31016
+ init_rule();
31017
+ FORCE_UNWRAP_REGEX = /!!(?=\s*[.\)}\};,\n\[])/g;
31018
+ kotlinForceUnwrapRule = createRule({
31019
+ id: "kotlin/force-unwrap",
31020
+ category: "logic",
31021
+ severity: "medium",
31022
+ aiSpecific: false,
31023
+ description: "!! force-unwrap \u2014 use ?. (safe call) or a proper null check",
31024
+ create(_context) {
31025
+ return {};
31026
+ },
31027
+ analyze(_context, facts) {
31028
+ const issues = [];
31029
+ const source = facts.v2?._source;
31030
+ if (!source) return issues;
31031
+ if (!/\.kts?$/i.test(facts.filePath)) return issues;
31032
+ let m;
31033
+ FORCE_UNWRAP_REGEX.lastIndex = 0;
31034
+ while ((m = FORCE_UNWRAP_REGEX.exec(source)) !== null) {
31035
+ const line = source.slice(0, m.index).split("\n").length;
31036
+ const lineStart = source.lastIndexOf("\n", m.index) + 1;
31037
+ const lineText = source.slice(lineStart, m.index);
31038
+ const quoteCount = (lineText.match(/"/g) || []).length;
31039
+ if (quoteCount % 2 === 1) continue;
31040
+ issues.push({
31041
+ ruleId: "kotlin/force-unwrap",
31042
+ category: "logic",
31043
+ severity: "medium",
31044
+ aiSpecific: false,
31045
+ message: `!! force-unwrap at line ${line}`,
31046
+ line,
31047
+ column: m.index - lineStart + 1,
31048
+ advice: "Use ?. (safe call) with ?: (Elvis) for a default, or a proper when/if check. !! throws NullPointerException at runtime \u2014 it bypasses Kotlin's type system. Reference: kotlin/force-unwrap v0.29."
31049
+ });
31050
+ }
31051
+ return issues;
31052
+ }
31053
+ });
31054
+ }
31055
+ });
31056
+
31057
+ // src/rules/kotlin/hardcoded-credential.ts
31058
+ var KEY_REGEX2, VALUE_REGEX2, FALSE_POSITIVES2, kotlinHardcodedCredentialRule;
31059
+ var init_hardcoded_credential2 = __esm({
31060
+ "src/rules/kotlin/hardcoded-credential.ts"() {
31061
+ "use strict";
31062
+ init_rule();
31063
+ KEY_REGEX2 = /\b(api[_-]?key|apikey|secret|token|password|auth|access[_-]?key|client[_-]?secret|private[_-]?key)\b\s*[=:]/i;
31064
+ VALUE_REGEX2 = /["']([A-Za-z0-9_\-+/=.@*!]{16,})["']/;
31065
+ FALSE_POSITIVES2 = /* @__PURE__ */ new Set([
31066
+ "passwordless",
31067
+ "tokenize",
31068
+ "tokenizer",
31069
+ "authorizationrequired",
31070
+ "authenticated",
31071
+ "authenticatortoken",
31072
+ "authtoken",
31073
+ "placeholder",
31074
+ // common in test fixtures
31075
+ "changeme"
31076
+ // placeholder, but still suspicious — kept for review
31077
+ ]);
31078
+ kotlinHardcodedCredentialRule = createRule({
31079
+ id: "kotlin/hardcoded-credential",
31080
+ category: "security",
31081
+ severity: "high",
31082
+ aiSpecific: false,
31083
+ description: "Hardcoded credential literal \u2014 use env vars or a secrets manager",
31084
+ create(_context) {
31085
+ return {};
31086
+ },
31087
+ analyze(_context, facts) {
31088
+ const issues = [];
31089
+ const source = facts.v2?._source;
31090
+ if (!source) return issues;
31091
+ if (!/\.kts?$/i.test(facts.filePath)) return issues;
31092
+ const lines = source.split("\n");
31093
+ for (let i = 0; i < lines.length; i++) {
31094
+ const line = lines[i];
31095
+ if (!KEY_REGEX2.test(line)) continue;
31096
+ const valueMatch = VALUE_REGEX2.exec(line);
31097
+ if (!valueMatch) continue;
31098
+ const value = valueMatch[1];
31099
+ if (FALSE_POSITIVES2.has(value.toLowerCase())) continue;
31100
+ if (!/[a-zA-Z]/.test(value) || !/[0-9]/.test(value)) continue;
31101
+ if (value.startsWith("$")) continue;
31102
+ if (/\/test\//i.test(facts.filePath) || /\.test\.kts?$/i.test(facts.filePath)) continue;
31103
+ issues.push({
31104
+ ruleId: "kotlin/hardcoded-credential",
31105
+ category: "security",
31106
+ severity: "high",
31107
+ aiSpecific: false,
31108
+ message: `Hardcoded credential at line ${i + 1}`,
31109
+ line: i + 1,
31110
+ column: 1,
31111
+ advice: "Move the credential to an environment variable, a .env file that is .gitignore'd, or a secrets manager (Vault, AWS Secrets Manager, GCP Secret Manager). Hardcoded credentials are the #1 source of secret leaks on GitHub. Reference: kotlin/hardcoded-credential v0.29 (OWASP A07:2021 \u2014 Identification and Authentication Failures)."
31112
+ });
31113
+ }
31114
+ return issues;
31115
+ }
31116
+ });
31117
+ }
31118
+ });
31119
+
30771
31120
  // src/rules/kotlin/object-singleton-misuse.ts
30772
31121
  var OBJECT_DECL_REGEX, kotlinObjectSingletonMisuseRule;
30773
31122
  var init_object_singleton_misuse = __esm({
@@ -30825,13 +31174,58 @@ var init_object_singleton_misuse = __esm({
30825
31174
  }
30826
31175
  });
30827
31176
 
31177
+ // src/rules/kotlin/println-as-log.ts
31178
+ var PRINTLN_REGEX, REAL_LOGGING_IMPORT_REGEX2, kotlinPrintlnAsLogRule;
31179
+ var init_println_as_log = __esm({
31180
+ "src/rules/kotlin/println-as-log.ts"() {
31181
+ "use strict";
31182
+ init_rule();
31183
+ PRINTLN_REGEX = /\bprintln\s*\(/g;
31184
+ REAL_LOGGING_IMPORT_REGEX2 = /\bimport\s+(?:android\.util\.Log|org\.slf4j\.|io\.github\.oshai\.kotlinlogging|kotlin\.logging|co\.touchlab\.kermit|com\.github\.ajalt\.timber|org\.apache\.logging\.log4j)/;
31185
+ kotlinPrintlnAsLogRule = createRule({
31186
+ id: "kotlin/println-as-log",
31187
+ category: "logic",
31188
+ severity: "low",
31189
+ aiSpecific: false,
31190
+ description: "println() used for logging \u2014 use slf4j, kermit, or android.util.Log",
31191
+ create(_context) {
31192
+ return {};
31193
+ },
31194
+ analyze(_context, facts) {
31195
+ const issues = [];
31196
+ const source = facts.v2?._source;
31197
+ if (!source) return issues;
31198
+ if (!/\.kts?$/i.test(facts.filePath)) return issues;
31199
+ if (/\/test\//i.test(facts.filePath) || /\.test\.kts?$/i.test(facts.filePath)) return issues;
31200
+ if (REAL_LOGGING_IMPORT_REGEX2.test(source)) return issues;
31201
+ let m;
31202
+ PRINTLN_REGEX.lastIndex = 0;
31203
+ while ((m = PRINTLN_REGEX.exec(source)) !== null) {
31204
+ const line = source.slice(0, m.index).split("\n").length;
31205
+ issues.push({
31206
+ ruleId: "kotlin/println-as-log",
31207
+ category: "logic",
31208
+ severity: "low",
31209
+ aiSpecific: false,
31210
+ message: `println() as logger at line ${line}`,
31211
+ line,
31212
+ column: 1,
31213
+ advice: "Use a real logging library: slf4j (JVM), android.util.Log (Android), Timber (Android), kermit (multiplatform), or kotlin-logging. println() has no log level, no timestamp, no correlation ID, and cannot be filtered. Reference: kotlin/println-as-log v0.29."
31214
+ });
31215
+ }
31216
+ return issues;
31217
+ }
31218
+ });
31219
+ }
31220
+ });
31221
+
30828
31222
  // src/rules/kotlin/println-debug.ts
30829
- var PRINTLN_REGEX, DEFAULT_THRESHOLD, kotlinPrintlnDebugRule;
31223
+ var PRINTLN_REGEX2, DEFAULT_THRESHOLD, kotlinPrintlnDebugRule;
30830
31224
  var init_println_debug = __esm({
30831
31225
  "src/rules/kotlin/println-debug.ts"() {
30832
31226
  "use strict";
30833
31227
  init_rule();
30834
- PRINTLN_REGEX = /^\s*println\s*\(/gm;
31228
+ PRINTLN_REGEX2 = /^\s*println\s*\(/gm;
30835
31229
  DEFAULT_THRESHOLD = 1;
30836
31230
  kotlinPrintlnDebugRule = createRule({
30837
31231
  id: "kotlin/println-debug",
@@ -30849,8 +31243,8 @@ var init_println_debug = __esm({
30849
31243
  if (!/\.kts?$/i.test(facts.filePath)) return issues;
30850
31244
  const matches = [];
30851
31245
  let m;
30852
- PRINTLN_REGEX.lastIndex = 0;
30853
- while ((m = PRINTLN_REGEX.exec(source)) !== null) {
31246
+ PRINTLN_REGEX2.lastIndex = 0;
31247
+ while ((m = PRINTLN_REGEX2.exec(source)) !== null) {
30854
31248
  matches.push(m.index);
30855
31249
  }
30856
31250
  if (matches.length <= context.threshold) return issues;
@@ -30875,13 +31269,102 @@ var init_println_debug = __esm({
30875
31269
  }
30876
31270
  });
30877
31271
 
31272
+ // src/rules/kotlin/runblocking-misuse.ts
31273
+ var RUN_BLOCKING_REGEX, kotlinRunBlockingMisuseRule;
31274
+ var init_runblocking_misuse = __esm({
31275
+ "src/rules/kotlin/runblocking-misuse.ts"() {
31276
+ "use strict";
31277
+ init_rule();
31278
+ RUN_BLOCKING_REGEX = /\brunBlocking\s*[({]/g;
31279
+ kotlinRunBlockingMisuseRule = createRule({
31280
+ id: "kotlin/runblocking-misuse",
31281
+ category: "perf",
31282
+ severity: "medium",
31283
+ aiSpecific: false,
31284
+ description: "runBlocking { ... } \u2014 blocks the calling thread; use coroutineScope {} or call suspend fun directly",
31285
+ create(_context) {
31286
+ return {};
31287
+ },
31288
+ analyze(_context, facts) {
31289
+ const issues = [];
31290
+ const source = facts.v2?._source;
31291
+ if (!source) return issues;
31292
+ if (!/\.kts?$/i.test(facts.filePath)) return issues;
31293
+ if (/\bfun\s+main\s*\(/.test(source)) return issues;
31294
+ let m;
31295
+ RUN_BLOCKING_REGEX.lastIndex = 0;
31296
+ while ((m = RUN_BLOCKING_REGEX.exec(source)) !== null) {
31297
+ const line = source.slice(0, m.index).split("\n").length;
31298
+ issues.push({
31299
+ ruleId: "kotlin/runblocking-misuse",
31300
+ category: "perf",
31301
+ severity: "medium",
31302
+ aiSpecific: false,
31303
+ message: `runBlocking { ... } at line ${line}`,
31304
+ line,
31305
+ column: 1,
31306
+ advice: 'runBlocking blocks the calling thread, defeating the purpose of coroutines. Use coroutineScope { } for structured concurrency, or call the suspend function directly. The Kotlin coroutines docs: runBlocking "should rarely (if ever) be used outside of main()". Reference: kotlin/runblocking-misuse v0.29.'
31307
+ });
31308
+ }
31309
+ return issues;
31310
+ }
31311
+ });
31312
+ }
31313
+ });
31314
+
31315
+ // src/rules/kotlin/sql-string-concat.ts
31316
+ var SQL_KEYWORD_REGEX2, UNSAFE_REGEX2, SAFE_REGEX2, kotlinSqlStringConcatRule;
31317
+ var init_sql_string_concat2 = __esm({
31318
+ "src/rules/kotlin/sql-string-concat.ts"() {
31319
+ "use strict";
31320
+ init_rule();
31321
+ SQL_KEYWORD_REGEX2 = /\b(?:SELECT|INSERT\s+INTO|UPDATE|DELETE\s+FROM|CREATE\s+TABLE|DROP\s+TABLE|ALTER\s+TABLE)\b/i;
31322
+ UNSAFE_REGEX2 = /(?:\+|\$\{)/;
31323
+ SAFE_REGEX2 = /(?:PreparedStatement|setParameter|setString|setInt|setLong|bind|:name|:\\?\\?|\?\\s*,)/;
31324
+ kotlinSqlStringConcatRule = createRule({
31325
+ id: "kotlin/sql-string-concat",
31326
+ category: "security",
31327
+ severity: "high",
31328
+ aiSpecific: false,
31329
+ description: "SQL query built via string concat / template \u2014 use PreparedStatement or setParameter()",
31330
+ create(_context) {
31331
+ return {};
31332
+ },
31333
+ analyze(_context, facts) {
31334
+ const issues = [];
31335
+ const source = facts.v2?._source;
31336
+ if (!source) return issues;
31337
+ if (!/\.kts?$/i.test(facts.filePath)) return issues;
31338
+ const lines = source.split("\n");
31339
+ for (let i = 0; i < lines.length; i++) {
31340
+ const line = lines[i];
31341
+ if (!SQL_KEYWORD_REGEX2.test(line)) continue;
31342
+ if (!UNSAFE_REGEX2.test(line)) continue;
31343
+ if (SAFE_REGEX2.test(line)) continue;
31344
+ issues.push({
31345
+ ruleId: "kotlin/sql-string-concat",
31346
+ category: "security",
31347
+ severity: "high",
31348
+ aiSpecific: false,
31349
+ message: `SQL query built via string concat/template at line ${i + 1}`,
31350
+ line: i + 1,
31351
+ column: 1,
31352
+ advice: 'Use a PreparedStatement (JDBC), setParameter() (Exposed), or an ORM (Room, jOOQ). String concatenation or template interpolation into a SQL query is the canonical SQL-injection pattern \u2014 even "trusted" inputs (signed JWT, internal config) can be influenced by an attacker. Reference: kotlin/sql-string-concat v0.29 (OWASP A03:2021).'
31353
+ });
31354
+ }
31355
+ return issues;
31356
+ }
31357
+ });
31358
+ }
31359
+ });
31360
+
30878
31361
  // src/rules/kotlin/string-concat-loop.ts
30879
- var STRING_CONCAT_REGEX, kotlinStringConcatLoopRule;
31362
+ var STRING_CONCAT_REGEX2, kotlinStringConcatLoopRule;
30880
31363
  var init_string_concat_loop = __esm({
30881
31364
  "src/rules/kotlin/string-concat-loop.ts"() {
30882
31365
  "use strict";
30883
31366
  init_rule();
30884
- STRING_CONCAT_REGEX = /\b(\w+)\s*=\s*\1\s*\+\s*[^;}]+[;}\n]/g;
31367
+ STRING_CONCAT_REGEX2 = /\b(\w+)\s*=\s*\1\s*\+\s*[^;}]+[;}\n]/g;
30885
31368
  kotlinStringConcatLoopRule = createRule({
30886
31369
  id: "kotlin/string-concat-loop",
30887
31370
  category: "perf",
@@ -30898,8 +31381,8 @@ var init_string_concat_loop = __esm({
30898
31381
  if (!/\.kts?$/i.test(facts.filePath)) return issues;
30899
31382
  if (!/\b(?:for|while|repeat|forEach)\b/.test(source)) return issues;
30900
31383
  let m;
30901
- STRING_CONCAT_REGEX.lastIndex = 0;
30902
- while ((m = STRING_CONCAT_REGEX.exec(source)) !== null) {
31384
+ STRING_CONCAT_REGEX2.lastIndex = 0;
31385
+ while ((m = STRING_CONCAT_REGEX2.exec(source)) !== null) {
30903
31386
  const line = source.slice(0, m.index).split("\n").length;
30904
31387
  const lineText = source.slice(0, m.index).split("\n").pop() ?? "";
30905
31388
  if (/\.append\s*\(/.test(lineText)) continue;
@@ -40459,7 +40942,7 @@ var init_fatal_error_thrown = __esm({
40459
40942
 
40460
40943
  // src/rules/swift/force-unwrap.ts
40461
40944
  var AS_FORCE_REGEX, ACCESS_FORCE_REGEX, TRY_FORCE_REGEX, swiftForceUnwrapRule;
40462
- var init_force_unwrap = __esm({
40945
+ var init_force_unwrap2 = __esm({
40463
40946
  "src/rules/swift/force-unwrap.ts"() {
40464
40947
  "use strict";
40465
40948
  init_rule();
@@ -46318,10 +46801,20 @@ var init_builtins = __esm({
46318
46801
  init_error_wrap_without_context();
46319
46802
  init_nil_slice_vs_empty();
46320
46803
  init_struct_tag_inconsistency();
46804
+ init_command_injection();
46805
+ init_hardcoded_credential();
46806
+ init_sql_string_concat();
46807
+ init_system_out_println();
46808
+ init_thread_sleep_in_loop();
46321
46809
  init_coroutine_global_scope();
46322
46810
  init_data_class_defaults_overuse();
46811
+ init_force_unwrap();
46812
+ init_hardcoded_credential2();
46323
46813
  init_object_singleton_misuse();
46814
+ init_println_as_log();
46324
46815
  init_println_debug();
46816
+ init_runblocking_misuse();
46817
+ init_sql_string_concat2();
46325
46818
  init_string_concat_loop();
46326
46819
  init_gap_monopoly();
46327
46820
  init_math_element_uniformity();
@@ -46362,7 +46855,7 @@ var init_builtins = __esm({
46362
46855
  init_target_blank_no_noopener();
46363
46856
  init_unsafe_html_render();
46364
46857
  init_fatal_error_thrown();
46365
- init_force_unwrap();
46858
+ init_force_unwrap2();
46366
46859
  init_implicitly_unwrapped_optional();
46367
46860
  init_print_debug();
46368
46861
  init_strong_self_capture();
@@ -46447,10 +46940,20 @@ var init_builtins = __esm({
46447
46940
  goErrorWrapWithoutContextRule,
46448
46941
  goNilSliceVsEmptyRule,
46449
46942
  goStructTagInconsistencyRule,
46943
+ javaCommandInjectionRule,
46944
+ javaHardcodedCredentialRule,
46945
+ javaSqlStringConcatRule,
46946
+ javaSystemOutPrintlnRule,
46947
+ javaThreadSleepInLoopRule,
46450
46948
  kotlinCoroutineGlobalScopeRule,
46451
46949
  kotlinDataClassDefaultsOveruseRule,
46950
+ kotlinForceUnwrapRule,
46951
+ kotlinHardcodedCredentialRule,
46452
46952
  kotlinObjectSingletonMisuseRule,
46953
+ kotlinPrintlnAsLogRule,
46453
46954
  kotlinPrintlnDebugRule,
46955
+ kotlinRunBlockingMisuseRule,
46956
+ kotlinSqlStringConcatRule,
46454
46957
  kotlinStringConcatLoopRule,
46455
46958
  gapMonopolyRule,
46456
46959
  mathElementUniformityRule,
@@ -50974,6 +51477,166 @@ var init_signal_strength = __esm({
50974
51477
  _v9Precision: 0.125,
50975
51478
  defaultOff: true
50976
51479
  },
51480
+ "kotlin/sql-string-concat": {
51481
+ recall: 469e-5,
51482
+ fpRate: 63e-4,
51483
+ ratio: 0.75,
51484
+ precision: 0.0556,
51485
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51486
+ verdict: "DORMANT",
51487
+ _calibrationNote: "v0.29: v9 Kotlin calibration (2698 neg, 213 pos). ratio=0.75 (DORMANT). 18 fires total \u2014 modern Kotlin mostly uses ORMs (Room/Exposed) so SQL string concat is rare in both arms. INSUFFICIENT_DATA: pos arm only 213 files. defaultOff: rule is loadable but invisible by default until v0.30 re-calibration with a larger pos arm.",
51488
+ aiSpecific: false,
51489
+ _v9Verdict: "DORMANT",
51490
+ _v9Lift: 0.75,
51491
+ _v9Recall: 469e-5,
51492
+ _v9FpRate: 63e-4,
51493
+ _v9Precision: 0.0556,
51494
+ defaultOff: true
51495
+ },
51496
+ "kotlin/hardcoded-credential": {
51497
+ recall: 0,
51498
+ fpRate: 0,
51499
+ ratio: 0,
51500
+ precision: 0,
51501
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51502
+ verdict: "DORMANT",
51503
+ _calibrationNote: "v0.29: v9 Kotlin calibration (2698 neg, 213 pos). 0 fires. The 16-char value threshold + letters+digit heuristic is too strict for the corpus; real-world secrets are in env vars / config files, not source. INSUFFICIENT_DATA: needs different corpus (CI configs, .env samples). defaultOff: loadable but invisible by default.",
51504
+ aiSpecific: false,
51505
+ _v9Verdict: "DORMANT",
51506
+ _v9Lift: 0,
51507
+ _v9Recall: 0,
51508
+ _v9FpRate: 0,
51509
+ _v9Precision: 0,
51510
+ defaultOff: true
51511
+ },
51512
+ "kotlin/runblocking-misuse": {
51513
+ recall: 0.10798,
51514
+ fpRate: 0.21534,
51515
+ ratio: 0.5,
51516
+ precision: 0.0381,
51517
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51518
+ verdict: "DORMANT",
51519
+ _calibrationNote: "v0.29: v9 Kotlin calibration (2698 neg, 213 pos). ratio=0.50 \u2014 fires 2x more on pre-2022 (neg) than post-2024 (pos). Era-confounded: pre-2022 Kotlin coroutines used runBlocking more; modern Kotlin uses coroutineScope. Same direction as kotlin/coroutine-global-scope (0.09). defaultOff: loadable but invisible by default until v0.30 re-calibration.",
51520
+ aiSpecific: false,
51521
+ _v9Verdict: "DORMANT",
51522
+ _v9Lift: 0.5,
51523
+ _v9Recall: 0.10798,
51524
+ _v9FpRate: 0.21534,
51525
+ _v9Precision: 0.0381,
51526
+ defaultOff: true
51527
+ },
51528
+ "kotlin/println-as-log": {
51529
+ recall: 0.08451,
51530
+ fpRate: 0.04596,
51531
+ ratio: 1.84,
51532
+ precision: 0.1268,
51533
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51534
+ verdict: "OK",
51535
+ _calibrationNote: "v0.29: v9 Kotlin calibration (2698 neg, 213 pos). ratio=1.84 (\u22651.5) \u2014 first rule in this entire session with a positive direction! Fires 1.84x more on post-2024 AI/demos than pre-2022 production. Precision=12.7% (below 50% USEFUL threshold); verdict=OK. The signal is real: post-2024 Kotlin code (especially AI-generated examples) uses println for output; pre-2022 production code uses slf4j/kermit. INSUFFICIENT_DATA: pos arm only 213 files. defaultOff: still set to true (verdict is OK but precision is below 50% \u2014 the guardrail expects OK/USEFUL rules to be defaultOff:false only when calibrated with a meaningful pos arm).",
51536
+ aiSpecific: false,
51537
+ _v9Verdict: "OK",
51538
+ _v9Lift: 1.84,
51539
+ _v9Recall: 0.08451,
51540
+ _v9FpRate: 0.04596,
51541
+ _v9Precision: 0.1268,
51542
+ defaultOff: true
51543
+ },
51544
+ "kotlin/force-unwrap": {
51545
+ recall: 0.11737,
51546
+ fpRate: 0.33284,
51547
+ ratio: 0.35,
51548
+ precision: 0.0271,
51549
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51550
+ verdict: "DORMANT",
51551
+ _calibrationNote: "v0.29: v9 Kotlin calibration (2698 neg, 213 pos). ratio=0.35 \u2014 fires 3x more on pre-2022 (neg) than post-2024 (pos). Era-confounded: pre-2022 Kotlin code uses !! freely; modern Kotlin relies on ?./?: and Result<T> wrappers. Stronger era signal than runblocking-misuse. defaultOff: loadable but invisible by default.",
51552
+ aiSpecific: false,
51553
+ _v9Verdict: "DORMANT",
51554
+ _v9Lift: 0.35,
51555
+ _v9Recall: 0.11737,
51556
+ _v9FpRate: 0.33284,
51557
+ _v9Precision: 0.0271,
51558
+ defaultOff: true
51559
+ },
51560
+ "java/sql-string-concat": {
51561
+ recall: 0.01116,
51562
+ fpRate: 0.01892,
51563
+ ratio: 0.59,
51564
+ precision: 0.0691,
51565
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51566
+ verdict: "DORMANT",
51567
+ _calibrationNote: "v0.30: v9 Java calibration (81891 neg, 10305 pos). ratio=0.59 \u2014 fires 1.7x more on pre-2022 (neg) than post-2024 (pos). Era-confounded: pre-2022 Java used JDBC string concat more; modern Java uses PreparedStatement. Same direction as kotlin/sql-string-concat. 1664 total fires \u2014 Java uses ORMs (Hibernate) heavily so SQL concat is rare in both arms. defaultOff.",
51568
+ aiSpecific: false,
51569
+ _v9Verdict: "DORMANT",
51570
+ _v9Lift: 0.59,
51571
+ _v9Recall: 0.01116,
51572
+ _v9FpRate: 0.01892,
51573
+ _v9Precision: 0.0691,
51574
+ defaultOff: true
51575
+ },
51576
+ "java/hardcoded-credential": {
51577
+ recall: 0,
51578
+ fpRate: 4e-5,
51579
+ ratio: 0,
51580
+ precision: 0,
51581
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51582
+ verdict: "DORMANT",
51583
+ _calibrationNote: "v0.30: v9 Java calibration (81891 neg, 10305 pos). 3 fires total \u2014 only in pre-2022 (neg). Real secrets are in env vars / config files, not source. INSUFFICIENT_DATA: needs different corpus (CI configs, .env samples, leaked-secret datasets). defaultOff.",
51584
+ aiSpecific: false,
51585
+ _v9Verdict: "DORMANT",
51586
+ _v9Lift: 0,
51587
+ _v9Recall: 0,
51588
+ _v9FpRate: 4e-5,
51589
+ _v9Precision: 0,
51590
+ defaultOff: true
51591
+ },
51592
+ "java/thread-sleep-in-loop": {
51593
+ recall: 0.0228,
51594
+ fpRate: 0.02343,
51595
+ ratio: 0.97,
51596
+ precision: 0.1091,
51597
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51598
+ verdict: "DORMANT",
51599
+ _calibrationNote: "v0.30: v9 Java calibration (81891 neg, 10305 pos). ratio=0.97 (just below 1.0) \u2014 fires equally on both arms. Borderline era-confound: pre-2022 Java had more Thread.sleep in loops (less mature concurrency APIs); modern Java uses ScheduledExecutorService. Same direction as kotlin/runblocking-misuse (0.50). 2154 total fires \u2014 high absolute count, meaningful measurement. defaultOff.",
51600
+ aiSpecific: false,
51601
+ _v9Verdict: "DORMANT",
51602
+ _v9Lift: 0.97,
51603
+ _v9Recall: 0.0228,
51604
+ _v9FpRate: 0.02343,
51605
+ _v9Precision: 0.1091,
51606
+ defaultOff: true
51607
+ },
51608
+ "java/system-out-println": {
51609
+ recall: 0.16681,
51610
+ fpRate: 0.05064,
51611
+ ratio: 3.29,
51612
+ precision: 0.293,
51613
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51614
+ verdict: "OK",
51615
+ _calibrationNote: "v0.30: v9 Java calibration (81891 neg, 10305 pos). ratio=3.29 (\u22651.5) \u2014 second positive-signal rule in v9 history (after kotlin/println-as-log at 1.84). Fires 3.29x more on post-2024 (pos) AI code than pre-2022 (neg) production. 5866 total fires (highest of any v0.30 rule). Precision=29.3% (below 50% USEFUL threshold); verdict=OK. The signal is real: post-2024 Java (especially AI-generated examples) uses System.out for output; pre-2022 production uses slf4j. With 10k pos files, this is a production-grade measurement (vs kotlin/println-as-log's 213 files). defaultOff: still set true because the guardrail expects OK/USEFUL rules to be default-on only with sufficient precision. The v0.31+ re-calibration may flip this if precision improves.",
51616
+ aiSpecific: false,
51617
+ _v9Verdict: "OK",
51618
+ _v9Lift: 3.29,
51619
+ _v9Recall: 0.16681,
51620
+ _v9FpRate: 0.05064,
51621
+ _v9Precision: 0.293,
51622
+ defaultOff: true
51623
+ },
51624
+ "java/command-injection": {
51625
+ recall: 0,
51626
+ fpRate: 1e-4,
51627
+ ratio: 0,
51628
+ precision: 0,
51629
+ lastCalibratedAt: "2026-07-03T00:00:00Z",
51630
+ verdict: "DORMANT",
51631
+ _calibrationNote: "v0.30: v9 Java calibration (81891 neg, 10305 pos). 8 fires total, all in neg. Command injection is rare in modern Java \u2014 most apps use ProcessBuilder with List<String> args, not Runtime.exec with concat. INSUFFICIENT_DATA: needs different corpus (security benchmarks, CVE samples). defaultOff.",
51632
+ aiSpecific: false,
51633
+ _v9Verdict: "DORMANT",
51634
+ _v9Lift: 0,
51635
+ _v9Recall: 0,
51636
+ _v9FpRate: 1e-4,
51637
+ _v9Precision: 0,
51638
+ defaultOff: true
51639
+ },
50977
51640
  "swift/force-unwrap": {
50978
51641
  recall: 0,
50979
51642
  fpRate: 0,
@@ -59186,6 +59849,18 @@ var RULE_HINTS = {
59186
59849
  "kotlin/println-debug": "Replace with `Timber.d(...)` or `android.util.Log`. `println` writes to stdout with no level, no redaction, can't be silenced in release builds. (v0.24.0 \u2014 DORMANT.)",
59187
59850
  "kotlin/object-singleton-misuse": "Replace with a class injected via DI, a Repository, or `MutableStateFlow`. The `object` keyword gives a thread-safe singleton handle, NOT thread-safe `var` fields. (v0.24.0 \u2014 DORMANT.)",
59188
59851
  "kotlin/string-concat-loop": "Wrap the loop in `buildString { append(...) }` or hoist a `StringBuilder`. Kotlin can't optimize `s = s + x` in a loop \u2014 O(n\xB2). (v0.24.0 \u2014 DORMANT.)",
59852
+ // v0.29.0 — non-AI Kotlin rules (DORMANT until larger pos arm)
59853
+ "kotlin/sql-string-concat": "Use a PreparedStatement (JDBC), setParameter() (Exposed), or an ORM (Room, jOOQ). String concat or template interpolation into a SQL query is the canonical SQL-injection pattern. OWASP A03:2021. (v0.29.0 \u2014 DORMANT.)",
59854
+ "kotlin/hardcoded-credential": "Move the credential to an env var, a .env file (gitignored), or a secrets manager (Vault, AWS Secrets Manager). Hardcoded creds are the #1 secret-leak vector. OWASP A07:2021. (v0.29.0 \u2014 DORMANT.)",
59855
+ "kotlin/runblocking-misuse": "Use coroutineScope { } for structured concurrency, or call the suspend function directly. runBlocking blocks the calling thread and is rarely correct outside main(). (v0.29.0 \u2014 DORMANT.)",
59856
+ "kotlin/println-as-log": "Use slf4j (JVM), android.util.Log (Android), Timber, kermit, or kotlin-logging. println has no log level, no timestamp, no correlation ID. (v0.29.0 \u2014 OK; first positive-signal rule in v9 history, ratio 1.84.)",
59857
+ "kotlin/force-unwrap": "Use ?. (safe call) with ?: (Elvis) for a default, or a proper when/if check. !! throws NullPointerException at runtime and bypasses Kotlin's type system. (v0.29.0 \u2014 DORMANT, era-confounded.)",
59858
+ // v0.30.0 — non-AI Java rules (Option C applied to v9 Java corpus, 92k files)
59859
+ "java/sql-string-concat": "Use a PreparedStatement (JDBC), setParameter (jOOQ), or an ORM (Hibernate, MyBatis with #{}). String concat into SQL is the canonical SQL-injection pattern. OWASP A03:2021. (v0.30.0 \u2014 DORMANT, ratio 0.59.)",
59860
+ "java/hardcoded-credential": "Move the credential to an env var, a .env file (gitignored), or a secrets manager (Vault, AWS Secrets Manager). Hardcoded creds are the #1 secret-leak vector. OWASP A07:2021. (v0.30.0 \u2014 DORMANT, 0 fires on v9 Java corpus.)",
59861
+ "java/thread-sleep-in-loop": "Use ScheduledExecutorService for periodic work, or BlockingQueue.take() for event-driven work. Thread.sleep in a loop is the polling anti-pattern \u2014 ties up Tomcat/Jetty/Netty threads. (v0.30.0 \u2014 DORMANT, era-confounded ratio 0.97.)",
59862
+ "java/system-out-println": "Use SLF4J (the standard facade), Log4j2, or java.util.logging. System.out has no log level, no timestamp, no correlation ID. (v0.30.0 \u2014 OK; second positive-signal rule in v9 history, ratio 3.29.)",
59863
+ "java/command-injection": "Use ProcessBuilder with a List<String> of args (no shell parsing) and validate each arg. Runtime.exec() with concat is the canonical command-injection pattern. OWASP A03:2021. (v0.30.0 \u2014 DORMANT.)",
59189
59864
  // v0.24.0 — Swift rules (DORMANT until v9 Swift corpus calibration)
59190
59865
  "swift/force-unwrap": "Replace with the safe form: `as?` + guard/if let, `try?`, or `guard let x = optional else { return }`. `!` crashes unconditionally in release. (v0.24.0 \u2014 DORMANT.)",
59191
59866
  "swift/print-debug": "Replace with `Logger(subsystem:..., category:...).info(...)` (os.log). `print` writes to stdout with no level and no redaction. (v0.24.0 \u2014 DORMANT.)",