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/engine/worker.cjs +589 -6
- package/dist/engine/worker.js +589 -6
- package/dist/index.cjs +686 -11
- package/dist/index.js +686 -11
- package/package.json +1 -1
package/dist/engine/worker.cjs
CHANGED
|
@@ -37000,6 +37000,211 @@ var goStructTagInconsistencyRule = createRule({
|
|
|
37000
37000
|
}
|
|
37001
37001
|
});
|
|
37002
37002
|
|
|
37003
|
+
// src/rules/java/command-injection.ts
|
|
37004
|
+
var COMMAND_INVOCATION_REGEX = /\b(?:Runtime\.exec|Runtime\.getRuntime\(\)\.exec|ProcessBuilder)\s*\(/;
|
|
37005
|
+
var STRING_CONCAT_REGEX = /["'][^"']*["']\s*\+/;
|
|
37006
|
+
var javaCommandInjectionRule = createRule({
|
|
37007
|
+
id: "java/command-injection",
|
|
37008
|
+
category: "security",
|
|
37009
|
+
severity: "high",
|
|
37010
|
+
aiSpecific: false,
|
|
37011
|
+
description: "Runtime.exec() or ProcessBuilder with string concat \u2014 use List<String> args + validation",
|
|
37012
|
+
create(_context) {
|
|
37013
|
+
return {};
|
|
37014
|
+
},
|
|
37015
|
+
analyze(_context, facts) {
|
|
37016
|
+
const issues = [];
|
|
37017
|
+
const source = facts.v2?._source;
|
|
37018
|
+
if (!source) return issues;
|
|
37019
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37020
|
+
const lines = source.split("\n");
|
|
37021
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37022
|
+
const line = lines[i];
|
|
37023
|
+
if (!COMMAND_INVOCATION_REGEX.test(line)) continue;
|
|
37024
|
+
if (!STRING_CONCAT_REGEX.test(line)) continue;
|
|
37025
|
+
issues.push({
|
|
37026
|
+
ruleId: "java/command-injection",
|
|
37027
|
+
category: "security",
|
|
37028
|
+
severity: "high",
|
|
37029
|
+
aiSpecific: false,
|
|
37030
|
+
message: `Command invocation with string concat at line ${i + 1}`,
|
|
37031
|
+
line: i + 1,
|
|
37032
|
+
column: 1,
|
|
37033
|
+
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)."
|
|
37034
|
+
});
|
|
37035
|
+
}
|
|
37036
|
+
return issues;
|
|
37037
|
+
}
|
|
37038
|
+
});
|
|
37039
|
+
|
|
37040
|
+
// src/rules/java/hardcoded-credential.ts
|
|
37041
|
+
var KEY_REGEX = /\b(api[_-]?key|apikey|secret|token|password|auth|access[_-]?key|client[_-]?secret|private[_-]?key)\b\s*[=:]/i;
|
|
37042
|
+
var VALUE_REGEX = /["']([A-Za-z0-9_\-+/=.@*!]{16,})["']/;
|
|
37043
|
+
var FALSE_POSITIVES = /* @__PURE__ */ new Set([
|
|
37044
|
+
"passwordless",
|
|
37045
|
+
"tokenize",
|
|
37046
|
+
"tokenizer",
|
|
37047
|
+
"authorizationrequired",
|
|
37048
|
+
"authenticated",
|
|
37049
|
+
"authenticatortoken",
|
|
37050
|
+
"authtoken",
|
|
37051
|
+
"placeholder",
|
|
37052
|
+
"changeme"
|
|
37053
|
+
]);
|
|
37054
|
+
var javaHardcodedCredentialRule = createRule({
|
|
37055
|
+
id: "java/hardcoded-credential",
|
|
37056
|
+
category: "security",
|
|
37057
|
+
severity: "high",
|
|
37058
|
+
aiSpecific: false,
|
|
37059
|
+
description: "Hardcoded credential literal \u2014 use env vars or a secrets manager",
|
|
37060
|
+
create(_context) {
|
|
37061
|
+
return {};
|
|
37062
|
+
},
|
|
37063
|
+
analyze(_context, facts) {
|
|
37064
|
+
const issues = [];
|
|
37065
|
+
const source = facts.v2?._source;
|
|
37066
|
+
if (!source) return issues;
|
|
37067
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37068
|
+
if (/\/test\//i.test(facts.filePath) || /\/src\/test\//i.test(facts.filePath)) return issues;
|
|
37069
|
+
const lines = source.split("\n");
|
|
37070
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37071
|
+
const line = lines[i];
|
|
37072
|
+
if (!KEY_REGEX.test(line)) continue;
|
|
37073
|
+
const valueMatch = VALUE_REGEX.exec(line);
|
|
37074
|
+
if (!valueMatch) continue;
|
|
37075
|
+
const value = valueMatch[1];
|
|
37076
|
+
if (FALSE_POSITIVES.has(value.toLowerCase())) continue;
|
|
37077
|
+
if (!/[a-zA-Z]/.test(value) || !/[0-9]/.test(value)) continue;
|
|
37078
|
+
if (value.startsWith("$")) continue;
|
|
37079
|
+
issues.push({
|
|
37080
|
+
ruleId: "java/hardcoded-credential",
|
|
37081
|
+
category: "security",
|
|
37082
|
+
severity: "high",
|
|
37083
|
+
aiSpecific: false,
|
|
37084
|
+
message: `Hardcoded credential at line ${i + 1}`,
|
|
37085
|
+
line: i + 1,
|
|
37086
|
+
column: 1,
|
|
37087
|
+
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)."
|
|
37088
|
+
});
|
|
37089
|
+
}
|
|
37090
|
+
return issues;
|
|
37091
|
+
}
|
|
37092
|
+
});
|
|
37093
|
+
|
|
37094
|
+
// src/rules/java/sql-string-concat.ts
|
|
37095
|
+
var SQL_KEYWORD_REGEX = /\b(?:SELECT|INSERT\s+INTO|UPDATE|DELETE\s+FROM|CREATE\s+TABLE|DROP\s+TABLE|ALTER\s+TABLE)\b/i;
|
|
37096
|
+
var UNSAFE_REGEX = /\+/;
|
|
37097
|
+
var SAFE_REGEX = /(?:PreparedStatement|setParameter|setString|setInt|setLong|createQuery.*:.*\b(?:set|bind)|:name\b|\?\s*,)/;
|
|
37098
|
+
var javaSqlStringConcatRule = createRule({
|
|
37099
|
+
id: "java/sql-string-concat",
|
|
37100
|
+
category: "security",
|
|
37101
|
+
severity: "high",
|
|
37102
|
+
aiSpecific: false,
|
|
37103
|
+
description: "SQL query built via string concat \u2014 use PreparedStatement or setParameter()",
|
|
37104
|
+
create(_context) {
|
|
37105
|
+
return {};
|
|
37106
|
+
},
|
|
37107
|
+
analyze(_context, facts) {
|
|
37108
|
+
const issues = [];
|
|
37109
|
+
const source = facts.v2?._source;
|
|
37110
|
+
if (!source) return issues;
|
|
37111
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37112
|
+
const lines = source.split("\n");
|
|
37113
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37114
|
+
const line = lines[i];
|
|
37115
|
+
if (!SQL_KEYWORD_REGEX.test(line)) continue;
|
|
37116
|
+
if (!UNSAFE_REGEX.test(line)) continue;
|
|
37117
|
+
if (SAFE_REGEX.test(line)) continue;
|
|
37118
|
+
issues.push({
|
|
37119
|
+
ruleId: "java/sql-string-concat",
|
|
37120
|
+
category: "security",
|
|
37121
|
+
severity: "high",
|
|
37122
|
+
aiSpecific: false,
|
|
37123
|
+
message: `SQL query built via string concat at line ${i + 1}`,
|
|
37124
|
+
line: i + 1,
|
|
37125
|
+
column: 1,
|
|
37126
|
+
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).'
|
|
37127
|
+
});
|
|
37128
|
+
}
|
|
37129
|
+
return issues;
|
|
37130
|
+
}
|
|
37131
|
+
});
|
|
37132
|
+
|
|
37133
|
+
// src/rules/java/system-out-println.ts
|
|
37134
|
+
var SYSTEM_OUT_REGEX = /\bSystem\.out\.println\s*\(/g;
|
|
37135
|
+
var 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)/;
|
|
37136
|
+
var javaSystemOutPrintlnRule = createRule({
|
|
37137
|
+
id: "java/system-out-println",
|
|
37138
|
+
category: "logic",
|
|
37139
|
+
severity: "low",
|
|
37140
|
+
aiSpecific: false,
|
|
37141
|
+
description: "System.out.println() used for logging \u2014 use SLF4J, Log4j2, or java.util.logging",
|
|
37142
|
+
create(_context) {
|
|
37143
|
+
return {};
|
|
37144
|
+
},
|
|
37145
|
+
analyze(_context, facts) {
|
|
37146
|
+
const issues = [];
|
|
37147
|
+
const source = facts.v2?._source;
|
|
37148
|
+
if (!source) return issues;
|
|
37149
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37150
|
+
if (/\/test\//i.test(facts.filePath) || /\/src\/test\//i.test(facts.filePath)) return issues;
|
|
37151
|
+
if (REAL_LOGGING_IMPORT_REGEX.test(source)) return issues;
|
|
37152
|
+
let m;
|
|
37153
|
+
SYSTEM_OUT_REGEX.lastIndex = 0;
|
|
37154
|
+
while ((m = SYSTEM_OUT_REGEX.exec(source)) !== null) {
|
|
37155
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37156
|
+
issues.push({
|
|
37157
|
+
ruleId: "java/system-out-println",
|
|
37158
|
+
category: "logic",
|
|
37159
|
+
severity: "low",
|
|
37160
|
+
aiSpecific: false,
|
|
37161
|
+
message: `System.out.println() at line ${line}`,
|
|
37162
|
+
line,
|
|
37163
|
+
column: 1,
|
|
37164
|
+
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."
|
|
37165
|
+
});
|
|
37166
|
+
}
|
|
37167
|
+
return issues;
|
|
37168
|
+
}
|
|
37169
|
+
});
|
|
37170
|
+
|
|
37171
|
+
// src/rules/java/thread-sleep-in-loop.ts
|
|
37172
|
+
var THREAD_SLEEP_REGEX = /\bThread\.sleep\s*\(/g;
|
|
37173
|
+
var javaThreadSleepInLoopRule = createRule({
|
|
37174
|
+
id: "java/thread-sleep-in-loop",
|
|
37175
|
+
category: "perf",
|
|
37176
|
+
severity: "medium",
|
|
37177
|
+
aiSpecific: false,
|
|
37178
|
+
description: "Thread.sleep() in a loop \u2014 use ScheduledExecutorService or BlockingQueue",
|
|
37179
|
+
create(_context) {
|
|
37180
|
+
return {};
|
|
37181
|
+
},
|
|
37182
|
+
analyze(_context, facts) {
|
|
37183
|
+
const issues = [];
|
|
37184
|
+
const source = facts.v2?._source;
|
|
37185
|
+
if (!source) return issues;
|
|
37186
|
+
if (!/\.java$/i.test(facts.filePath)) return issues;
|
|
37187
|
+
if (!/\bThread\.sleep\s*\(/.test(source)) return issues;
|
|
37188
|
+
if (!/\b(?:for|while|do)\b/.test(source)) return issues;
|
|
37189
|
+
let m;
|
|
37190
|
+
THREAD_SLEEP_REGEX.lastIndex = 0;
|
|
37191
|
+
while ((m = THREAD_SLEEP_REGEX.exec(source)) !== null) {
|
|
37192
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37193
|
+
issues.push({
|
|
37194
|
+
ruleId: "java/thread-sleep-in-loop",
|
|
37195
|
+
category: "perf",
|
|
37196
|
+
severity: "medium",
|
|
37197
|
+
aiSpecific: false,
|
|
37198
|
+
message: `Thread.sleep() at line ${line}`,
|
|
37199
|
+
line,
|
|
37200
|
+
column: 1,
|
|
37201
|
+
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.'
|
|
37202
|
+
});
|
|
37203
|
+
}
|
|
37204
|
+
return issues;
|
|
37205
|
+
}
|
|
37206
|
+
});
|
|
37207
|
+
|
|
37003
37208
|
// src/rules/kotlin/coroutine-global-scope.ts
|
|
37004
37209
|
var GLOBAL_SCOPE_REGEX = /GlobalScope\s*\.\s*(?:launch|async|runBlocking)\s*[({]/g;
|
|
37005
37210
|
var kotlinCoroutineGlobalScopeRule = createRule({
|
|
@@ -37092,6 +37297,101 @@ var kotlinDataClassDefaultsOveruseRule = createRule({
|
|
|
37092
37297
|
}
|
|
37093
37298
|
});
|
|
37094
37299
|
|
|
37300
|
+
// src/rules/kotlin/force-unwrap.ts
|
|
37301
|
+
var FORCE_UNWRAP_REGEX = /!!(?=\s*[.\)}\};,\n\[])/g;
|
|
37302
|
+
var kotlinForceUnwrapRule = createRule({
|
|
37303
|
+
id: "kotlin/force-unwrap",
|
|
37304
|
+
category: "logic",
|
|
37305
|
+
severity: "medium",
|
|
37306
|
+
aiSpecific: false,
|
|
37307
|
+
description: "!! force-unwrap \u2014 use ?. (safe call) or a proper null check",
|
|
37308
|
+
create(_context) {
|
|
37309
|
+
return {};
|
|
37310
|
+
},
|
|
37311
|
+
analyze(_context, facts) {
|
|
37312
|
+
const issues = [];
|
|
37313
|
+
const source = facts.v2?._source;
|
|
37314
|
+
if (!source) return issues;
|
|
37315
|
+
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37316
|
+
let m;
|
|
37317
|
+
FORCE_UNWRAP_REGEX.lastIndex = 0;
|
|
37318
|
+
while ((m = FORCE_UNWRAP_REGEX.exec(source)) !== null) {
|
|
37319
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37320
|
+
const lineStart = source.lastIndexOf("\n", m.index) + 1;
|
|
37321
|
+
const lineText = source.slice(lineStart, m.index);
|
|
37322
|
+
const quoteCount = (lineText.match(/"/g) || []).length;
|
|
37323
|
+
if (quoteCount % 2 === 1) continue;
|
|
37324
|
+
issues.push({
|
|
37325
|
+
ruleId: "kotlin/force-unwrap",
|
|
37326
|
+
category: "logic",
|
|
37327
|
+
severity: "medium",
|
|
37328
|
+
aiSpecific: false,
|
|
37329
|
+
message: `!! force-unwrap at line ${line}`,
|
|
37330
|
+
line,
|
|
37331
|
+
column: m.index - lineStart + 1,
|
|
37332
|
+
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."
|
|
37333
|
+
});
|
|
37334
|
+
}
|
|
37335
|
+
return issues;
|
|
37336
|
+
}
|
|
37337
|
+
});
|
|
37338
|
+
|
|
37339
|
+
// src/rules/kotlin/hardcoded-credential.ts
|
|
37340
|
+
var KEY_REGEX2 = /\b(api[_-]?key|apikey|secret|token|password|auth|access[_-]?key|client[_-]?secret|private[_-]?key)\b\s*[=:]/i;
|
|
37341
|
+
var VALUE_REGEX2 = /["']([A-Za-z0-9_\-+/=.@*!]{16,})["']/;
|
|
37342
|
+
var FALSE_POSITIVES2 = /* @__PURE__ */ new Set([
|
|
37343
|
+
"passwordless",
|
|
37344
|
+
"tokenize",
|
|
37345
|
+
"tokenizer",
|
|
37346
|
+
"authorizationrequired",
|
|
37347
|
+
"authenticated",
|
|
37348
|
+
"authenticatortoken",
|
|
37349
|
+
"authtoken",
|
|
37350
|
+
"placeholder",
|
|
37351
|
+
// common in test fixtures
|
|
37352
|
+
"changeme"
|
|
37353
|
+
// placeholder, but still suspicious — kept for review
|
|
37354
|
+
]);
|
|
37355
|
+
var kotlinHardcodedCredentialRule = createRule({
|
|
37356
|
+
id: "kotlin/hardcoded-credential",
|
|
37357
|
+
category: "security",
|
|
37358
|
+
severity: "high",
|
|
37359
|
+
aiSpecific: false,
|
|
37360
|
+
description: "Hardcoded credential literal \u2014 use env vars or a secrets manager",
|
|
37361
|
+
create(_context) {
|
|
37362
|
+
return {};
|
|
37363
|
+
},
|
|
37364
|
+
analyze(_context, facts) {
|
|
37365
|
+
const issues = [];
|
|
37366
|
+
const source = facts.v2?._source;
|
|
37367
|
+
if (!source) return issues;
|
|
37368
|
+
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37369
|
+
const lines = source.split("\n");
|
|
37370
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37371
|
+
const line = lines[i];
|
|
37372
|
+
if (!KEY_REGEX2.test(line)) continue;
|
|
37373
|
+
const valueMatch = VALUE_REGEX2.exec(line);
|
|
37374
|
+
if (!valueMatch) continue;
|
|
37375
|
+
const value = valueMatch[1];
|
|
37376
|
+
if (FALSE_POSITIVES2.has(value.toLowerCase())) continue;
|
|
37377
|
+
if (!/[a-zA-Z]/.test(value) || !/[0-9]/.test(value)) continue;
|
|
37378
|
+
if (value.startsWith("$")) continue;
|
|
37379
|
+
if (/\/test\//i.test(facts.filePath) || /\.test\.kts?$/i.test(facts.filePath)) continue;
|
|
37380
|
+
issues.push({
|
|
37381
|
+
ruleId: "kotlin/hardcoded-credential",
|
|
37382
|
+
category: "security",
|
|
37383
|
+
severity: "high",
|
|
37384
|
+
aiSpecific: false,
|
|
37385
|
+
message: `Hardcoded credential at line ${i + 1}`,
|
|
37386
|
+
line: i + 1,
|
|
37387
|
+
column: 1,
|
|
37388
|
+
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)."
|
|
37389
|
+
});
|
|
37390
|
+
}
|
|
37391
|
+
return issues;
|
|
37392
|
+
}
|
|
37393
|
+
});
|
|
37394
|
+
|
|
37095
37395
|
// src/rules/kotlin/object-singleton-misuse.ts
|
|
37096
37396
|
var OBJECT_DECL_REGEX = /\bobject\s+(?!\w*Companion\b)(\w+)\s*\{/g;
|
|
37097
37397
|
var kotlinObjectSingletonMisuseRule = createRule({
|
|
@@ -37142,8 +37442,46 @@ var kotlinObjectSingletonMisuseRule = createRule({
|
|
|
37142
37442
|
}
|
|
37143
37443
|
});
|
|
37144
37444
|
|
|
37445
|
+
// src/rules/kotlin/println-as-log.ts
|
|
37446
|
+
var PRINTLN_REGEX = /\bprintln\s*\(/g;
|
|
37447
|
+
var 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)/;
|
|
37448
|
+
var kotlinPrintlnAsLogRule = createRule({
|
|
37449
|
+
id: "kotlin/println-as-log",
|
|
37450
|
+
category: "logic",
|
|
37451
|
+
severity: "low",
|
|
37452
|
+
aiSpecific: false,
|
|
37453
|
+
description: "println() used for logging \u2014 use slf4j, kermit, or android.util.Log",
|
|
37454
|
+
create(_context) {
|
|
37455
|
+
return {};
|
|
37456
|
+
},
|
|
37457
|
+
analyze(_context, facts) {
|
|
37458
|
+
const issues = [];
|
|
37459
|
+
const source = facts.v2?._source;
|
|
37460
|
+
if (!source) return issues;
|
|
37461
|
+
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37462
|
+
if (/\/test\//i.test(facts.filePath) || /\.test\.kts?$/i.test(facts.filePath)) return issues;
|
|
37463
|
+
if (REAL_LOGGING_IMPORT_REGEX2.test(source)) return issues;
|
|
37464
|
+
let m;
|
|
37465
|
+
PRINTLN_REGEX.lastIndex = 0;
|
|
37466
|
+
while ((m = PRINTLN_REGEX.exec(source)) !== null) {
|
|
37467
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37468
|
+
issues.push({
|
|
37469
|
+
ruleId: "kotlin/println-as-log",
|
|
37470
|
+
category: "logic",
|
|
37471
|
+
severity: "low",
|
|
37472
|
+
aiSpecific: false,
|
|
37473
|
+
message: `println() as logger at line ${line}`,
|
|
37474
|
+
line,
|
|
37475
|
+
column: 1,
|
|
37476
|
+
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."
|
|
37477
|
+
});
|
|
37478
|
+
}
|
|
37479
|
+
return issues;
|
|
37480
|
+
}
|
|
37481
|
+
});
|
|
37482
|
+
|
|
37145
37483
|
// src/rules/kotlin/println-debug.ts
|
|
37146
|
-
var
|
|
37484
|
+
var PRINTLN_REGEX2 = /^\s*println\s*\(/gm;
|
|
37147
37485
|
var DEFAULT_THRESHOLD = 1;
|
|
37148
37486
|
var kotlinPrintlnDebugRule = createRule({
|
|
37149
37487
|
id: "kotlin/println-debug",
|
|
@@ -37161,8 +37499,8 @@ var kotlinPrintlnDebugRule = createRule({
|
|
|
37161
37499
|
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37162
37500
|
const matches = [];
|
|
37163
37501
|
let m;
|
|
37164
|
-
|
|
37165
|
-
while ((m =
|
|
37502
|
+
PRINTLN_REGEX2.lastIndex = 0;
|
|
37503
|
+
while ((m = PRINTLN_REGEX2.exec(source)) !== null) {
|
|
37166
37504
|
matches.push(m.index);
|
|
37167
37505
|
}
|
|
37168
37506
|
if (matches.length <= context.threshold) return issues;
|
|
@@ -37185,8 +37523,83 @@ var kotlinPrintlnDebugRule = createRule({
|
|
|
37185
37523
|
}
|
|
37186
37524
|
});
|
|
37187
37525
|
|
|
37526
|
+
// src/rules/kotlin/runblocking-misuse.ts
|
|
37527
|
+
var RUN_BLOCKING_REGEX = /\brunBlocking\s*[({]/g;
|
|
37528
|
+
var kotlinRunBlockingMisuseRule = createRule({
|
|
37529
|
+
id: "kotlin/runblocking-misuse",
|
|
37530
|
+
category: "perf",
|
|
37531
|
+
severity: "medium",
|
|
37532
|
+
aiSpecific: false,
|
|
37533
|
+
description: "runBlocking { ... } \u2014 blocks the calling thread; use coroutineScope {} or call suspend fun directly",
|
|
37534
|
+
create(_context) {
|
|
37535
|
+
return {};
|
|
37536
|
+
},
|
|
37537
|
+
analyze(_context, facts) {
|
|
37538
|
+
const issues = [];
|
|
37539
|
+
const source = facts.v2?._source;
|
|
37540
|
+
if (!source) return issues;
|
|
37541
|
+
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37542
|
+
if (/\bfun\s+main\s*\(/.test(source)) return issues;
|
|
37543
|
+
let m;
|
|
37544
|
+
RUN_BLOCKING_REGEX.lastIndex = 0;
|
|
37545
|
+
while ((m = RUN_BLOCKING_REGEX.exec(source)) !== null) {
|
|
37546
|
+
const line = source.slice(0, m.index).split("\n").length;
|
|
37547
|
+
issues.push({
|
|
37548
|
+
ruleId: "kotlin/runblocking-misuse",
|
|
37549
|
+
category: "perf",
|
|
37550
|
+
severity: "medium",
|
|
37551
|
+
aiSpecific: false,
|
|
37552
|
+
message: `runBlocking { ... } at line ${line}`,
|
|
37553
|
+
line,
|
|
37554
|
+
column: 1,
|
|
37555
|
+
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.'
|
|
37556
|
+
});
|
|
37557
|
+
}
|
|
37558
|
+
return issues;
|
|
37559
|
+
}
|
|
37560
|
+
});
|
|
37561
|
+
|
|
37562
|
+
// src/rules/kotlin/sql-string-concat.ts
|
|
37563
|
+
var SQL_KEYWORD_REGEX2 = /\b(?:SELECT|INSERT\s+INTO|UPDATE|DELETE\s+FROM|CREATE\s+TABLE|DROP\s+TABLE|ALTER\s+TABLE)\b/i;
|
|
37564
|
+
var UNSAFE_REGEX2 = /(?:\+|\$\{)/;
|
|
37565
|
+
var SAFE_REGEX2 = /(?:PreparedStatement|setParameter|setString|setInt|setLong|bind|:name|:\\?\\?|\?\\s*,)/;
|
|
37566
|
+
var kotlinSqlStringConcatRule = createRule({
|
|
37567
|
+
id: "kotlin/sql-string-concat",
|
|
37568
|
+
category: "security",
|
|
37569
|
+
severity: "high",
|
|
37570
|
+
aiSpecific: false,
|
|
37571
|
+
description: "SQL query built via string concat / template \u2014 use PreparedStatement or setParameter()",
|
|
37572
|
+
create(_context) {
|
|
37573
|
+
return {};
|
|
37574
|
+
},
|
|
37575
|
+
analyze(_context, facts) {
|
|
37576
|
+
const issues = [];
|
|
37577
|
+
const source = facts.v2?._source;
|
|
37578
|
+
if (!source) return issues;
|
|
37579
|
+
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37580
|
+
const lines = source.split("\n");
|
|
37581
|
+
for (let i = 0; i < lines.length; i++) {
|
|
37582
|
+
const line = lines[i];
|
|
37583
|
+
if (!SQL_KEYWORD_REGEX2.test(line)) continue;
|
|
37584
|
+
if (!UNSAFE_REGEX2.test(line)) continue;
|
|
37585
|
+
if (SAFE_REGEX2.test(line)) continue;
|
|
37586
|
+
issues.push({
|
|
37587
|
+
ruleId: "kotlin/sql-string-concat",
|
|
37588
|
+
category: "security",
|
|
37589
|
+
severity: "high",
|
|
37590
|
+
aiSpecific: false,
|
|
37591
|
+
message: `SQL query built via string concat/template at line ${i + 1}`,
|
|
37592
|
+
line: i + 1,
|
|
37593
|
+
column: 1,
|
|
37594
|
+
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).'
|
|
37595
|
+
});
|
|
37596
|
+
}
|
|
37597
|
+
return issues;
|
|
37598
|
+
}
|
|
37599
|
+
});
|
|
37600
|
+
|
|
37188
37601
|
// src/rules/kotlin/string-concat-loop.ts
|
|
37189
|
-
var
|
|
37602
|
+
var STRING_CONCAT_REGEX2 = /\b(\w+)\s*=\s*\1\s*\+\s*[^;}]+[;}\n]/g;
|
|
37190
37603
|
var kotlinStringConcatLoopRule = createRule({
|
|
37191
37604
|
id: "kotlin/string-concat-loop",
|
|
37192
37605
|
category: "perf",
|
|
@@ -37203,8 +37616,8 @@ var kotlinStringConcatLoopRule = createRule({
|
|
|
37203
37616
|
if (!/\.kts?$/i.test(facts.filePath)) return issues;
|
|
37204
37617
|
if (!/\b(?:for|while|repeat|forEach)\b/.test(source)) return issues;
|
|
37205
37618
|
let m;
|
|
37206
|
-
|
|
37207
|
-
while ((m =
|
|
37619
|
+
STRING_CONCAT_REGEX2.lastIndex = 0;
|
|
37620
|
+
while ((m = STRING_CONCAT_REGEX2.exec(source)) !== null) {
|
|
37208
37621
|
const line = source.slice(0, m.index).split("\n").length;
|
|
37209
37622
|
const lineText = source.slice(0, m.index).split("\n").pop() ?? "";
|
|
37210
37623
|
if (/\.append\s*\(/.test(lineText)) continue;
|
|
@@ -42745,10 +43158,20 @@ var builtinRules = [
|
|
|
42745
43158
|
goErrorWrapWithoutContextRule,
|
|
42746
43159
|
goNilSliceVsEmptyRule,
|
|
42747
43160
|
goStructTagInconsistencyRule,
|
|
43161
|
+
javaCommandInjectionRule,
|
|
43162
|
+
javaHardcodedCredentialRule,
|
|
43163
|
+
javaSqlStringConcatRule,
|
|
43164
|
+
javaSystemOutPrintlnRule,
|
|
43165
|
+
javaThreadSleepInLoopRule,
|
|
42748
43166
|
kotlinCoroutineGlobalScopeRule,
|
|
42749
43167
|
kotlinDataClassDefaultsOveruseRule,
|
|
43168
|
+
kotlinForceUnwrapRule,
|
|
43169
|
+
kotlinHardcodedCredentialRule,
|
|
42750
43170
|
kotlinObjectSingletonMisuseRule,
|
|
43171
|
+
kotlinPrintlnAsLogRule,
|
|
42751
43172
|
kotlinPrintlnDebugRule,
|
|
43173
|
+
kotlinRunBlockingMisuseRule,
|
|
43174
|
+
kotlinSqlStringConcatRule,
|
|
42752
43175
|
kotlinStringConcatLoopRule,
|
|
42753
43176
|
gapMonopolyRule,
|
|
42754
43177
|
mathElementUniformityRule,
|
|
@@ -44967,6 +45390,166 @@ var signal_strength_default = {
|
|
|
44967
45390
|
_v9Precision: 0.125,
|
|
44968
45391
|
defaultOff: true
|
|
44969
45392
|
},
|
|
45393
|
+
"kotlin/sql-string-concat": {
|
|
45394
|
+
recall: 469e-5,
|
|
45395
|
+
fpRate: 63e-4,
|
|
45396
|
+
ratio: 0.75,
|
|
45397
|
+
precision: 0.0556,
|
|
45398
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45399
|
+
verdict: "DORMANT",
|
|
45400
|
+
_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.",
|
|
45401
|
+
aiSpecific: false,
|
|
45402
|
+
_v9Verdict: "DORMANT",
|
|
45403
|
+
_v9Lift: 0.75,
|
|
45404
|
+
_v9Recall: 469e-5,
|
|
45405
|
+
_v9FpRate: 63e-4,
|
|
45406
|
+
_v9Precision: 0.0556,
|
|
45407
|
+
defaultOff: true
|
|
45408
|
+
},
|
|
45409
|
+
"kotlin/hardcoded-credential": {
|
|
45410
|
+
recall: 0,
|
|
45411
|
+
fpRate: 0,
|
|
45412
|
+
ratio: 0,
|
|
45413
|
+
precision: 0,
|
|
45414
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45415
|
+
verdict: "DORMANT",
|
|
45416
|
+
_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.",
|
|
45417
|
+
aiSpecific: false,
|
|
45418
|
+
_v9Verdict: "DORMANT",
|
|
45419
|
+
_v9Lift: 0,
|
|
45420
|
+
_v9Recall: 0,
|
|
45421
|
+
_v9FpRate: 0,
|
|
45422
|
+
_v9Precision: 0,
|
|
45423
|
+
defaultOff: true
|
|
45424
|
+
},
|
|
45425
|
+
"kotlin/runblocking-misuse": {
|
|
45426
|
+
recall: 0.10798,
|
|
45427
|
+
fpRate: 0.21534,
|
|
45428
|
+
ratio: 0.5,
|
|
45429
|
+
precision: 0.0381,
|
|
45430
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45431
|
+
verdict: "DORMANT",
|
|
45432
|
+
_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.",
|
|
45433
|
+
aiSpecific: false,
|
|
45434
|
+
_v9Verdict: "DORMANT",
|
|
45435
|
+
_v9Lift: 0.5,
|
|
45436
|
+
_v9Recall: 0.10798,
|
|
45437
|
+
_v9FpRate: 0.21534,
|
|
45438
|
+
_v9Precision: 0.0381,
|
|
45439
|
+
defaultOff: true
|
|
45440
|
+
},
|
|
45441
|
+
"kotlin/println-as-log": {
|
|
45442
|
+
recall: 0.08451,
|
|
45443
|
+
fpRate: 0.04596,
|
|
45444
|
+
ratio: 1.84,
|
|
45445
|
+
precision: 0.1268,
|
|
45446
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45447
|
+
verdict: "OK",
|
|
45448
|
+
_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).",
|
|
45449
|
+
aiSpecific: false,
|
|
45450
|
+
_v9Verdict: "OK",
|
|
45451
|
+
_v9Lift: 1.84,
|
|
45452
|
+
_v9Recall: 0.08451,
|
|
45453
|
+
_v9FpRate: 0.04596,
|
|
45454
|
+
_v9Precision: 0.1268,
|
|
45455
|
+
defaultOff: true
|
|
45456
|
+
},
|
|
45457
|
+
"kotlin/force-unwrap": {
|
|
45458
|
+
recall: 0.11737,
|
|
45459
|
+
fpRate: 0.33284,
|
|
45460
|
+
ratio: 0.35,
|
|
45461
|
+
precision: 0.0271,
|
|
45462
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45463
|
+
verdict: "DORMANT",
|
|
45464
|
+
_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.",
|
|
45465
|
+
aiSpecific: false,
|
|
45466
|
+
_v9Verdict: "DORMANT",
|
|
45467
|
+
_v9Lift: 0.35,
|
|
45468
|
+
_v9Recall: 0.11737,
|
|
45469
|
+
_v9FpRate: 0.33284,
|
|
45470
|
+
_v9Precision: 0.0271,
|
|
45471
|
+
defaultOff: true
|
|
45472
|
+
},
|
|
45473
|
+
"java/sql-string-concat": {
|
|
45474
|
+
recall: 0.01116,
|
|
45475
|
+
fpRate: 0.01892,
|
|
45476
|
+
ratio: 0.59,
|
|
45477
|
+
precision: 0.0691,
|
|
45478
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45479
|
+
verdict: "DORMANT",
|
|
45480
|
+
_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.",
|
|
45481
|
+
aiSpecific: false,
|
|
45482
|
+
_v9Verdict: "DORMANT",
|
|
45483
|
+
_v9Lift: 0.59,
|
|
45484
|
+
_v9Recall: 0.01116,
|
|
45485
|
+
_v9FpRate: 0.01892,
|
|
45486
|
+
_v9Precision: 0.0691,
|
|
45487
|
+
defaultOff: true
|
|
45488
|
+
},
|
|
45489
|
+
"java/hardcoded-credential": {
|
|
45490
|
+
recall: 0,
|
|
45491
|
+
fpRate: 4e-5,
|
|
45492
|
+
ratio: 0,
|
|
45493
|
+
precision: 0,
|
|
45494
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45495
|
+
verdict: "DORMANT",
|
|
45496
|
+
_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.",
|
|
45497
|
+
aiSpecific: false,
|
|
45498
|
+
_v9Verdict: "DORMANT",
|
|
45499
|
+
_v9Lift: 0,
|
|
45500
|
+
_v9Recall: 0,
|
|
45501
|
+
_v9FpRate: 4e-5,
|
|
45502
|
+
_v9Precision: 0,
|
|
45503
|
+
defaultOff: true
|
|
45504
|
+
},
|
|
45505
|
+
"java/thread-sleep-in-loop": {
|
|
45506
|
+
recall: 0.0228,
|
|
45507
|
+
fpRate: 0.02343,
|
|
45508
|
+
ratio: 0.97,
|
|
45509
|
+
precision: 0.1091,
|
|
45510
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45511
|
+
verdict: "DORMANT",
|
|
45512
|
+
_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.",
|
|
45513
|
+
aiSpecific: false,
|
|
45514
|
+
_v9Verdict: "DORMANT",
|
|
45515
|
+
_v9Lift: 0.97,
|
|
45516
|
+
_v9Recall: 0.0228,
|
|
45517
|
+
_v9FpRate: 0.02343,
|
|
45518
|
+
_v9Precision: 0.1091,
|
|
45519
|
+
defaultOff: true
|
|
45520
|
+
},
|
|
45521
|
+
"java/system-out-println": {
|
|
45522
|
+
recall: 0.16681,
|
|
45523
|
+
fpRate: 0.05064,
|
|
45524
|
+
ratio: 3.29,
|
|
45525
|
+
precision: 0.293,
|
|
45526
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45527
|
+
verdict: "OK",
|
|
45528
|
+
_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.",
|
|
45529
|
+
aiSpecific: false,
|
|
45530
|
+
_v9Verdict: "OK",
|
|
45531
|
+
_v9Lift: 3.29,
|
|
45532
|
+
_v9Recall: 0.16681,
|
|
45533
|
+
_v9FpRate: 0.05064,
|
|
45534
|
+
_v9Precision: 0.293,
|
|
45535
|
+
defaultOff: true
|
|
45536
|
+
},
|
|
45537
|
+
"java/command-injection": {
|
|
45538
|
+
recall: 0,
|
|
45539
|
+
fpRate: 1e-4,
|
|
45540
|
+
ratio: 0,
|
|
45541
|
+
precision: 0,
|
|
45542
|
+
lastCalibratedAt: "2026-07-03T00:00:00Z",
|
|
45543
|
+
verdict: "DORMANT",
|
|
45544
|
+
_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.",
|
|
45545
|
+
aiSpecific: false,
|
|
45546
|
+
_v9Verdict: "DORMANT",
|
|
45547
|
+
_v9Lift: 0,
|
|
45548
|
+
_v9Recall: 0,
|
|
45549
|
+
_v9FpRate: 1e-4,
|
|
45550
|
+
_v9Precision: 0,
|
|
45551
|
+
defaultOff: true
|
|
45552
|
+
},
|
|
44970
45553
|
"swift/force-unwrap": {
|
|
44971
45554
|
recall: 0,
|
|
44972
45555
|
fpRate: 0,
|