A serializer that can create any type from its input is used

tx0/csharp:insecure-deserializerrecommendedwarningsecurity/deserializationdepth fastsecurity, cwe-502

What it finds

These serializers write type names into the data and create whatever types the data names when reading it. Data from outside then decides which constructors and setters run, which is enough to run arbitrary code. System.Text.Json and DataContractSerializer with known types read only the types the code expects.

From the rule's source, insecure_deserializer.rs.

Example from the rule's tests
using System.IO;using System.Runtime.Serialization.Formatters.Binary; class Store{    object Load(Stream stream)    {        var formatter = new BinaryFormatter();tx0 reports: BinaryFormatter can run code chosen by whoever controls the data        return formatter.Deserialize(stream);    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

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:

tx0.toml
[rules]
"tx0/csharp:insecure-deserializer" = "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:insecure-deserializer] reason="..."

tx0 explain tx0/csharp:insecure-deserializer shows the same in the terminal. Found a false positive? Report it.