Skip to content

Commit d48293e

Browse files
Potential fix for code scanning alert no. 46: Query built from user-controlled sources
Fix SQL injection in Benchmark00839.java:75 Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
1 parent 034a7ba commit d48293e

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

src/main/java/org/owasp/benchmark/testcode/Benchmark00839.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,15 @@ public void doPost(HttpServletRequest request, HttpServletResponse response)
7272

7373
bar = (7 * 42) - num > 200 ? "This should never happen" : param;
7474

75-
String sql = "SELECT * from USERS where USERNAME=? and PASSWORD='" + bar + "'";
75+
String sql = "SELECT * from USERS where USERNAME=? and PASSWORD=?";
7676

7777
try {
7878
java.sql.Connection connection =
7979
org.owasp.benchmark.helpers.DatabaseHelper.getSqlConnection();
8080
java.sql.PreparedStatement statement =
8181
connection.prepareStatement(sql, new String[] {"Column1", "Column2"});
8282
statement.setString(1, "foo");
83+
statement.setString(2, bar);
8384
statement.execute();
8485
org.owasp.benchmark.helpers.DatabaseHelper.printResults(statement, sql, response);
8586
} catch (java.sql.SQLException e) {

0 commit comments

Comments
 (0)