Description
A password or authentication key embedded in source code is visible to anyone who can read that code.
Potential impact
While the credential is valid, a reader may gain the account’s privileges, including administrative access.
Remediation
Revoke and replace exposed credentials. Deliver the replacement through an access-controlled secret store or deployment configuration. For user sign-in, store a password hash and verify it with Spring Security’s PasswordEncoder.
Examples
Before
java
@RestController
public class LoginController {
private static final String USERNAME = "admin";
private static final String PASSWORD = "admin123"; // Hard-coded password
@PostMapping("/login")
public String login(@RequestParam String username, @RequestParam String password) {
if (USERNAME.equals(username) && PASSWORD.equals(password)) {
return "로그인 성공";
}
return "로그인 실패";
}
}
After
java
@RestController
public class LoginController {
@Value("${credentials.username}")
private String username;
@Value("${credentials.password}")
private String password;
@PostMapping("/login")
public String login(@RequestParam String username, @RequestParam String password) {
if (this.username.equals(username) && this.password.equals(password)) {
return "로그인 성공";
}
return "로그인 실패";
}
}
The revised controller uses @Value to read credentials from configuration. Keep their values out of committed files. The sample still compares plaintext strings and needs password-hash verification for a real sign-in.
Related CVEs
- CVE-2022-29953: Hard-coded credentials in a Condition Monitor firmware maintenance interface
- CVE-2022-29960: Hard-coded cryptographic keys in an Engineering Workstation can allow unauthorized filesystem access and privilege escalation
- CVE-2022-29964: Hard-coded passwords for local shell access in a Distributed Control System (DCS)