49 lines
876 B
Plaintext
49 lines
876 B
Plaintext
=== How to fix it in ASP.NET
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,csharp,diff-id=1,diff-type=noncompliant]
|
|
----
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
public class ExampleController : Controller
|
|
{
|
|
[HttpGet]
|
|
public void Redirect(string url)
|
|
{
|
|
Response.Redirect(url);
|
|
}
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
[source,csharp,diff-id=1,diff-type=compliant]
|
|
----
|
|
using System.Web;
|
|
using System.Web.Mvc;
|
|
|
|
public class ExampleController : Controller
|
|
{
|
|
private readonly string[] allowedUrls = { "/", "/login", "/logout" };
|
|
|
|
[HttpGet]
|
|
public void Redirect(string url)
|
|
{
|
|
if (allowedUrls.Contains(url))
|
|
{
|
|
Response.Redirect(url);
|
|
}
|
|
}
|
|
}
|
|
----
|
|
|
|
include::../../common/fix/how-does-this-work.adoc[]
|
|
|
|
=== Pitfalls
|
|
|
|
include::../../common/pitfalls/starts-with.adoc[]
|