Why it matters
The caller can run script in another user's browser.
How to fix it
Render the value through a Razor view, which encodes it, or encode it with HtmlEncoder.Default.Encode before building HTML by hand. Never wrap request data in HtmlString.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
using Microsoft.AspNetCore.Mvc;
public class GreetController : Controller
{
public IActionResult Hello(string name)
{
return Content("<h1>Hello " + name + "</h1>", "text/html");
}
}using System.Text.Encodings.Web;
using Microsoft.AspNetCore.Mvc;
public class GreetController : Controller
{
public IActionResult Hello(string name)
{
return Content("<h1>Hello " + HtmlEncoder.Default.Encode(name) + "</h1>", "text/html");
}
}What TrustIvan reads
Runs on repository scans of C# source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.
Weakness classes and references
Related checks
- SSRF from request input (C#)
C#Severity: High
trustivan-csharp-taint-ssrf - Deserialization from request input (C#)
C#Severity: High
trustivan-csharp-taint-deserialization - Path traversal from request input (C#)
C#Severity: High
trustivan-csharp-taint-path-traversal - Open redirect from request input (C#)
C#Severity: Medium
trustivan-csharp-taint-open-redirect - Command injection from request input (C#)
C#Severity: High
trustivan-csharp-taint-command-injection - LDAP injection from request input (C#)
C#Severity: High
trustivan-csharp-taint-ldap-injection
Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10
All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation