Skip to content

Commit

Permalink
Add secure implementation level 4 for BlindSQLInjectionVulneravility
Browse files Browse the repository at this point in the history
  • Loading branch information
imertetsu committed Oct 8, 2024
1 parent 33835a3 commit 792a7c8
Showing 1 changed file with 28 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,32 @@ public ResponseEntity<String> getCarInformationLevel3(
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE);
});
}

//Input Validation - Ensure that the input data is valid and of the expected type.
@VulnerableAppRequestMapping(
value = LevelConstants.LEVEL_4,
variant = Variant.SECURE,
htmlTemplate = "LEVEL_1/SQLInjection_Level1")
public ResponseEntity<String> getCarInformationLevel4(
@RequestParam Map<String, String> queryParams) {
String id = queryParams.get(Constants.ID);

// Validate numeric ID
if (!id.matches("\\d+")) {
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Invalid ID format.");
}

BodyBuilder bodyBuilder = ResponseEntity.status(HttpStatus.OK);
bodyBuilder.body(ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE);
return applicationJdbcTemplate.query(
"select * from cars where id=" + id,
(rs) -> {
if (rs.next()) {
return bodyBuilder.body(CAR_IS_PRESENT_RESPONSE);
}
return bodyBuilder.body(
ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE);
});
}

}

0 comments on commit 792a7c8

Please sign in to comment.