logo

Database

Java Resttemplate Insecure Http Request

Description

Detects the use of insecure HTTP URLs in Spring Framework's RestTemplate methods. Using unencrypted HTTP instead of HTTPS for web requests can expose sensitive data to man-in-the-middle attacks and network eavesdropping, potentially compromising data confidentiality and integrity.

Weakness:

372 - Use of an insecure channel - HTTP

Category: Information Collection

Detection Strategy

    1. Checks if Spring Web Client library (org.springframework.web.client) is imported in the code

    2. Identifies calls to RestTemplate methods like getForObject, postForEntity, exchange, etc.

    3. Examines if the first argument of these methods contains an HTTP URL (not HTTPS)

    4. Verifies that the method is called on a RestTemplate object

    5. Reports a vulnerability when HTTP URLs are used with RestTemplate methods instead of secure HTTPS URLs

Vulnerable code example

import org.springframework.web.client.RestTemplate;

public class VulnerableExample {
    public void unsafeRestCalls() {
        RestTemplate restTemplate = new RestTemplate();
        
        // Vulnerable: Using unencrypted HTTP protocol for REST calls
        restTemplate.delete("http://example.com");...

✅ Secure code example

import org.springframework.web.client.RestTemplate;

public class SecureExample {
    public void safeRestCalls() {
        RestTemplate restTemplate = new RestTemplate();
        
        // Safe: Using encrypted HTTPS protocol for REST calls
        restTemplate.delete("https://example.com");...