-
Notifications
You must be signed in to change notification settings - Fork 6.1k
XmlDocument DOM docs: note XmlResolver=null for untrusted XML #55982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,9 @@ ms.assetid: ad3fa320-4b8f-4e5c-b549-01157591007a | |
|
|
||
| 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. | ||
|
|
||
| > [!IMPORTANT] | ||
| > When the input XML comes from an untrusted source, do not allow the **XmlDocument** to open external resources. Set the **XmlResolver** property to `null`, or supply an <xref:System.Xml.XmlSecureResolver> that restricts which resources can be accessed. For more information, see [CA3075: Insecure DTD processing](../../../fundamentals/code-analysis/quality-rules/ca3075.md). | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note This response was generated by AI. Agreed - the existing table in this same file states that
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note This response was generated by AI. Confirmed - |
||
|
|
||
| ## Fully-Trusted XmlDocument | ||
|
|
||
| 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**. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note
This response was generated by AI.
Correct. CA3075's Violation 3 flags
XmlDocument { XmlResolver = null }; doc.LoadXml(xml)and its solution wraps the input in anXmlReadercreated withXmlReaderSettings.XmlResolver = null;Load(XmlReader)also honors the reader's resolver over the document's (the table further down inresolving-external-resources.mdalready spells that out). I'll narrow the callout so it recommends the reader-based fix forLoadXmlandLoad(XmlReader), and keepXmlDocument.XmlResolverguidance scoped to the stream/string/URI overloads.