XML external entities: parsers that fetch and read on behalf of a document

How 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.

Lesson 19 of 69 · 12 min read · practice only with authorization

Diagram

A parser following an entity

Follow the path. One example at a time.

Step 1 of 4

Upload

A user submits XML: an API body, an SVG, or a document.

Illustration: Upload
# Upload
# A user submits XML: an API body, an SVG, or a document.

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

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

  1. XML is everywhere

    What fails
    SOAP APIs, SAML assertions, SVG images, RSS feeds, and DOCX and XLSX files are all XML.
    Who is affected
    Servers that parse any of those formats.
    What you would notice
    An upload or import feature that accepts those file types.
    What you change
    Inventory every parser and configure each to refuse DTDs.
  2. Defaults vary

    What fails
    Some libraries resolve external entities by default, especially older Java and PHP configurations.
    Who is affected
    Applications that rely on defaults.
    What you would notice
    A parser created with no security features set.
    What you change
    Set the features explicitly and test them.
  3. Blind variants

    What fails
    XXE can fetch URLs without showing content, which works like SSRF.
    Who is affected
    Internal services reachable from the parser host.
    What you would notice
    Outbound requests from a parsing service.
    What you change
    Disable DTDs and restrict egress from parsing services.

Confirming safely in a lab

Submit a small document whose external entity points at a canary URL you control. A request arriving at the canary shows the parser resolves external entities, without reading any local file.

<?xml version="1.0"?>
<!DOCTYPE note [ <!ENTITY probe SYSTEM "https://canary.example.net/hb-xxe-7731"> ]>
<note>&probe;</note>

# canary log: GET /hb-xxe-7731 from 203.0.113.80 -> parser resolves external entities

Review walkthrough

Search for parser construction and check each for DTD settings. Dependencies count: a PDF, Office, or SAML library may parse XML internally with its own configuration.

Related pages

XInclude and Office documents covers formats that hide XML, and parsers in dependencies covers libraries you did not configure yourself.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

Which Java feature disables DOCTYPE declarations?

Go deeper

Specific techniques, exercises, and glossary cards for this topic.

  1. 01XInclude and XML features that fetchTurning off one entity switch is not the whole parser. Includes the diagram and a defensive fix.
  2. 02XML parsers you did not configureA dependency can parse XML with its own defaults even when your code’s parser is hardened. Includes the diagram and a defensive fix.

Exercises

  1. 01Control benchAn XML parser is still resolving external references. Choose the setting that turns that off.