Quick revision
The short answer
XML parsing often happens inside libraries: SOAP clients, SAML libraries, Apache POI reading the XML inside .xlsx files, SVG and RSS processing and configuration loaders. Spring MVC also registers XML message converters automatically when Jackson's XML module or Jakarta XML Binding is on the classpath, so an endpoint may quietly accept application/xml. We find these with a dependency and code search and by sending requests with Content-Type: application/xml, and fix them by removing unneeded converters, upgrading libraries to secure versions, configuring parser factories centrally, and adding an automated test that sends an XXE payload and asserts it is rejected.
What to remember
In this answer, we saw that a service can parse XML without anyone writing parser code: SOAP and SAML libraries, Apache POI reading .xlsx files, SVG and feed processing, configuration loaders, and Spring MVC's XML message converters registered automatically when Jackson XML or Jakarta XML Binding is on the classpath. We found the parser with the scanner's evidence, a dependency and code search, and requests with Content-Type: application/xml, fixed it by removing unneeded converters, upgrading libraries and configuring factories centrally, and added a test that sends an XXE payload and asserts rejection.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
XML parsing often happens inside libraries: SOAP clients, SAML libraries, Apache POI reading the XML inside .xlsx files, SVG and RSS processing and configuration loaders. Spring MVC also registers XML message converters automatically when Jackson's XML module or Jakarta XML Binding is on the classpath, so an endpoint may quietly accept application/xml. We find these with a dependency and code search and by sending requests with Content-Type: application/xml, and fix them by removing unneeded converters, upgrading libraries to secure versions, configuring parser factories centrally, and adding an automated test that sends an XXE payload and asserts it is rejected.
Why this question is asked
Security scanners do not care whether our own code mentions XML. They test the running service or inspect its dependencies, and when one reports XXE, XML External Entity injection, the first reaction of the team is often that it must be a false positive. Sometimes it is, but often the parsing is real and simply hidden. Interviewers ask this debugging question to see whether we know where XML hides in a Spring application and how to investigate methodically. In this answer, we will list the hidden places, see how Spring MVC can accept XML without anyone asking for it, find the parser step by step, fix it, and lock the fix in with a test.
1Where XML Parsing Hides
XXE is possible wherever a parser processes untrusted XML with external entities enabled, whether we wrote the parser call or a library did. Many common libraries parse XML internally. SOAP clients and servers parse every message. SAML libraries parse identity provider responses in single sign-on flows. Apache POI reads .xlsx and .docx files, which are zip archives of XML documents, so an upload of a crafted spreadsheet goes through an XML parser; older POI versions had XXE vulnerabilities. Image libraries that handle SVG parse XML, as do RSS and Atom feed readers, sitemap processors and some configuration loaders.
So the honest answer to 'we never parse XML' is usually 'we never wrote DocumentBuilder', which is a different statement. The question to ask is: which untrusted bytes reach an XML parser, through any path?
| Path | Who parses | Untrusted input? |
|---|---|---|
@RequestBody with application/xml | Spring XML message converter | yes, any client |
| File upload of .xlsx or .docx | Apache POI | yes, the uploaded file |
| SAML single sign-on | SAML library | yes, the assertion |
| SOAP client response | JAX-WS or CXF runtime | partly, the partner |
| SVG upload or image processing | SVG library | yes, the image |
| Feed or sitemap import | feed library | yes, the remote feed |
2How Spring MVC Accepts XML Without Being Asked
Spring MVC converts request bodies with HttpMessageConverters, and it registers some of them automatically based on what is on the classpath. If Jackson's XML module (jackson-dataformat-xml) is present, Spring adds a Jackson XML converter; if Jakarta XML Binding is present without it, Spring adds a JAXB converter for annotated classes. The exact converter class names differ between Spring Framework 6 and 7, so check your version.
The consequence is that a controller written for JSON, @PostMapping("/orders") with @RequestBody OrderRequest, may also accept the same object as XML. Nobody on the team chose this; a transitive dependency, perhaps added for a reporting library, pulled jackson-dataformat-xml in. The scanner sends Content-Type: application/xml with an entity payload, and the endpoint parses it. Whether that parse is exploitable depends on how the converter's parser is configured; Spring's own converters disable external entities by default in current versions, but a custom converter, an old version or a library's own parser may not.
3Finding the Parser Step by Step
We investigate from three directions. First, the scanner report itself: which URL, which request, which response proved the issue. That points to a specific endpoint or upload. Second, the dependencies: we list the full tree and look for XML-related libraries, and we search the code and configuration for parser factories and converter registrations. Third, the running service: we send XML to endpoints ourselves and see which accept it.
- Read the scanner evidenceURL, payload, response
- List dependencies and search codeXML libraries, parser factories, converters
- Send application/xml to the endpoints201 or 400 means XML is parsed
- Is XML needed on that path?YesHarden the parser and upgrade the libraryNoRemove the converter or dependency
- Add an XXE regression testpayload must be rejected
5 steps in order. Play them, or step through them one at a time.
A 415 Unsupported Media Type response means the endpoint does not accept XML; a 2xx or a 400 with a parse error means an XML converter handled it. For uploads, we check which library opens each accepted file type. Only test against environments we own, never against production systems of others.
4Fixing It
If nobody needs XML on the endpoint, the cleanest fix removes the capability. We exclude the transitive jackson-dataformat-xml dependency if nothing uses it, or remove XML converters in the MVC configuration, or restrict the mappings with consumes = MediaType.APPLICATION_JSON_VALUE so other content types get a 415. Less attack surface is better than a well-configured parser we do not need.
Where XML is needed, for SOAP, SAML or spreadsheet uploads, we upgrade the libraries to versions with secure defaults and fixed CVEs, and we make sure every parser we create comes from a shared factory class that disallows DOCTYPE declarations or disables external entities, with ACCESS_EXTERNAL_DTD and ACCESS_EXTERNAL_SCHEMA set to empty. Libraries that accept a parser factory or have their own secure option get it configured explicitly rather than relying on defaults.
5Locking the Fix In With a Test
Finally, we add an automated test so the problem cannot return with the next dependency change. It sends an XXE payload to each endpoint that might parse XML and asserts that the request is rejected and the response contains nothing from the file.
Similar tests upload a spreadsheet containing an entity declaration and post a crafted SAML response in the test environment. Together with dependency scanning in CI, they turn a one-off scanner finding into a permanent guard.
6Follow-up questions
How do you know whether the finding is a false positive?
We reproduce it. If the scanner's payload, sent by us to a test environment, produces file content, an outbound request to a host we control, or a parse that accepted the DOCTYPE, it is real. If every XML request gets a 415 or a DOCTYPE rejection and no library parses the input, we document the evidence and mark it as a false positive with an expiry date for review.
Why remove the converter instead of just configuring it securely?
Because an unused feature is pure risk. Even a securely configured XML converter widens the attack surface, adds parsing cost and may expose different validation behaviour than the JSON path. If no client sends XML, rejecting it with 415 is simplest and safest.
Can dependency scanning alone catch this?
It catches known vulnerable library versions, such as an old POI or dom4j, but not insecure configuration in our own code or a converter that is enabled but secure. Dynamic tests that send XML to the running service and code search for parser factories are needed as well.
7Conclusion
In this answer, we saw that a service can parse XML without anyone writing parser code: SOAP and SAML libraries, Apache POI reading .xlsx files, SVG and feed processing, configuration loaders, and Spring MVC's XML message converters registered automatically when Jackson XML or Jakarta XML Binding is on the classpath. We found the parser with the scanner's evidence, a dependency and code search, and requests with Content-Type: application/xml, fixed it by removing unneeded converters, upgrading libraries and configuring factories centrally, and added a test that sends an XXE payload and asserts rejection.
Open with
My first point would be that not writing DocumentBuilder is not the same as not parsing XML. Lots of libraries parse XML internally: SOAP clients, SAML libraries for single sign-on, Apache POI when someone uploads an xlsx, which is a zip of XML files, SVG processing, RSS feeds, some config loaders.
Then, if they want more
And Spring MVC registers XML message converters automatically when jackson-dataformat-xml or Jakarta XML Binding is on the classpath, often through a transitive dependency, so a controller written for JSON may happily accept application/xml.
To find it, I start from the scanner's evidence, which endpoint and which payload, then run a dependency tree filtered for XML libraries to see what pulled them in, search the code for parser factories and converter configuration, and send a small XML body with Content-Type application/xml to the endpoints in a test environment: a 415 means no, a 201 or a 400 parse error means yes.
To fix it, if we do not need XML, I remove the capability: exclude the dependency, remove the converter, or restrict consumes to JSON. If we need XML, I upgrade the libraries to versions with secure defaults and create every parser through a shared factory that disallows doctype declarations.
Then I add a test that posts an XXE payload and asserts a 4xx and no leaked content, so it cannot come back.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Spring Framework 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "A security scanner reports XXE in a Spring service, but developers say they never parse...": https://scrivio-interview-library.netlify.app/java/xml-processing/dd08805f53/