ASP.NET request validation is switched off with [ValidateInput(false)] or [AllowHtml]

tx0/csharp:request-validation-disabledrecommendedwarningsecurity/xssdepth fastsecurity, cwe-79

What it finds

Classic ASP.NET rejects requests that contain markup unless validation is switched off. Turning it off for an action or a property lets script reach the code, which then has to encode it everywhere it is shown.

From the rule's source, request_validation_disabled.rs.

Example from the rule's tests
using System.Web.Mvc; class CommentsController : Controller{    [ValidateInput(false)]tx0 reports: request validation is switched off here    public ActionResult Post(string text) => View();}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:request-validation-disabled" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:request-validation-disabled] reason="..."

tx0 explain tx0/csharp:request-validation-disabled shows the same in the terminal. Found a false positive? Report it.