Json.NET is set to read type names from the JSON, which lets the input choose types
What it finds
With TypeNameHandling other than None, Json.NET creates the types named in $type properties of the input. Untrusted JSON can then make it construct dangerous types. Leave it at None, or restrict the types with a serialization binder.
From the rule's source, type_name_handling.rs.
using Newtonsoft.Json; class Settings{ JsonSerializerSettings Make() => new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.All,tx0 reports: TypeNameHandling.All lets the JSON choose the types that are created }; JsonSerializerSettings Safe() => new JsonSerializerSettings { TypeNameHandling = TypeNameHandling.None };} 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:
[rules]
"tx0/csharp:type-name-handling" = "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:type-name-handling] reason="..."tx0 explain tx0/csharp:type-name-handling shows the same in the terminal. Found a false positive? Report it.