ID: java-security/tainted-url-host

Language: Java

Severity: Error

Category: Security


No description found

Non-Compliant Code Examples

public void redirect(@RequestParam() String url, String a) throws MalformedURLException {
    URL newUrl = new URL(url);  // Bad: User-controlled input used directly
    URL newUrl = new URL(url + "/path");

public void apiEndpoint(@RequestParam String host) {
    String url1 = "http://" + host + "/api/resource";  // Bad: User input concatenated into URL

    String url2 = "http://".concat(host);

    String url3 = "https://";
    url3 += host;

    String url4 = String.format("https://%v", host);

    String url5 = "https://%v";

    String url6 = String.format(url5, host)

public void fetchData(@RequestParam String endpoint) {
    StringBuilder sb = new StringBuilder("");
    sb.append(endpoint);  // Bad: User input appended to base URL

Compliant Code Examples

public void safeRedirect(@RequestParam String path) throws MalformedURLException {
    String baseUrl = "";
    URL newUrl = new URL(baseUrl + URLEncoder.encode(path, "UTF-8"));  // Good: User input only affects the path, not the host
} jetbrains

Seamless integrations. Try Datadog Code Analysis