C Sharp Schema By Url
Description
Detects potential XML External Entity (XXE) vulnerabilities in C# code where XmlSchemaCollection.Add() loads an XML schema from a URI controlled by user input. An attacker-supplied URI can point the parser at a malicious schema with external entity references or make the server fetch internal resources.
Detection Strategy
• Looks for .Add() method calls whose receiver is defined as a new XmlSchemaCollection
• Takes the second argument of the call, which is the schema URI
• Reports a vulnerability when the URI comes from HTTP request input, directly or through unsanitized variable definitions
Vulnerable code example
using System;
using System.Xml.Schema;
public partial class SchemaForm : System.Web.UI.Page {
protected void LoadSchema() {
string schemaUrl = Request.QueryString["schema"];
XmlSchemaCollection xsc = new XmlSchemaCollection();
xsc.Add("urn:schema", schemaUrl); // Vulnerable: schema URI comes from the request...✅ Secure code example
using System;
using System.Xml.Schema;
public partial class SchemaForm : System.Web.UI.Page {
protected void LoadSchema() {
XmlSchemaCollection xsc = new XmlSchemaCollection();
xsc.Add("urn:schema", "books.xsd"); // Safe: schema URI is fixed by the application
}...Search for vulnerabilities in your apps for free with Fluid Attacks' automated security testing! Start your 21-day free trial and discover the benefits of the Essential plan. If you prefer the Advanced plan, which includes the expertise of Fluid Attacks' pentesting team, fill out this contact form.