GuardAPI Logo
GuardAPI

Fix SSRF (Server Side Request Forgery) in Quarkus

SSRF in Quarkus/Java environments allows an attacker to force the server-side application to make HTTP requests to arbitrary domains. In a cloud-native context, this is a high-severity pivot point used to exfiltrate IMDSv1/v2 credentials, hit internal Kubernetes services, or scan the local loopback. If you are blindly passing query params into a Vert.x WebClient or RestEasy client, you are wide open.

The Vulnerable Pattern

@Path("/proxy")
public class VulnerableResource {
    @Inject
    WebClient webClient;
@GET
public Uni<String> proxy(@QueryParam("url") String url) {
    // CRITICAL VULNERABILITY: User-controlled URL is passed directly to the client.
    // Attacker can pass 'http://169.254.169.254/latest/meta-data/' to steal AWS tokens.
    return webClient.getAbs(url)
            .send()
            .map(resp -> resp.bodyAsString());
}

}

The Secure Implementation

To kill SSRF, stop trusting strings. The secure implementation uses a three-pronged defense: First, it parses the input into a URI object to extract the host safely. Second, it checks that host against a hardcoded allowlist (Deny-by-Default). Third, it reconstructs the request manually using specific port and protocol constraints rather than using the raw 'getAbs' method. This prevents protocol smuggling and ensures the request cannot be redirected to internal IP ranges like 127.0.0.1 or 10.0.0.0/8 via user-supplied input.

@Path("/proxy")
public class SecureResource {
    @Inject
    WebClient webClient;
private static final Set<String> ALLOWED_DOMAINS = Set.of("api.trusted-partner.com", "static.mycdn.com");

@GET
public Uni<String> proxy(@QueryParam("url") String url) {
    try {
        java.net.URI uri = new java.net.URI(url);
        String host = uri.getHost();

        // 1. Strict Allowlist validation
        if (host == null || !ALLOWED_DOMAINS.contains(host)) {
            throw new WebApplicationException("Disallowed target host", 403);
        }

        // 2. Protocol Enforcement (No file://, gopher://, etc.)
        if (!"https".equalsIgnoreCase(uri.getScheme())) {
            throw new WebApplicationException("HTTPS required", 400);
        }

        // 3. Prevent DNS Rebinding / Internal pivoting by reconstructing the request
        return webClient.get(443, host, uri.getRawPath() + (uri.getRawQuery() != null ? "?" + uri.getRawQuery() : ""))
                .send()
                .map(resp -> resp.bodyAsString());
    } catch (Exception e) {
        throw new WebApplicationException("Invalid URL format", 400);
    }
}

}

System Alert • ID: 5359
Target: Quarkus API
Potential Vulnerability

Your Quarkus API might be exposed to SSRF (Server Side Request Forgery)

74% of Quarkus apps fail this check. Hackers use automated scanners to find this specific flaw. Check your codebase before they do.

RUN FREE SECURITY DIAGNOSTIC
GuardLabs Engine: ONLINE

Free Tier • No Credit Card • Instant Report

Verified by Ghost Labs Security Team

This content is continuously validated by our automated security engine and reviewed by our research team. Ghost Labs analyzes over 500+ vulnerability patterns across 40+ frameworks to provide up-to-date remediation strategies.