web devprogramming

Kept in this browser · My desk

Stands for: Extensible Markup Language

The World Wide Web Consortium (W3C) markup language for structured documents, a subset of SGML (Standard Generalized Markup Language) in which elements nest properly inside a single root element.

The current edition of XML (Extensible Markup Language) 1.0 is the fifth, a World Wide Web Consortium (W3C) Recommendation of 26 November 2008. It separates two levels: a data object is an XML document only if it is well-formed, and it is valid only if it also has a document type declaration and meets the constraints expressed in it. Breaking a well-formedness rule is a fatal error, after which a conforming processor must stop processing the document normally, which is why one unescaped & or < outside markup can stop a whole import. The DOCTYPE, where entities are declared, is also where XXE (XML external entity) attacks begin.

Where it came from. XML (Extensible Markup Language) was written by a working group formed under the World Wide Web Consortium (W3C) in 1996, first called the SGML Editorial Review Board, chaired by Jon Bosak of Sun Microsystems with Dan Connolly as the W3C's contact. Its goal was to let generic SGML (Standard Generalized Markup Language, ISO 8879:1986) be served, received and processed on the web the way HTML (HyperText Markup Language) already was, so XML is defined as a subset of SGML that the specification describes completely. The first Recommendation is dated 10 February 1998; the fifth edition of 26 November 2008, edited by Tim Bray, Jean Paoli, C. M. Sperberg-McQueen, Eve Maler and François Yergeau, is the current one. Two of its ten design goals explain a lot of later practice: the number of optional features should be kept to the absolute minimum, ideally zero, and terseness in markup is of minimal importance.

Well-formed versus valid. Well-formedness is the grammar every XML processor must enforce. There is exactly one root element, also called the document element, and every other element nests properly inside it; the name in an end-tag must match the name in its start-tag; an attribute name may appear only once in the same tag; and the ampersand and the left angle bracket must not appear literally except as markup delimiters or inside a comment, a processing instruction or a CDATA section. Elsewhere they are written as entity or character references, and XML predefines five entities for that purpose: amp, lt, gt, apos and quot. Validity is the further level: a document type declaration (DOCTYPE) and a document that satisfies the constraints declared in it. Every processor must accept the UTF-8 and UTF-16 encodings of Unicode.

Fatal means fatal. The specification calls a violation of well-formedness a fatal error: the processor must detect and report it, may keep scanning to report further errors, but must not continue normal processing, which means it must not keep passing character data and structure to the application as usual. That rule is deliberate, so a single stray ampersand in a value exported from a database, or a truncated file, makes the whole document unusable rather than slightly wrong.

The versions around it. XML 1.1, whose second edition dates from 16 August 2006, exists mainly for line ends and control characters: it adds NEL (#x85), the line end of IBM mainframe conventions, and the Unicode line separator #x2028; allows character references to the control characters #x1 to #x1F; requires #x7F to #x9F to appear only as references; and still forbids #x0. Namespaces in XML 1.0, in its third edition of 8 December 2009, is the separate recommendation that lets one document mix vocabularies. Request for Comments (RFC) 7303 (July 2014) registers application/xml, keeps text/xml as an alias and standardizes the +xml suffix for other XML-based media types.

Where engineers meet it. The Network Configuration Protocol (NETCONF), RFC 6241 of June 2011, encodes both configuration data and protocol messages in XML and carries its operations as remote procedure calls, so XML is what a router or switch exchanges with an automation system that speaks NETCONF. SAML (Security Assertion Markup Language) 2.0 messages are XML documents, deflated and Base64-encoded into a Uniform Resource Locator (URL) in the Redirect binding or Base64-encoded into a form in the POST binding, which is why single sign-on troubleshooting starts with a decoder.

The DOCTYPE is the attack surface. Entities declared in a DOCTYPE can point outside the document, and the OWASP (Open Worldwide Application Security Project) cheat sheet defines XML external entity (XXE) injection as a processor resolving such an entity from untrusted input, which can expose local files, cause server-side request forgery (SSRF) or exhaust resources. MITRE's Common Weakness Enumeration entry CWE-611 gives the classic payloads: a file:// Uniform Resource Identifier (URI) that reads /etc/passwd back into the response, and an http:// URI that makes the server fetch from hosts the attacker cannot reach, bypassing firewalls or hiding a port scan. Entity expansion is the other half: the billion laughs attack nests entities that each reference the previous one several times until a few hundred bytes expand into gigabytes, and the quadratic blowup repeats one large entity to slip under limits on nesting. Defaults have improved, unevenly: OWASP notes that libxml2 disabled XXE by default from version 2.9, and the Python documentation says Expat neither reads local files nor opens connections by default but that versions before 2.7.2 may still be vulnerable to billion laughs and quadratic blowup. The safe rule in every language is the same: disable document type definitions (DTDs) entirely or reject any DOCTYPE, keep XInclude off, and remember that blocking XXE does not by itself stop every XML denial of service.

Numbers worth remembering: 1998 for the first Recommendation and 26 November 2008 for the fifth edition; one root element; five predefined entities; UTF-8 and UTF-16 mandatory for every processor; and XML 1.1's #x85 and #x2028 as the only new line ends.

Also known as: extensible markup language, xml 1.0, well-formed xml, well-formedness

Sources

← Back to X Back to the glossary