Skip to content

Commit 138bf8b

Browse files
Merge pull request #298 from AikidoSec/trim-userinput-for-sql-injection-algo
Trim user input before sending to detectSqlInjection
2 parents 3f27cdc + b8693f8 commit 138bf8b

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

agent_api/src/main/java/dev/aikido/agent_api/vulnerabilities/sql_injection/SqlDetector.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ public DetectorResult run(String userInput, String[] arguments) {
3535
}
3636
public static boolean detectSqlInjection(String query, String userInput, Dialect dialect) {
3737
String queryLower = query.toLowerCase();
38-
String userInputLower = userInput.toLowerCase();
39-
if (shouldReturnEarly(queryLower, userInputLower)) {
38+
String userInputNormalized = userInput.toLowerCase().trim();
39+
if (shouldReturnEarly(queryLower, userInputNormalized)) {
4040
return false;
4141
}
42-
return RustSQLInterface.detectSqlInjection(queryLower, userInputLower, dialect);
42+
return RustSQLInterface.detectSqlInjection(queryLower, userInputNormalized, dialect);
4343
}
4444
/**
4545
* Input : Lowercased query and user_input.

agent_api/src/test/java/vulnerabilities/SqlInjectionTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ public void testMultilineQueries() {
356356
"1' OR 1=1", "all"
357357
);
358358
}
359+
@Test
360+
public void testTrimmedUserInputBypass() {
361+
// Attacker pads payload with trailing spaces; app trims before DB execution.
362+
// The trimmed payload must still be detected (AIKIDO-OR0E0082).
363+
isSqlInjection(
364+
"INSERT INTO pets (name, owner) VALUES ('x', 'dummy'), ('injected', 'hacker'); --', 'owner')",
365+
"x', 'dummy'), ('injected', 'hacker'); -- ",
366+
"all"
367+
);
368+
}
369+
359370
@Test
360371
public void testLowercasedInputSqlInjection() {
361372
String sql = """

0 commit comments

Comments
 (0)