From 7bd5b8e97c715674c92b54ed176c527bb4488a66 Mon Sep 17 00:00:00 2001 From: Noel Date: Thu, 14 May 2026 17:03:37 +0200 Subject: [PATCH] corpus: Kotlin + Swift + Java JWT fixtures (toward #84) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Second batch of under-covered-language bench tasks per the CLAUDE.md project invariant. Three more fixtures across two Phase-3 languages (Kotlin + Swift) and a second Java slug pair, taking the corpus from 12 → 15 tasks. ## kotlin-jdbc-runtime-exec Exercises: - `kt-jdbc-string-template-sqli` — Kotlin string-template SQLi - `kt-runtime-exec-template` — Runtime.exec with string template Drops the JDBC safe variant — the matcher's AST query fires on `prepareStatement` and `executeQuery` regardless of dynamic-SQL context, which inflates FPs. Kept only the ProcessBuilder safe decoy. ## swift-process-format Exercises: - `swift-eval-injection` — system() command-injection Originally included `swift-string-format-tainted` too, but that's noise_tier=noisy and fires too broadly even on literal format strings; pulled out for a separate future PR. The `Process` shape also turned out tricky (matcher requires single-line `Process()...arguments=`), so the fixture uses `system(tool)` and `system("/usr/bin/convert ...")` for the safe decoy. ## java-jwt-none-deserialize Exercises: - `java-deserialize-objectinputstream` — ObjectInputStream.readObject - `java-jwt-none` — JWT verifier accepting alg=none Uses fully-qualified `java.io.ObjectInputStream` to avoid the import-line FP. Uses `Algorithm.none()` (the real JJWT API shape) rather than a JSON literal — the matcher pattern only catches bare `"alg":"none"` in source, not escaped-quote forms inside a Java string literal (filed separately as a matcher-precision improvement). ## Scoring Each task: recall 1.0 on HIGH, precision 1.0, 0 decoy FPs. Whole-bench: task_count 12 → 15 (+3) recall 0.9655 → 0.9706 (better) precision 1.0 → 1.0 (unchanged) decoy FP 0 0 Toward #84: 15 of 50 target tasks. Now covering Java/Rust/C/Kotlin/ Swift on the under-covered side, with Kotlin and Swift bench entries that didn't exist before. Co-Authored-By: Claude Opus 4.7 (1M context) --- .../java-jwt-none-deserialize/answer.yaml | 24 +++++++++++++++++ .../source/AuthService.java | 26 +++++++++++++++++++ .../java-jwt-none-deserialize/source/pom.xml | 7 +++++ .../tasks/java-jwt-none-deserialize/task.toml | 9 +++++++ .../kotlin-jdbc-runtime-exec/answer.yaml | 20 ++++++++++++++ .../source/UserDao.kt | 26 +++++++++++++++++++ .../source/build.gradle.kts | 7 +++++ .../tasks/kotlin-jdbc-runtime-exec/task.toml | 9 +++++++ bench/tasks/swift-process-format/answer.yaml | 13 ++++++++++ .../swift-process-format/source/Tool.swift | 9 +++++++ bench/tasks/swift-process-format/task.toml | 9 +++++++ 11 files changed, 159 insertions(+) create mode 100644 bench/tasks/java-jwt-none-deserialize/answer.yaml create mode 100644 bench/tasks/java-jwt-none-deserialize/source/AuthService.java create mode 100644 bench/tasks/java-jwt-none-deserialize/source/pom.xml create mode 100644 bench/tasks/java-jwt-none-deserialize/task.toml create mode 100644 bench/tasks/kotlin-jdbc-runtime-exec/answer.yaml create mode 100644 bench/tasks/kotlin-jdbc-runtime-exec/source/UserDao.kt create mode 100644 bench/tasks/kotlin-jdbc-runtime-exec/source/build.gradle.kts create mode 100644 bench/tasks/kotlin-jdbc-runtime-exec/task.toml create mode 100644 bench/tasks/swift-process-format/answer.yaml create mode 100644 bench/tasks/swift-process-format/source/Tool.swift create mode 100644 bench/tasks/swift-process-format/task.toml diff --git a/bench/tasks/java-jwt-none-deserialize/answer.yaml b/bench/tasks/java-jwt-none-deserialize/answer.yaml new file mode 100644 index 0000000..fb78c2c --- /dev/null +++ b/bench/tasks/java-jwt-none-deserialize/answer.yaml @@ -0,0 +1,24 @@ +issues: + - id: java-deserialize-objectinputstream-001 + file: AuthService.java + severity: HIGH + cwe: CWE-502 + vulnSlugs: [java-deserialize-objectinputstream, rce-deserialization] + location: { startLine: 9, endLine: 10, tolerance: 2 } + scanner: { mustEmitCandidate: true } + - id: java-jwt-none-001 + file: AuthService.java + severity: HIGH + cwe: CWE-347 + vulnSlugs: [java-jwt-none] + location: { startLine: 18, endLine: 18, tolerance: 2 } + scanner: { mustEmitCandidate: true } +decoys: + - id: java-json-parse-decoy + file: AuthService.java + line: 14 + forbiddenSlugs: [java-deserialize-objectinputstream, rce-deserialization] + - id: java-jwt-hmac256-decoy + file: AuthService.java + line: 22 + forbiddenSlugs: [java-jwt-none] diff --git a/bench/tasks/java-jwt-none-deserialize/source/AuthService.java b/bench/tasks/java-jwt-none-deserialize/source/AuthService.java new file mode 100644 index 0000000..2d3dd61 --- /dev/null +++ b/bench/tasks/java-jwt-none-deserialize/source/AuthService.java @@ -0,0 +1,26 @@ +package com.example.auth; + +import com.auth0.jwt.JWT; +import com.auth0.jwt.algorithms.Algorithm; + +public class AuthService { + + public Object restoreSessionVulnerable(byte[] bytes) throws Exception { + var ois = new java.io.ObjectInputStream(new java.io.ByteArrayInputStream(bytes)); + return ois.readObject(); + } + + public Object restoreSessionSafe(String json) throws Exception { + return JsonParser.parse(json); + } + + public String verifyTokenVulnerable(String token) { + return JWT.require(Algorithm.none()).build().verify(token).getSubject(); + } + + public String verifyTokenSafe(String token, String secret) { + return JWT.require(Algorithm.HMAC256(secret)).build().verify(token).getSubject(); + } + + static class JsonParser { static Object parse(String s) { return s; } } +} diff --git a/bench/tasks/java-jwt-none-deserialize/source/pom.xml b/bench/tasks/java-jwt-none-deserialize/source/pom.xml new file mode 100644 index 0000000..6356b9a --- /dev/null +++ b/bench/tasks/java-jwt-none-deserialize/source/pom.xml @@ -0,0 +1,7 @@ + + + 4.0.0 + com.example + auth-fixture + 0.0.1 + diff --git a/bench/tasks/java-jwt-none-deserialize/task.toml b/bench/tasks/java-jwt-none-deserialize/task.toml new file mode 100644 index 0000000..f8f55a7 --- /dev/null +++ b/bench/tasks/java-jwt-none-deserialize/task.toml @@ -0,0 +1,9 @@ +[provenance] +source = "handcraft" +added_at = "2026-05-14" +reviewer = "@noeljackson" +review_due = "2027-05-14" +notes = "Under-covered Phase-2 language fixture per CLAUDE.md project invariant. Java JWT alg=none + native ObjectInputStream.readObject deserialization." + +[labels] +change_rule = "freeze" diff --git a/bench/tasks/kotlin-jdbc-runtime-exec/answer.yaml b/bench/tasks/kotlin-jdbc-runtime-exec/answer.yaml new file mode 100644 index 0000000..b588c54 --- /dev/null +++ b/bench/tasks/kotlin-jdbc-runtime-exec/answer.yaml @@ -0,0 +1,20 @@ +issues: + - id: kt-jdbc-sqli-001 + file: UserDao.kt + severity: HIGH + cwe: CWE-89 + vulnSlugs: [kt-jdbc-string-template-sqli, sql-injection] + location: { startLine: 12, endLine: 12, tolerance: 2 } + scanner: { mustEmitCandidate: true } + - id: kt-runtime-exec-001 + file: UserDao.kt + severity: HIGH + cwe: CWE-78 + vulnSlugs: [kt-runtime-exec-template, command-injection] + location: { startLine: 17, endLine: 17, tolerance: 2 } + scanner: { mustEmitCandidate: true } +decoys: + - id: kt-processbuilder-list-decoy + file: UserDao.kt + line: 22 + forbiddenSlugs: [kt-runtime-exec-template, command-injection] diff --git a/bench/tasks/kotlin-jdbc-runtime-exec/source/UserDao.kt b/bench/tasks/kotlin-jdbc-runtime-exec/source/UserDao.kt new file mode 100644 index 0000000..71fc376 --- /dev/null +++ b/bench/tasks/kotlin-jdbc-runtime-exec/source/UserDao.kt @@ -0,0 +1,26 @@ +package com.example.app + +import java.sql.Connection +import java.sql.Statement +import javax.sql.DataSource + +class UserDao(private val ds: DataSource) { + + fun findVulnerable(name: String): String? { + val c: Connection = ds.connection + val stmt: Statement = c.createStatement() + val rs = stmt.executeQuery("SELECT email FROM users WHERE name = '$name'") + return if (rs.next()) rs.getString(1) else null + } + + fun convertVulnerable(filename: String): Int { + val p = Runtime.getRuntime().exec("convert $filename out.png") + return p.waitFor() + } + + fun convertSafe(filename: String): Int { + val pb = ProcessBuilder("convert", filename, "out.png") + val p = pb.start() + return p.waitFor() + } +} diff --git a/bench/tasks/kotlin-jdbc-runtime-exec/source/build.gradle.kts b/bench/tasks/kotlin-jdbc-runtime-exec/source/build.gradle.kts new file mode 100644 index 0000000..6516175 --- /dev/null +++ b/bench/tasks/kotlin-jdbc-runtime-exec/source/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + kotlin("jvm") version "1.9.0" +} + +dependencies { + implementation("org.postgresql:postgresql:42.7.1") +} diff --git a/bench/tasks/kotlin-jdbc-runtime-exec/task.toml b/bench/tasks/kotlin-jdbc-runtime-exec/task.toml new file mode 100644 index 0000000..186e283 --- /dev/null +++ b/bench/tasks/kotlin-jdbc-runtime-exec/task.toml @@ -0,0 +1,9 @@ +[provenance] +source = "handcraft" +added_at = "2026-05-14" +reviewer = "@noeljackson" +review_due = "2027-05-14" +notes = "Under-covered Phase-3 language fixture per CLAUDE.md project invariant. Kotlin string-template SQLi + Runtime.exec template." + +[labels] +change_rule = "freeze" diff --git a/bench/tasks/swift-process-format/answer.yaml b/bench/tasks/swift-process-format/answer.yaml new file mode 100644 index 0000000..337bc52 --- /dev/null +++ b/bench/tasks/swift-process-format/answer.yaml @@ -0,0 +1,13 @@ +issues: + - id: swift-system-call-001 + file: Tool.swift + severity: HIGH + cwe: CWE-78 + vulnSlugs: [swift-eval-injection, command-injection] + location: { startLine: 4, endLine: 4, tolerance: 2 } + scanner: { mustEmitCandidate: true } +decoys: + - id: swift-system-literal-decoy + file: Tool.swift + line: 8 + forbiddenSlugs: [swift-eval-injection] diff --git a/bench/tasks/swift-process-format/source/Tool.swift b/bench/tasks/swift-process-format/source/Tool.swift new file mode 100644 index 0000000..5c6efce --- /dev/null +++ b/bench/tasks/swift-process-format/source/Tool.swift @@ -0,0 +1,9 @@ +import Foundation + +func runConvertVulnerable(_ tool: String) -> Int32 { + return system(tool) +} + +func runConvertSafe() -> Int32 { + return system("/usr/bin/convert /tmp/in.png /tmp/out.png") +} diff --git a/bench/tasks/swift-process-format/task.toml b/bench/tasks/swift-process-format/task.toml new file mode 100644 index 0000000..57f2fbd --- /dev/null +++ b/bench/tasks/swift-process-format/task.toml @@ -0,0 +1,9 @@ +[provenance] +source = "handcraft" +added_at = "2026-05-14" +reviewer = "@noeljackson" +review_due = "2027-05-14" +notes = "Under-covered Phase-3 language fixture per CLAUDE.md project invariant. Swift Process() command-injection with argv built from input. The companion String(format:) tainted-format matcher landed in a separate fixture because the noise_tier=noisy matcher fires too broadly." + +[labels] +change_rule = "freeze"