XML Validation#
This section outlines specific implementation details for the validation_xml functionality.
In the table below outlines how functionality implemented in validate_xml and its underlying functions (_validate_xml_file, XMLSecurityValidator, and HTTPSOnlyRedirectHandler) are created:
Check |
Description |
Code Implementation |
|---|---|---|
Max File Size |
Enforces maximum XML file size (bytes) |
Checks local |
Max Nesting Depth |
Prevents deeply nested elements causing stack overflow |
|
Max Elements |
Limits total element count to prevent DoS |
Increments |
Max Attributes |
Caps attributes per element |
Checks |
Max Text Length |
Limits text node and attribute value sizes |
Checks |
Max Name Length |
Limits element and attribute name lengths |
Validates both |
DOCTYPE Rejection |
Blocks DTD declarations (XXE, entity expansion) |
|
GZip Support |
Handles compressed XML with size limits |
Checks for magic header |
UTF-8 Validation |
Rejects files with invalid UTF-8 encoding |
Decodes with |
Remote File Restriction |
Strictly restricts remote access to HTTPS only |
|
Parser Hardening |
Uses defusedxml-style protections against known XML attacks |
Combines custom tree traversal depth/size limits with strict DOCTYPE rejection, preventing XXE, quadratic blowup, and Billion Laughs entity expansion. |