Skip to content

Conversation

@odaysec
Copy link

@odaysec odaysec commented Apr 25, 2025

upstreamRequest.setURI(URI.create(request.getRequestLine().getUri()));

fix the SSRF vulnerability will validate the URI extracted from the incoming request. Specifically:

  1. Introduce a whitelist of allowed hosts or URI prefixes that the proxy server can forward requests to.
  2. Before creating the URI object, check if the incoming URI matches the allowed hosts or prefixes. If it does not, reject the request by setting an appropriate error response.
  3. This ensures that the proxy server only forwards requests to trusted destinations, mitigating the SSRF risk.

Directly incorporating user input into an HTTP request without validating the input can facilitate server-side request forgery (SSRF) attacks. In these attacks, the server may be tricked into making a request and interacting with an attacker-controlled server.

POC

The following shows an HTTP request parameter being used directly to form a new request without validating the input, which facilitates SSRF attacks. It also shows how to remedy the problem by validating the user input against a known fixed string.

import java.net.http.HttpClient;

public class SSRF extends HttpServlet {
	private static final String VALID_URI = "http://lgtm.com";
	private HttpClient client = HttpClient.newHttpClient();

	protected void doGet(HttpServletRequest request, HttpServletResponse response)
		throws ServletException, IOException {
		URI uri = new URI(request.getParameter("uri"));
		// BAD: a request parameter is incorporated without validation into a Http request
		HttpRequest r = HttpRequest.newBuilder(uri).build();
		client.send(r, null);

		// GOOD: the request parameter is validated against a known fixed string
		if (VALID_URI.equals(request.getParameter("uri"))) {
			HttpRequest r2 = HttpRequest.newBuilder(uri).build();
			client.send(r2, null);
		}
	}
}

References

OWASP SSRF
CWE-918

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v9.1.0 external-contributor Pull request authored by a developer outside the Elasticsearch team labels Apr 25, 2025
@DaveCTurner
Copy link
Contributor

This is a private test-only class that only listens on localhost on a CI test runner. If you can talk to it, you're already on the other side of the airtight hatchway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

external-contributor Pull request authored by a developer outside the Elasticsearch team needs:triage Requires assignment of a team area label v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants