All rules
CA2351Security Enabled by default: No

Ensure DataSet.ReadXml()'s input is trusted

Ensure DataSet.ReadXml()'s input is trusted

Microsoft docs

Description

When deserializing a System.Data.DataSet with untrusted input, an attacker can craft malicious input to perform a denial of service attack. There may be unknown remote code execution vulnerabilities.

For more information, see DataSet and DataTable security guidance.

Cause

The System.Data.DataSet.ReadXml method was called or referenced, and not within autogenerated code.

This rule classifies autogenerated code b:

  • Being inside a method named ReadXmlSerializable.
  • The ReadXmlSerializable method has a System.Diagnostics.DebuggerNonUserCodeAttribute.
  • The ReadXmlSerializable method is within a type that has a System.ComponentModel.DesignerCategoryAttribute.

CA2361 is a similar rule, for when System.Data.DataSet.ReadXml appears within autogenerated code.

How to fix violations

  • If possible, use Entity Framework rather than the System.Data.DataSet.
  • Make the serialized data tamper-proof. After serialization, cryptographically sign the serialized data. Before deserialization, validate the cryptographic signature. Protect the cryptographic key from being disclosed and design for key rotations.

Example

using System.Data;

public class ExampleClass
{
    public DataSet MyDeserialize(string untrustedXml)
    {
        DataSet dt = new DataSet();
        dt.ReadXml(untrustedXml);
    }
}
Group results
0 yes 0 no
ConsensusNone (disabled)
Severity preference (yes voters)
Suggestion0
Warning0
Error0