using System.Web;
using System.Web.Mvc;
public class ExampleController: Controller
{
private readonly string[] allowedSchemes = { "https" };
private readonly string[] allowedDomains = { "trusted1.example.com", "trusted2.example.com" };
[HttpGet]
public async Task<IActionResult> ImageFetch(string location)
{
Uri uri = new Uri(location);
if (!allowedDomains.Contains(uri.Host) && !allowedSchemes.Contains(uri.Scheme))
{
return BadRequest();
}
await using Stream stream =
await client.GetStreamAsync(location);
var exampleImage =
await JsonSerializer.DeserializeAsync<ExampleImage>(stream);
return Ok(example ?? new());
}
}