Why it matters
Deserialising data an attacker can influence runs their code.
How to fix it
Replace the formatter with System.Text.Json or a contract-based serialiser bound to fixed types. Microsoft has removed BinaryFormatter from .NET 9.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
public static class Cache
{
public static object Load(Stream s)
{
var formatter = new BinaryFormatter();
return formatter.Deserialize(s);
}
}using System.IO;
using System.Text.Json;
public static class Cache
{
public static CacheEntry Load(Stream s)
{
return JsonSerializer.Deserialize<CacheEntry>(s);
}
}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
- SQL string concatenation (C#)
C#Severity: Medium
trustivan-csharp-sql-string-concatenation - Json type name handling (C#)
C#Severity: High
trustivan-csharp-json-type-name-handling - Header injection from request input (C#)
C#Severity: Medium
trustivan-csharp-taint-header-injection - XXE XML resolver (C#)
C#Severity: High
trustivan-csharp-xxe-xml-resolver - Template injection from request input (C#)
C#Severity: High
trustivan-csharp-taint-template-injection - XXE DTD processing (C#)
C#Severity: High
trustivan-csharp-xxe-dtd-processing
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