Get started

Let's get your .NET application protected against Server Side Request Forgery attacks.

Create a .NET project with the idunno.Security.Ssrf nuget package

  1. At the command line run the following commands
    dotnet new console -n NoSsrf
    cd NoSsrf
    dotnet add package idunno.Security.Ssrf
    

Create an HttpClient

  1. Open the Program.cs file in your editor of choice and add the following lines.
    using (var httpClient = new HttpClient())
    {
        var response = await httpClient.GetAsync("https://example.com");
        Console.WriteLine(response.StatusCode);
    }
    
  2. Save the changed file.
  3. Compile and run your project with the following command
    dotnet run
    

The program should run without any errors, and should output 200, the HTTP status code for a successful request.

Create an HttpClient with SSRF protection

  1. Open the Program.cs file in your editor of choice and add the following lines.
    var ssrfHandler = SsrfSocketsHttpHandlerFactory.Create();
    using (var httpClient = new HttpClient(ssrfHandler))
    {
        var response = await httpClient.GetAsync("https://example.com");
        Console.WriteLine(response.StatusCode);
    }
    
  2. Save the changed file.
  3. Compile and run your project with the following command
    dotnet run
    

The program should run without any errors, and should output two lines that say 200, the HTTP status code for a successful request.

Congratulations, you have an HttpClient with protection from SSRF!

Explainers

Advanced Topics