diff --git a/rules/S5144/csharp/how-to-fix-it/dotnet.adoc b/rules/S5144/csharp/how-to-fix-it/dotnet.adoc index 64086c821f1..df0b495826e 100644 --- a/rules/S5144/csharp/how-to-fix-it/dotnet.adoc +++ b/rules/S5144/csharp/how-to-fix-it/dotnet.adoc @@ -14,11 +14,14 @@ using System.Web.Mvc; public class ExampleController: Controller { [HttpGet] - public IActionResult ImageFetch(string location) + public async Task ImageFetch(string location) { - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(location); + await using Stream stream = + await client.GetStreamAsync(location); // Noncompliant + var exampleImage = + await JsonSerializer.DeserializeAsync(stream); - return Ok(); + return Ok(example ?? new()); } } ---- @@ -36,7 +39,7 @@ public class ExampleController: Controller private readonly string[] allowedDomains = { "trusted1.example.com", "trusted2.example.com" }; [HttpGet] - public IActionResult ImageFetch(string location) + public async Task ImageFetch(string location) { Uri uri = new Uri(location); @@ -45,9 +48,12 @@ public class ExampleController: Controller return BadRequest(); } - HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); + await using Stream stream = + await client.GetStreamAsync(location); + var exampleImage = + await JsonSerializer.DeserializeAsync(stream); - return Ok(); + return Ok(example ?? new()); } } ----