Validating untrusted XML input with the XmlValidatingReader class instantiated without an XmlReader object can potentially lead to denial of service, information disclosure, and server-side request forgery. These attacks are enabled by untrusted DTD and XML schema processing, which allows for the inclusion of XML bombs and malicious external entities in the XML. Only with XmlReader is it possible to disable DTD. Inline XML schema processing as XmlReader has the ProhibitDtd and ProcessInlineSchema property set to false by default in .NET Framework starting in version 4.0.
Rule description
Processing untrusted DTD and XML schemas may enable loading dangerous external references. This dangerous loading can be restricted by using an XmlReader with a secure resolver or with DTD and XML inline schema processing disabled. This rule detects code that uses the XmlValidatingReader class without XmlReader as a constructor parameter.
How to fix violations
Use XmlValidatingReader(XmlReader) with ProhibitDtd and ProcessInlineSchema properties set to false.
Starting in .NET Framework 2.0, XmlValidatingReader is considered obsolete. You can instantiate a validating reader with XmlReader.Create.
When to suppress warnings
You can potentially suppress this warning if the XmlValidatingReader is always used to validate XML that comes from a trusted source and hence cannot be tampered with.
Suppress a warning
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
C#
#pragmawarning disable CA5370// The code that's violating the rule is on this line.#pragmawarning restore CA5370
To disable the rule for a file, folder, or project, set its severity to none in the configuration file.
The following pseudo-code sample illustrates the pattern detected by this rule.
The type of the first parameter of XmlValidatingReader.XmlValidatingReader() is not XmlReader.
C#
using System;
using System.IO;
using System.Xml;
...
publicvoidTestMethod(Stream xmlFragment, XmlNodeType fragType, XmlParserContext context)
{
var obj = new XmlValidatingReader(xmlFragment, fragType, context);
}
Solution
C#
using System;
using System.Xml;
...
publicvoidTestMethod(XmlReader xmlReader)
{
var obj = new XmlValidatingReader(xmlReader);
}
ითანამშრომლეთ ჩვენთან GitHub-ზე
ამ შიგთავსის წყაროს მოძიება GitHub-ზე არის შესაძლებელი, სადაც თქვენ ასევე შეგიძლიათ პრობლემების შექმნა და განხილვა და მოთხოვნების გადმოტანა. დამატებითი ინფორმაციისთვის იხილეთ ჩვენი დამხმარე სახელმძღვანელო.
.NET-(ი)ს უკუკავშირი
.NET არის ღია წყაროს პროექტი. აირჩიეთ ბმული უკუკავშირის გასაგზავნად:
შემოუერთდით Meetup სერიას, რათა შექმნათ მასშტაბური AI გადაწყვეტილებები რეალურ სამყაროში გამოყენების შემთხვევებზე დაყრდნობით თანამემამულე დეველოპერებთან და ექსპერტებთან.