Skip to content

Commit 7e11c5c

Browse files
dunningdanclaude
andcommitted
✨ Add vulnerable searchUser endpoint to demonstrate SQL injection
This endpoint is intentionally vulnerable for security scanning demos. It uses direct string concatenation in SQL queries, making it susceptible to SQL injection attacks. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent ca17858 commit 7e11c5c

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

src/main/java/org/owasp/webgoat/lessons/sqlinjection/advanced/SqlInjectionChallenge.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import org.owasp.webgoat.container.assignments.AssignmentHints;
3030
import org.owasp.webgoat.container.assignments.AttackResult;
3131
import org.springframework.util.StringUtils;
32+
import org.springframework.web.bind.annotation.GetMapping;
3233
import org.springframework.web.bind.annotation.PutMapping;
3334
import org.springframework.web.bind.annotation.RequestParam;
3435
import org.springframework.web.bind.annotation.ResponseBody;
@@ -101,4 +102,48 @@ private AttackResult checkArguments(String username_reg, String email_reg, Strin
101102
}
102103
return null;
103104
}
105+
106+
/**
107+
* VULNERABLE ENDPOINT - Demonstrates SQL Injection vulnerability This endpoint is intentionally
108+
* vulnerable to demonstrate security scanning
109+
*/
110+
@GetMapping("/SqlInjectionAdvanced/searchUser")
111+
@ResponseBody
112+
public AttackResult searchUser(@RequestParam("searchTerm") String searchTerm) {
113+
try (Connection connection = dataSource.getConnection()) {
114+
// VULNERABILITY: SQL Injection - Direct string concatenation
115+
String vulnerableQuery =
116+
"SELECT userid, email FROM sql_challenge_users WHERE userid LIKE '%"
117+
+ searchTerm
118+
+ "%' OR email LIKE '%"
119+
+ searchTerm
120+
+ "%'";
121+
122+
Statement statement = connection.createStatement();
123+
ResultSet resultSet = statement.executeQuery(vulnerableQuery);
124+
125+
StringBuilder results = new StringBuilder();
126+
int count = 0;
127+
while (resultSet.next()) {
128+
results
129+
.append("User: ")
130+
.append(resultSet.getString("userid"))
131+
.append(", Email: ")
132+
.append(resultSet.getString("email"))
133+
.append("\n");
134+
count++;
135+
}
136+
137+
if (count > 0) {
138+
return success(this)
139+
.feedback("Found " + count + " user(s):\n" + results.toString())
140+
.build();
141+
} else {
142+
return success(this).feedback("No users found matching: " + searchTerm).build();
143+
}
144+
} catch (SQLException e) {
145+
log.error("SQL error in searchUser", e);
146+
return failed(this).output("Database error: " + e.getMessage()).build();
147+
}
148+
}
104149
}

0 commit comments

Comments
 (0)