Skip to content

Commit

Permalink
Add secure implementation level 5 for BlindSQLInjectionVulnerability
Browse files Browse the repository at this point in the history
  • Loading branch information
imertetsu committed Oct 31, 2024
1 parent 792a7c8 commit ca12393
Showing 1 changed file with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.sasanlabs.service.vulnerability.sqlInjection;

import java.util.Map;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.sasanlabs.internal.utility.LevelConstants;
import org.sasanlabs.internal.utility.Variant;
import org.sasanlabs.internal.utility.annotations.AttackVector;
Expand Down Expand Up @@ -29,6 +31,7 @@
value = "BlindSQLInjectionVulnerability")
public class BlindSQLInjectionVulnerability {

@PersistenceContext private EntityManager entityManager;
private JdbcTemplate applicationJdbcTemplate;

static final String CAR_IS_PRESENT_RESPONSE = "{ \"isCarPresent\": true}";
Expand Down Expand Up @@ -107,7 +110,7 @@ public ResponseEntity<String> getCarInformationLevel3(
});
}

//Input Validation - Ensure that the input data is valid and of the expected type.
// Input Validation - Ensure that the input data is valid and of the expected type.
@VulnerableAppRequestMapping(
value = LevelConstants.LEVEL_4,
variant = Variant.SECURE,
Expand All @@ -134,4 +137,22 @@ public ResponseEntity<String> getCarInformationLevel4(
});
}

// Implementation Level 5 - Hibernate
@VulnerableAppRequestMapping(
value = LevelConstants.LEVEL_5,
variant = Variant.SECURE,
htmlTemplate = "LEVEL_1/SQLInjection_Level1")
public ResponseEntity<String> getCarInformationLevel5(
@RequestParam Map<String, String> queryParams) {
int id = Integer.parseInt(queryParams.get(Constants.ID));

CarInformation car = entityManager.find(CarInformation.class, id);

if (car != null) {
return ResponseEntity.ok(CAR_IS_PRESENT_RESPONSE);
} else {
return ResponseEntity.status(HttpStatus.NOT_FOUND)
.body(ErrorBasedSQLInjectionVulnerability.CAR_IS_NOT_PRESENT_RESPONSE);
}
}
}

0 comments on commit ca12393

Please sign in to comment.