|
5 | 5 | import com.uid2.operator.model.UserIdentity; |
6 | 6 |
|
7 | 7 | import java.time.Instant; |
| 8 | +import java.sql.Connection; |
| 9 | +import java.sql.DriverManager; |
| 10 | +import java.sql.ResultSet; |
| 11 | +import java.sql.Statement; |
| 12 | +import java.nio.file.Files; |
| 13 | +import java.nio.file.Paths; |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.List; |
8 | 16 |
|
9 | 17 | public class InputUtil { |
10 | 18 |
|
@@ -272,4 +280,40 @@ public UserIdentity toUserIdentity(IdentityScope identityScope, int privacyBits, |
272 | 280 | } |
273 | 281 | } |
274 | 282 |
|
| 283 | + // VULNERABILITY: SQL Injection - for CodeQL testing purposes only |
| 284 | + // This method is intentionally vulnerable to demonstrate SQL injection detection |
| 285 | + public static List<String> validateUserInput(String userQuery) { |
| 286 | + List<String> results = new ArrayList<>(); |
| 287 | + try { |
| 288 | + Connection conn = DriverManager.getConnection("jdbc:h2:mem:testdb"); |
| 289 | + Statement stmt = conn.createStatement(); |
| 290 | + |
| 291 | + // VULNERABILITY: Direct string concatenation creates SQL injection risk |
| 292 | + String sql = "SELECT username FROM users WHERE email = '" + userQuery + "'"; |
| 293 | + |
| 294 | + ResultSet rs = stmt.executeQuery(sql); |
| 295 | + while (rs.next()) { |
| 296 | + results.add(rs.getString("username")); |
| 297 | + } |
| 298 | + stmt.close(); |
| 299 | + conn.close(); |
| 300 | + } catch (Exception e) { |
| 301 | + // VULNERABILITY: Potentially leaking database error information |
| 302 | + throw new RuntimeException("Database query failed: " + e.getMessage()); |
| 303 | + } |
| 304 | + return results; |
| 305 | + } |
| 306 | + |
| 307 | + // VULNERABILITY: Path Traversal - for CodeQL testing purposes only |
| 308 | + // This method is intentionally vulnerable to demonstrate directory traversal detection |
| 309 | + public static String readConfigFile(String filename) { |
| 310 | + try { |
| 311 | + // VULNERABILITY: No validation allows directory traversal with ../ |
| 312 | + String content = Files.readString(Paths.get("/config/" + filename)); |
| 313 | + return content; |
| 314 | + } catch (Exception e) { |
| 315 | + throw new RuntimeException("Failed to read config file: " + filename); |
| 316 | + } |
| 317 | + } |
| 318 | + |
275 | 319 | } |
0 commit comments