Skip to content

Find the holes before someone else does. A fast, 100% Rust vulnerability scanner: XSS, SQL injection, leaked secrets, dependency CVEs and AI agent setups.

fix(code): match Scala triple-quoted interpolations in sql-injection (#244)

Mert Durukan21a77fec83db
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 851f500..7b64883 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,6 +2,8 @@
## Unreleased
+- Code: `code.sql-injection` now also reports Scala triple-quoted interpolations on one line
+ (`s"""SELECT id FROM users WHERE id = $id"""`), while `sql"""..."""` stays quiet.
- Agent: `agent.mcp-insecure-url` now also checks Gemini CLI's `httpUrl` field and plain
WebSocket (`ws://`) URLs, strips RFC 3986 userinfo (`user:pass@`) before checking the host so
URLs like `http://localhost:[email protected]` and `http://[::1]@evil.example` do not look local,
diff --git a/src/rules/code.rs b/src/rules/code.rs
index 4ab8cfa..f9d8d45 100644
--- a/src/rules/code.rs
+++ b/src/rules/code.rs
@@ -359,17 +359,17 @@ pub static RULES: &[Rule] = &[
SQLI_MSG,
SQLI_FIX
),
- // Scala `s` and `f` interpolations (`s"... $id"`, `s"... ${id}"`). Scala
- // files only: in Java and Groovy a `$` inside a string is just a character.
- // The word boundary keeps the `sql"..."` interpolator (Slick, doobie),
- // which binds its holes as parameters, quiet, and an escaped `\$` is
- // skipped.
+ // Scala `s` and `f` interpolations (`s"... $id"`, `s"... ${id}"`), also
+ // triple-quoted (`s"""..."""`). Scala files only: in Java and Groovy a `$`
+ // inside a string is just a character. The word boundary keeps the
+ // `sql"..."` interpolator (Slick, doobie), which binds its holes as
+ // parameters, quiet, and an escaped `\$` is skipped.
rule!(
"code.sql-injection",
High,
scala,
concat!(
- r#"\b[sf]"\s*"#,
+ r#"\b[sf]"(?:"")?\s*"#,
kw!(".", r"(?:\s|\\[nrt])"),
r#"(?:[^"\\]|\\.)*?\$\{?[A-Za-z_]"#
),
@@ -927,6 +927,10 @@ mod tests {
r#"val q = f"SELECT id FROM users WHERE id = $id%d""#,
// A positional placeholder first, then a hole.
r#"val q = s"SELECT id FROM users WHERE a = $1 AND b = $name""#,
+ // Triple-quoted strings, so quotes inside need no escaping.
+ r#"val q = s"""SELECT id FROM users WHERE id = $id""""#,
+ r#"val q = s"""SELECT id FROM users WHERE name = '${user.name}'""""#,
+ r#"val q = f"""SELECT id FROM users WHERE id = $id%d""""#,
] {
assert!(sqli(name, s), "expected code.sql-injection in {name}: {s}");
}
@@ -941,6 +945,10 @@ mod tests {
r#"val q = sql"SELECT id FROM users WHERE id = $id""#,
// Without an interpolator a $ is just text in Scala.
r#"val q = "SELECT id FROM users WHERE id = $id""#,
+ r#"val msg = s"""Selected $n users from the list""""#,
+ r#"val q = s"""SELECT id FROM users WHERE id = ?""""#,
+ r#"val q = sql"""SELECT id FROM users WHERE id = $id""""#,
+ r#"val q = """SELECT id FROM users WHERE id = $id""""#,
] {
assert!(
!sqli(name, s),
diff --git a/tests/fixtures/code/EXPECTED b/tests/fixtures/code/EXPECTED
index c86aa6f..6dd39e3 100644
--- a/tests/fixtures/code/EXPECTED
+++ b/tests/fixtures/code/EXPECTED
@@ -3,6 +3,7 @@ api/Repo.kt:2 code.sql-injection
api/Repo.scala:1 code.sql-injection
api/Repo.scala:2 code.sql-injection
api/Repo.scala:3 code.sql-injection
+api/Repo.scala:6 code.sql-injection
api/UserRepo.java:1 code.sql-injection
api/UserRepo.java:3 code.command-injection
api/UserRepo.java:4 code.unsafe-deserialization
diff --git a/tests/fixtures/code/api/Repo.scala b/tests/fixtures/code/api/Repo.scala
index bc5db31..33aae60 100644
--- a/tests/fixtures/code/api/Repo.scala
+++ b/tests/fixtures/code/api/Repo.scala
@@ -3,3 +3,5 @@ val b = s"SELECT id FROM users WHERE id = ${user.id}"
val c = "SELECT id FROM users WHERE id = " + id
val d = s"Selected $n users from the list"
val e = sql"SELECT id FROM users WHERE id = $id"
+val f = s"""SELECT id FROM users WHERE id = $id"""
+val g = sql"""SELECT id FROM users WHERE id = $id"""