Skip to content

Commit d7a6a54

Browse files
committed
Remove XmlTextReader from sample solutions in CA3075
1 parent 65ca51e commit d7a6a54

File tree

1 file changed

+6
-22
lines changed

1 file changed

+6
-22
lines changed

docs/code-quality/ca3075-insecure-dtd-processing.md

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ If you use insecure <xref:System.Xml.XmlReaderSettings.DtdProcessing%2A> instanc
2424

2525
## Rule description
2626

27-
A *Document Type Definition (DTD)* is one of two ways an XML parser can determine the validity of a document, as defined by the [World Wide Web Consortium (W3C) Extensible Markup Language (XML) 1.0](http://www.w3.org/TR/2008/REC-xml-20081126/). This rule seeks properties and instances where untrusted data is accepted to warn developers about potential [Information Disclosure](/dotnet/framework/wcf/feature-details/information-disclosure) threats, which may lead to [Denial of Service (DoS)](/dotnet/framework/wcf/feature-details/denial-of-service) attacks. This rule triggers when:
27+
A *Document Type Definition (DTD)* is one of two ways an XML parser can determine the validity of a document, as defined by the [World Wide Web Consortium (W3C) Extensible Markup Language (XML) 1.0](http://www.w3.org/TR/2008/REC-xml-20081126/). This rule seeks properties and instances where untrusted data is accepted to warn developers about potential [Information Disclosure](/dotnet/framework/wcf/feature-details/information-disclosure) threats, or which may lead to [Denial of Service (DoS)](/dotnet/framework/wcf/feature-details/denial-of-service) attacks. This rule triggers when:
2828

2929
- DtdProcessing is enabled on the <xref:System.Xml.XmlReader> instance, which resolves external XML entities using <xref:System.Xml.XmlUrlResolver>.
3030

@@ -44,7 +44,7 @@ In each of these cases, the outcome is the same: the contents from either the fi
4444

4545
- Catch and process all XmlTextReader exceptions properly to avoid path information disclosure .
4646

47-
- Use the <xref:System.Xml.XmlSecureResolver> to restrict the resources that the XmlTextReader can access.
47+
- Use the <xref:System.Xml.XmlSecureResolver> to restrict the resources that the XmlTextReader can access.
4848

4949
- Do not allow the <xref:System.Xml.XmlReader> to open any external resources by setting the <xref:System.Xml.XmlResolver> property to **null**.
5050

@@ -198,7 +198,7 @@ public static void TestMethod(string xml)
198198
{
199199
XmlDocument doc = new XmlDocument() { XmlResolver = null };
200200
System.IO.StringReader sreader = new System.IO.StringReader(xml);
201-
XmlTextReader reader = new XmlTextReader(sreader) { DtdProcessing = DtdProcessing.Prohibit };
201+
XmlReader reader = XmlReader.Create(sreader, new XmlReaderSettings() { XmlResolver = null });
202202
doc.Load(reader);
203203
}
204204
```
@@ -237,7 +237,7 @@ namespace TestNamespace
237237
public void TestMethod(Stream stream)
238238
{
239239
XmlSerializer serializer = new XmlSerializer(typeof(UseXmlReaderForDeserialize));
240-
XmlTextReader reader = new XmlTextReader(stream) { DtdProcessing = DtdProcessing.Prohibit } ;
240+
XmlReader reader = XmlReader.Create(stream, new XmlReaderSettings() { XmlResolver = null });
241241
serializer.Deserialize(reader );
242242
}
243243
}
@@ -274,7 +274,7 @@ namespace TestNamespace
274274
{
275275
public void TestMethod(string path)
276276
{
277-
XmlTextReader reader = new XmlTextReader(path) { DtdProcessing = DtdProcessing.Prohibit };
277+
XmlReader reader = XmlReader.Create(path, new XmlReaderSettings() { XmlResolver = null });
278278
XPathDocument doc = new XPathDocument(reader);
279279
}
280280
}
@@ -314,22 +314,6 @@ namespace TestNamespace
314314
```csharp
315315
using System.Xml;
316316

317-
namespace TestNamespace
318-
{
319-
public class TestClass
320-
{
321-
public void TestMethod(string path)
322-
{
323-
XmlReaderSettings settings = new XmlReaderSettings(){ DtdProcessing = DtdProcessing.Parse };
324-
XmlReader reader = XmlReader.Create(path, settings); // warn
325-
}
326-
}
327-
}
328-
```
329-
330-
```csharp
331-
using System.Xml;
332-
333317
namespace TestNamespace
334318
{
335319
class TestClass
@@ -372,7 +356,7 @@ namespace TestNamespace
372356
{
373357
public void TestMethod(string path)
374358
{
375-
XmlReaderSettings settings = new XmlReaderSettings(){ DtdProcessing = DtdProcessing.Prohibit };
359+
XmlReaderSettings settings = new XmlReaderSettings() { XmlResolver = null };
376360
XmlReader reader = XmlReader.Create(path, settings);
377361
}
378362
}

0 commit comments

Comments
 (0)