Skip to content

Commit 61baec0

Browse files
krwqCopilotBillWagnerCopilot
authored
XmlDocument DOM docs: note XmlResolver=null for untrusted XML (#55982)
* docs: note XmlResolver=null for untrusted XML in XmlDocument guidance Adds a short IMPORTANT callout to the two pages that walk through XmlDocument loading without mentioning external-resolution safety: - resolving-external-resources.md - reading-an-xml-document-into-the-dom.md Both point at CA3075 for details. Style matches the existing > [!IMPORTANT] callouts already used in this folder (e.g. in xslt-security-considerations.md). Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Revise XmlDocument security guidelines for untrusted XML Updated security recommendations for handling untrusted XML sources in XmlDocument methods. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Co-authored-by: Bill Wagner <wiwagn@microsoft.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
1 parent 4703933 commit 61baec0

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

‎docs/standard/data/xml/reading-an-xml-document-into-the-dom.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ XML information is read into memory from different formats. It can be read from
1313

1414
The <xref:System.Xml.XmlDocument.Load*> method brings the document into memory and has overloaded methods available to take data from each of the different formats. There is also a <xref:System.Xml.XmlDocument.LoadXml*> method that reads XML from a string.
1515

16+
> [!IMPORTANT]
17+
> When the XML is from an untrusted source, set <xref:System.Xml.XmlDocument.XmlResolver?displayProperty=nameWithType> to `null` before calling the <xref:System.Xml.XmlDocument.Load*> overloads that don't take an <xref:System.Xml.XmlReader>. For <xref:System.Xml.XmlDocument.Load*> overloads that take a reader, configure the reader's <xref:System.Xml.XmlReaderSettings.XmlResolver?displayProperty=nameWithType> to `null`; use the same reader-based pattern instead of <xref:System.Xml.XmlDocument.LoadXml*>. For more information, see [CA3075: Insecure DTD processing](../../../fundamentals/code-analysis/quality-rules/ca3075.md).
18+
1619
Different <xref:System.Xml.XmlDocument.Load*> methods affect which nodes are created when the XML Document Object Model (DOM) is loaded. The following table lists the differences between some of the <xref:System.Xml.XmlDocument.Load*> methods and topics that address them.
1720

1821
|Subject|Topic|

‎docs/standard/data/xml/resolving-external-resources.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ ms.assetid: ad3fa320-4b8f-4e5c-b549-01157591007a
88

99
The **XmlResolver** property of the **XmlDocument** is used by the **XmlDocument** class to locate resources that are not inline in the XML data, such as external document type definitions (DTDs), entities, and schemas. These items can be located on a network or on a local drive, and are identifiable by a Uniform Resource Identifier (URI). This allows the **XmlDocument** to resolve **EntityReference** nodes that are present in the document and validate the document according to the external DTD or schema.
1010

11+
> [!IMPORTANT]
12+
> When the input XML comes from an untrusted source, do not allow the **XmlDocument** to open external resources. Set the **XmlResolver** property to `null`. In .NET 7 and later, you can instead use <xref:System.Xml.XmlResolver.ThrowingResolver?displayProperty=nameWithType> to reject resolution attempts. For more information, see [CA3075: Insecure DTD processing](../../../fundamentals/code-analysis/quality-rules/ca3075.md).
13+
1114
## Fully-Trusted XmlDocument
1215

1316
The **XmlResolver** property affects the functionality of the **XmlDocument.Load** method. The table below shows how the **XmlDocument.XmlResolver** property works when the **XmlDocument** object is fully trusted. The following table shows the **XmlDocument.Load** methods when the input to the Load is a **TextReader**, **String**, **Stream**, or **URI**. This table does not apply to the **Load** method if the **XmlDocument** is loaded from an **XmlReader**.

0 commit comments

Comments
 (0)