XML parsers you did not configure

A dependency can parse XML with its own defaults even when your code’s parser is hardened. The endpoint that accepts the bytes is still yours.

Lesson 65 of 69 · 14 min read · practice only with authorization

Diagram

From your route to a parser inside a library

Follow the path. One example at a time.

Step 1 of 4

Route

Your handler accepts a body or a file and hands the bytes to a library.

Illustration: the route accepts a document
# A route receives a document body.
# A library later in the stack may parse it.
What changes the outcome
Your code

Flags are set on the parser you construct.

Library

It builds a second parser.

Bytes

Untrusted XML reaches the second one.

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

4 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Two parsers, one body

    What fails
    Hardening the parser you call does nothing for the parser a library calls on the same bytes.
    Who is affected
    Owners of files or internal services that second parser can reach.
    What you would notice
    A dependency that mentions XML in its tree, on a route that accepts uploads or SOAP.
    What you change
    Find every parser. Configure it or remove the route’s ability to reach it.
  2. Defaults change across versions

    What fails
    A safe default in the version you read about may not be the version you pin. The pin and the test are the record.
    Who is affected
    The next upgrade that silently swaps defaults.
    What you would notice
    A lockfile bump with no XML test in the suite.
    What you change
    Pin the parser. Keep a test that a document type fails on every endpoint that accepts XML.
  3. An edge filter is not a parser

    What fails
    Rejecting a string in the body is a seatbelt. Encodings and nested documents get past string checks. The parser flags still have to be set.
    Who is affected
    Anyone a bypassed filter can reach through the real parser.
    What you would notice
    A ticket that closes the issue because the route searches for a document-type token.
    What you change
    Keep the parser configuration. Treat the string check as extra, not as the fix.
  4. Where XML hides

    What fails
    SAML, SOAP, RSS, SVG, office previews, and “XML config import” are the routes. So are bill-of-materials and license files if you parse them on upload.
    Who is affected
    The operator who imported a file, and the owners of anything the parser can read.
    What you would notice
    An inventory of XML routes that lists one and misses the SSO callback.
    What you change
    Make the inventory part of review. New XML acceptance has to use the helper.

Your settings do not cross a library boundary

Application code often gets XML right in the one factory the team wrote, then calls a client library that parses a status document, a SAML response, or an office manifest on its own. That library constructs a parser you have never seen, with the defaults of the year it was written. The bytes are the same untrusted bytes.

Treat “we disabled entities” as a claim about a specific object in memory, not about the process. The review item is a list of constructors. If you cannot list them, you do not know the endpoint’s posture.

Pin and test, because defaults move

Parser projects do change defaults after widely discussed bugs. They also fork, wrap, and re-expose settings. Pin the version. Read the notes when you bump it. Keep a test that submits a document with a document type to each XML endpoint and expects rejection. The test is how you notice a wrapper that regressed.

A substring filter at the edge can sit in front of that test as a cheap reject, but it is not the assertion you want. Assert that the hardened parser, or the library configured to use it, is what ran. A filter that returns early can hide a parser that would have accepted the document.

Build the route inventory

Search the codebase and the lockfile for XML parsers, and then search product language for import, SSO, SOAP, SVG, and previews. The second search finds routes the first search names only inside a dependency. Write the list down next to the helper you expect them to use.

People affected are the owners of files and internal services the process can reach if a forgotten parser fetches. That is the impact to put on the ticket. Do not prove it by aiming a document at a real internal file. The missing configuration is the finding.

What you change

Point libraries at your factory when they allow a parser to be injected. Replace libraries that do not and that parse untrusted XML with defaults you cannot change. Reject formats you do not need. One helper, one test per endpoint, one inventory.

When a new dependency brings a parser, the dependency review should ask whether untrusted bytes can reach it. If the answer is yes and the flags are not set, the dependency is not ready to merge. That question is cheaper than a second parser in production.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

Your parser factory disables entities. A library used by the same route builds its own parser with defaults and parses the upload. What failed?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

  1. MapXML external entities: parsers that fetch and read on behalf of a documentHow DTD entity features let an XML document make the parser read local files or fetch URLs, where XML hides (SOAP, SAML, SVG, Office files), and how to disable DTDs in common parsers.
  1. 01XInclude and XML features that fetchTurning off one entity switch is not the whole parser.

Practice

  1. LabControl benchA failure is described. Choose the control that changes the outcome.

Glossary

  1. CardXML external entitiesAn XML parser resolves external references and reads local files or makes network requests while parsing.