Enjoy Sharing Technology!

Software,Develope,Devops, Security,TroubleShooting

Sunday, November 14, 2021

fortify scan: Missing XML Validation

Abstract:

Failure to enable validation when parsing XML gives an attacker the opportunity to supply malicious input.

Most successful attacks begin with a violation of the programmer’s assumptions. By accepting an XML document without validating it against a DTD or XML schema, the programmer leaves a door open for attackers to provide unexpected, unreasonable, or malicious input. It is not possible for an XML parser to validate all aspects of a document’s content; a parser cannot understand the complete semantics of the data. However, a parser can do a complete and thorough job of checking the document’s structure and therefore guarantee to the code that processes the document that the content is well-formed.

Explanation:

Most successful attacks begin with a violation of the programmer's assumptions. By accepting an XML document without validating it against a DTD or XML schema, the programmer leaves a door open for attackers to provide unexpected, unreasonable, or malicious input. It is not possible for an XML parser to validate all aspects of a document's content; a parser cannot understand the complete semantics of the data. However, a parser can do a complete and thorough job of checking the document's structure and therefore guarantee to the code that processes the document that the content is well-formed.

Recommendations:

Always enable validation when you parse XML. If enabling validation causes problems because the rules for defining a well-formed document are Byzantine or altogether unknown, chances are good that there are security errors nearby.

Example: The following code demonstrates how to enable validation when using XmlReader.

XmlReaderSettings settings = new XmlReaderSettings();

settings.Schemas.Add(schema);

settings.ValidationType = ValidationType.Schema;

StringReader sr = new StringReader(xmlDoc);

XmlReader reader = XmlReader.Create(sr, settings);


Share:

0 comments:

Post a Comment

Search This Blog

Weekly Pageviews

Translate

Blog Archive