Static analysis (SAST) check · C#

XXE XML resolver (C#)

An XML parser is given a resolver that fetches external entities.

Why it matters

A document can then read local files or make the server send requests (XXE).

How to fix it

Set XmlResolver = null on XmlDocument and XmlReaderSettings (the default on .NET Core and on .NET Framework 4.5.2 and later).

Example

The rule's own test fixtures, verbatim: the test suite requires the rule to report the first and not the second.

Vulnerable: reported (C#)
using System.Xml;

public static class Feed
{
    public static XmlDocument Parse(string xml)
    {
        var doc = new XmlDocument();
        doc.XmlResolver = new XmlUrlResolver();
        doc.LoadXml(xml);
        return doc;
    }
}
Fixed: not reported (C#)
using System.Xml;

public static class Feed
{
    public static XmlDocument Parse(string xml)
    {
        var doc = new XmlDocument();
        doc.XmlResolver = null;
        doc.LoadXml(xml);
        return doc;
    }
}

What TrustIvan reads

Runs on repository scans of C# source once static analysis is turned on (SAST_RULES and the separately built analyzer image); it is off by default.

Weakness classes and references

Terms: SAST (static application security testing), Taint analysis, CWE (Common Weakness Enumeration), OWASP Top 10

All static analysis (SAST) checks · The whole catalogue · How this works in TrustIvan · Documentation

See TrustIvan on your own estate.

Book thirty minutes with an engineer and bring an image, a repository or a cloud account, or start free on the hosted service.