logo

Database

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.

Weakness:

142 - Sensitive information in source code - API Key

Category: Information Collection

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;
    }
...