XInclude and XML features that fetch
Turning off one entity switch is not the whole parser. XInclude, external schemas, and office or SVG documents can still make the server read or fetch.
Diagram
From a document you meant to display to a parser that fetches
Step 1 of 4
Document
Someone uploads XML, SVG, or an office file. You meant to read the elements or the text.
# An office file is a package of XML. # The feature needs the text, not a fetch.
Entities are off, XInclude is on.
The caller controls the bytes.
The server may still pull in another resource.
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.
One switch is not the parser
- What fails
- Entity flags, XInclude, and schema locations are different features. Disabling the one you remember leaves the others.
- Who is affected
- Owners of files or internal hosts the parser can still reach.
- What you would notice
- A configuration that sets two flags and leaves the factory defaults for the rest.
- What you change
- Set the full list from your parser’s current hardening guide. Add a test that a document type is rejected.
Office and SVG
- What fails
- Documents that are “not XML” to the product are XML to the library inside the converter.
- Who is affected
- The person who uploads, and anyone whose file the converter can read while it renders a preview.
- What you would notice
- A preview pipeline that accepts office files or SVG and uses a default XML parser.
- What you change
- Configure that parser too, or reject the format until you can.
The process identity
- What fails
- A parser that cannot fetch is still running as a user. Keep that user from reading the rest of the disk.
- Who is affected
- Everyone who shares the host if the user is broad and a feature was missed.
- What you would notice
- The XML parser runs as the same account that owns the deployment.
- What you change
- Parse as a limited user. Do not give it the application’s general file access.
Prefer a boring format
- What fails
- JSON or a constrained schema does not have an include feature. That is a better control than a perfect flag list you must repeat in every service.
- Who is affected
- Future readers of a document format you did not need.
- What you would notice
- An endpoint that accepts XML because a sample did.
- What you change
- Change the contract if you can. Keep the flags if you cannot.
The parser has more than one way to fetch
XML external entity bugs are described as a document type that names an external file. Parsers grew other features that do the same kind of work: XInclude, external schema locations, and catalog resolvers. A hardening snippet copied from a single blog often sets the entity flags and leaves XInclude on its default. The document can still ask the server to pull something in.
Read the hardening notes for the parser version you actually ship. Set every feature that loads an external resource to off. Reject document types. Then add a test that a document which declares a document type fails to parse. The test fixture can be a minimal document in the repo. You do not need it to point at a real file.
Office files and SVG are XML in disguise
A preview that accepts office documents is often a zip of XML plus a parser you did not configure. SVG is XML with a different extension. If those pipelines use a default factory, they are XML endpoints whether or not the route says “upload image.” Configure them, or reject the type until you do.
Converters sometimes shell out. That is a second problem, covered with the command-injection pages. The XML configuration still has to be set in-process. One fix does not imply the other.
What a successful include would see
The impact is the application user’s view of the disk and the network, not the uploader’s. A parser that cannot leave the process is a much smaller bug than a parser that can read configuration or reach an internal HTTP service. Run parsing with the least file access you can. Do not put secrets in files next to the app “because the parser is probably fine.”
You would notice an XML dependency added for one endpoint, a default factory, and an office preview that nobody listed in the XML inventory. The inventory is the work. The finding names the endpoint and the flags. It does not include the contents of a file the parser might have opened.
What you change
One factory helper should build every parser in the process, with the safe flags, and nobody should call the raw constructor. Prefer JSON or a closed schema for new features. Keep the helper even so, because a transitive library may still parse XML.
Review dependencies for a second parser. The helper does not configure code that never calls it. A short comment in the helper is not a scan. Look at the lockfile and at preview, import, and SAML or SOAP paths specifically. Those are where XML arrives.
Check yourself
Recognition and the fix. Nothing here is a procedure.
External entities are disabled. XInclude is still aware, and the endpoint accepts SVG. What failed?
Sibling techniques
Pages at the same depth, plus a lab and a glossary card for this one.