Description
An endpoint can disclose sensitive data to the wrong caller. Here, userId identifies the requested record. Use the authenticated principal to decide whether the caller may read it.
Potential impact
Without that check, a signed-in user may be able to read someone else’s details.
Remediation
Authorize the caller before looking up the record and return only the fields they need. Encrypt sensitive data in storage and in transit, and filter it out of application and security logs.
Examples
getUserDetails() returns sample text. For the self-service endpoint shown, use a server-authenticated Principal whose name uses the same identifier as userId.
Before
@RestController
public class UserController {
@GetMapping("/user")
public String getUserInfo(@RequestParam String userId) {
// No per-user access check is shown.
return "Displaying user info: " + getUserDetails(userId);
}
private String getUserDetails(String userId) {
// User-information lookup stub
return "User Details"; // Simplified sample data
}
}
After
@RestController
public class UserController {
@GetMapping("/user")
public ResponseEntity<String> getUserInfo(@RequestParam String userId, Principal principal) {
// Require an authenticated principal matching the requested user.
if (principal == null || !principal.getName().equals(userId)) {
return new ResponseEntity<>("Access Denied", HttpStatus.FORBIDDEN);
}
return new ResponseEntity<>("Displaying user info: " + getUserDetails(userId), HttpStatus.OK);
}
private String getUserDetails(String userId) {
// User-information lookup stub
return "User Details"; // Simplified sample data
}
}
The revised controller returns HTTP 403 when the principal is missing or the requested ID differs from the principal's name.
Related CVEs
- CVE-2022-31162: Rust library leaks Oauth client details in application debug logs
- CVE-2021-25476: Digital Rights Management (DRM) capability for mobile platform leaks pointer information, simplifying ASLR bypass
- CVE-2001-1483: Enumeration of valid usernames based on inconsistent responses