Unsanitized user input in HTTP request (SSRF)

Description

Constructing URLs based on user input puts your application at risk of Server-Side Request Forgery (SSRF) attacks. This vulnerability allows attackers to manipulate the application into making unintended HTTP requests.

Remediations

  • Do not directly incorporate user input into URLs for HTTP requests. This can lead to SSRF vulnerabilities.
    const response = axios.get(`https://${req.params.host}`) // unsafe
  • Do validate or map user input against a predefined list of allowed values before using it to form URLs. This approach minimizes the risk of SSRF attacks.
    const hosts = new Map([
    ["option1", "api1.com"],
    ["option2", "api2.com"]
    ])

    const host = hosts.get(req.params.host)
    const response = axios.get(`https://${host}`)

Associated CWE

OWASP Top 10

Configuration

To skip this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --skip-rule=javascript_lang_http_url_using_user_input

To run only this rule during a scan, use the following flag

bearer scan /path/to/your-project/ --only-rule=javascript_lang_http_url_using_user_input