Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,11 @@ public ResponseEntity<GenericVulnerabilityResponseBean<Object>> level1(
String actualToken = cookieToken;
try {
if (actualToken != null) {
idorLoginService.decodeToken(actualToken);
User decodedUser = idorLoginService.decodeToken(actualToken);
if (id != null) {
if (decodedUser.getUserId() != id) {
return response(ACCESS_DENIED_INSUFFICIENT, false);
}
User profile = fetchUserById(id);
if (profile == null) {
return response(USER_NOT_FOUND, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,38 @@ void setup() {
}

@Test
void level1_ShouldAllowAccessToAnyId() {
void level1_ShouldRejectAccessToAnotherUsersId() {
String validToken = "valid-token";
User decoded = new User();
decoded.setUserId(1);
decoded.setRole("USER");
User bob = new User(2, "Bob", 60000, "USER");

when(idorLoginService.decodeToken(validToken)).thenReturn(decoded);

ResponseEntity<GenericVulnerabilityResponseBean<Object>> response =
idor.level1(validToken, 2);

assertFalse(response.getBody().getIsValid());
assertEquals("Access Denied - Insufficient privileges", response.getBody().getContent());
}

@Test
void level1_ShouldAllowAccessToOwnId() {
String validToken = "valid-token";
User decoded = new User();
decoded.setUserId(1);
decoded.setRole("USER");
User alice = new User(1, "Alice", 50000, "USER");

when(idorLoginService.decodeToken(validToken)).thenReturn(decoded);
when(jdbcTemplate.query(
anyString(),
any(Object[].class),
any(org.springframework.jdbc.core.RowMapper.class)))
.thenReturn(Arrays.asList(bob));
.thenReturn(Arrays.asList(alice));

ResponseEntity<GenericVulnerabilityResponseBean<Object>> response =
idor.level1(validToken, 2);
idor.level1(validToken, 1);

assertTrue(response.getBody().getIsValid());
}
Expand Down