Java Insufficiently Protected Credentials
Description
Detects when credentials are insufficiently protected by identifying hardcoded authentication credentials in Spring RestTemplate HTTP headers. This practice exposes sensitive authentication information directly in the code, making it vulnerable to compromise if the source code is exposed.
Detection Strategy
• Application code imports Spring RestTemplate (org.springframework.web.client.RestTemplate)
• Headers are modified using an 'add' method call on a headers object
• The header values contain hardcoded credentials or authentication information
• The credentials are passed directly as string literals or constants rather than being retrieved from secure configuration
Vulnerable code example
@Configuration
public class ApiConfig {
// Hardcoded sensitive value as constant
private static final String API_KEY = "sk-live-abc123def456ghi789";
@Bean
public RestTemplate vulnerableRestTemplate() {
RestTemplate template = new RestTemplate();...✅ Secure code example
@Configuration
public class ApiConfig {
private final Environment env;
public ApiConfig(Environment env) {
this.env = env;
}
...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Continuous Hacking Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' hacking team, fill out this contact form.