Why it matters
A payload can then name a gadget type whose constructor or setters run code.
How to fix it
Leave TypeNameHandling at None. If polymorphism is needed, use a SerializationBinder that allows only your own types, or System.Text.Json's JsonDerivedType attributes.
Example
The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.
using Newtonsoft.Json;
public static class Messages
{
public static object Read(string json)
{
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All };
return JsonConvert.DeserializeObject(json, settings);
}
}using Newtonsoft.Json;
public static class Messages
{
public static Message Read(string json)
{
var settings = new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None };
return JsonConvert.DeserializeObject<Message>(json, settings);
}
}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
- BinaryFormatter use (C#)
C#Severity: High
trustivan-csharp-binaryformatter-use - XXE XML resolver (C#)
C#Severity: High
trustivan-csharp-xxe-xml-resolver - SQL string concatenation (C#)
C#Severity: Medium
trustivan-csharp-sql-string-concatenation - XXE DTD processing (C#)
C#Severity: High
trustivan-csharp-xxe-dtd-processing - Header injection from request input (C#)
C#Severity: Medium
trustivan-csharp-taint-header-injection - Weak hash (C#)
C#Severity: Medium
trustivan-csharp-weak-hash
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