Description
An application that grants a session without verifying the caller’s identity may let someone sign in as another user. A fixed username and password in the code cannot distinguish individual users.
Potential impact
An unauthenticated user may read data or perform actions with someone else’s privileges. Exposed administrative features may also allow code or commands to run.
Remediation
- Have the authentication service verify the identity of each user or system. For password logins, verify the supplied password against the account’s stored hash and create a session only after authentication succeeds.
- Enable multifactor authentication (MFA).
- Protect stored credentials, including password hashes, and use HTTPS to transmit authentication data.
Examples
Before
java
@PostMapping("/login")
public String login(String username, String password, HttpSession session) {
if (username.equals("admin") && password.equals("admin")) {
session.setAttribute("user", "admin");
return "dashboard";
}
return "login";
}
After
java
@PostMapping("/login")
public String login(String username, String password, HttpSession session) {
User user = userService.authenticate(username, password);
if (user != null) {
session.setAttribute("user", user);
return "dashboard";
}
return "login";
}
Explanation:
- Before: Authentication relies on a fixed username and password that an attacker can use to bypass the intended identity check.
- After: An authentication service verifies the username and password. Merely moving the check into a separate method does not establish secure authentication; the service must implement password-hash verification and failure handling correctly.
Related CVEs
- CVE-2022-35248: A chat application's CAS configuration skips validation and removes the second authentication factor
- CVE-2022-36436: An authentication proxy accepts the 'None' authentication type without enforcing a password during the initial handshake
- CVE-2022-30034: Missing regex anchors in login-email validation (CWE-777) can allow OAuth bypass (CWE-1390) in a Python RPC framework's web UI