# V5618. OWASP. Possible server-side request forgery. Potentially tainted data is used in the URL.

The analyzer detected an attempt to access a remote resource without checking URL provided by the user. The use of unverified external data to generate an address can cause Server-Side Request Forgery.

Vulnerabilities of the Server-Side Request Forgery type are allocated to a separate risk category in the OWASP Top 10 Application Security Risks 2021: A10:2021-Server-Side Request Forgery.

Look at the example:

    void ServerSideRequestForgery()
    {
      var url = Request.QueryString["url"];
      WebRequest request = WebRequest.Create(url);
      WebResponse response = request.GetResponse();
      using (Stream stream = response.GetResponseStream())
      {
        using (StreamReader reader = new StreamReader(stream))
        {
          ....
        }
      }
      response.Close();
    }

In this example, 'url' may contain tainted data since it comes from an external source. A request is generated from this address, and it's executed server-side. The request can be sent to any web resource or the server itself.

Thus, attackers can perform malicious actions by sending requests to resources that they don't have direct access to.

An example of compromised data:

    http://localhost/admin/delete?username=testSSRF

An attacker can delete the user with the help of such a request.

When fighting SSRF, don't use a prohibited list or regular expressions. An attacker can easily evade these restrictions by:

- Redirection — an attacker can create an external resource that redirects to another URL as a response.
- Alternate representations:

    http://2130706433/ = http://127.0.0.1
    http://0x7f000001/ = http://127.0.0.1

An example of fighting SSRF by using verification of the external data:

    string ServerSideRequestForgery()
    {
      var url = Request.QueryString["url"];
      if (!whiteList.Contains(url))
        return "Forbidden URL";

      WebRequest request = WebRequest.Create(url);
      ....
    }

This diagnostic is classified as:

CWE-918 OWASP-12.6.1 OWASP-5.2.6