Why it matters
A crafted payload runs code on this server.
How to fix it
Deserialise request data with System.Text.Json into a fixed type. BinaryFormatter, SoapFormatter, NetDataContractSerializer, LosFormatter and ObjectStateFormatter are unsafe for any input that crosses a trust boundary.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
using System.Runtime.Serialization.Formatters.Binary;
using Microsoft.AspNetCore.Mvc;
[ApiController]
public class ImportController : ControllerBase
{
[HttpPost("/import")]
public IActionResult Import()
{
BinaryFormatter formatter = Create();
var obj = formatter.Deserialize(Request.Body);
return Ok(obj.GetType().Name);
}
}using System.Text.Json;
using Microsoft.AspNetCore.Mvc;
[ApiController]
public class ImportController : ControllerBase
{
[HttpPost("/import")]
public async System.Threading.Tasks.Task<IActionResult> Import()
{
var obj = await JsonSerializer.DeserializeAsync<ImportBatch>(Request.Body);
return Ok(obj.Count);
}
}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
- XSS from request input (C#)
C#Severity: High
trustivan-csharp-taint-xss - Open redirect from request input (C#)
C#Severity: Medium
trustivan-csharp-taint-open-redirect - SSRF from request input (C#)
C#Severity: High
trustivan-csharp-taint-ssrf - LDAP injection from request input (C#)
C#Severity: High
trustivan-csharp-taint-ldap-injection - Path traversal from request input (C#)
C#Severity: High
trustivan-csharp-taint-path-traversal - XPath injection from request input (C#)
C#Severity: High
trustivan-csharp-taint-xpath-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