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 @@ -204,7 +204,7 @@ public ResponseEntity<GenericVulnerabilityResponseBean<Object>> level4(
if (actualToken != null) {
User decodedUser = idorLoginService.decodeToken(actualToken);
int tokenUserId = decodedUser.getUserId();
String role = cookieRole != null ? decodeBase64(cookieRole) : decodedUser.getRole();
String role = decodedUser.getRole();

if (id == null) {
id = tokenUserId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void level3_ShouldAllowRoleEscalationWhenRoleCookieIsAdmin() {
}

@Test
void level4_ShouldAllowOpaqueIdAccess() {
void level4_ShouldRejectEncodedRoleEscalation() {
String encodedRole =
java.util.Base64.getUrlEncoder()
.withoutPadding()
Expand All @@ -112,19 +112,14 @@ void level4_ShouldAllowOpaqueIdAccess() {
User decoded = new User();
decoded.setUserId(1);
decoded.setRole("USER");
User bob = new User(2, "Bob", 60000, "USER");

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

ResponseEntity<GenericVulnerabilityResponseBean<Object>> response =
idor.level4(escalatedToken, encodedRole, 2);

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

@Test
Expand Down Expand Up @@ -173,7 +168,7 @@ void level3_ShouldRejectInvalidToken() {
}

@Test
void level4_ShouldAllowAccessToAnyOpaqueIdRegardlessOfRole() {
void level4_ShouldRejectCrossUserAccessWithEncodedAdminRole() {
String userToken =
java.util.Base64.getEncoder()
.encodeToString("{\"userId\":1,\"role\":\"USER\"}".getBytes());
Expand All @@ -185,19 +180,14 @@ void level4_ShouldAllowAccessToAnyOpaqueIdRegardlessOfRole() {
User decoded = new User();
decoded.setUserId(1);
decoded.setRole("USER");
User bob = new User(2, "Bob", 60000, "USER");

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

ResponseEntity<GenericVulnerabilityResponseBean<Object>> response =
idor.level4(userToken, encodedRole, 2);

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

@Test
Expand Down