Scrivio Interview library
LeadershipAdvanced8 min read · updated 12 November 2026

After an XXE incident in one service, you must make sure no service in a 300-service Java estate is vulnerable. How do you organise this?

I would run it as a short, tracked programme with four parts: find every vulnerable parser with static analysis across all repositories, give teams a hardened XML factory library so the fix is one line, scan dependencies for old XML libraries with deadlines by risk, and prove the result with dynamic XXE tests against internet-facing endpoints. Progress is tracked per team and reported to leadership, and the static rules stay in CI afterwards so the problem cannot quietly come back.

Why this question is asked

One XXE incident is rarely a one-off. XXE, short for XML External Entity injection, is a flaw in how a parser is configured, and Java's default XML factories have historically allowed it, so if one team wrote vulnerable code, others almost certainly copied the same pattern. Interviewers ask this question at senior level because the technical fix is easy and the organisational problem is hard: 300 services, dozens of teams, different build tools and different priorities. In this answer, we will recap what makes a Java parser vulnerable, then walk through how to find the problem everywhere, how to make the fix cheap, how to cover dependencies and running systems, and how to track and lock in the result.

1A Quick Recap of XXE in Java

XML allows a document to declare a DTD, a Document Type Definition, and inside it to define entities, which are named pieces of text the parser substitutes when it meets a reference such as &name;. An external entity takes its text from a URI. If an attacker can send XML to our service, they can declare an entity that points at file:///etc/passwd or at an internal URL, and a parser that resolves it will read the file or make the request on their behalf. That is XXE: it leaks files, enables server-side request forgery, and with nested entities can also exhaust memory.

In Java, the vulnerable code usually looks perfectly normal. DocumentBuilderFactory, SAXParserFactory, XMLInputFactory, TransformerFactory, SchemaFactory and libraries built on them may process DTDs unless we switch that off, and the exact defaults have changed between JDK versions and libraries. So the safe position is that every factory must be configured explicitly, and the most reliable setting is to refuse DTDs completely.

Java
// Vulnerable: default factory, DTDs processed
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
Document doc = dbf.newDocumentBuilder().parse(input); // <!ENTITY x SYSTEM "file:///etc/passwd"> may be resolved
// Hardened: refuse any document that has a DOCTYPE
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setXIncludeAware(false);
dbf.setExpandEntityReferences(false);
// parse(...) now throws SAXParseException for a document with a DOCTYPE

Notice that the fix is three lines, but it has to be applied at every place a factory is created. In a 300-service estate that may be thousands of call sites, many inside shared libraries. That is why this is a programme, not a ticket.

2Finding Every Vulnerable Parser With Static Analysis

The first step is to know where we stand. Static analysis tools such as Semgrep or CodeQL ship rules that recognise XML factories created without the hardening features. Because they work on source code, we can run them centrally across every repository in a single afternoon, without waiting for each team to do it.

I would run the scan from a central security pipeline that clones all repositories, and produce one list of findings with the repository, the owning team, the file and line, and whether the service is internet-facing. The last column matters because it decides priority: a vulnerable parser behind a public endpoint that accepts XML is an emergency, while one that only reads a configuration file bundled in the jar is low risk.

Then we add the same rule to every build, configured to fail on new findings only. Failing on existing findings on day one would break hundreds of builds and teams would push to have the rule removed. Failing only on new findings stops the problem from growing while the backlog is worked down.

Step throughRunning the XXE programme
  1. Scan all 300 repositories centrallySemgrep or CodeQL XXE rules
  2. Rank findings by exposureinternet-facing XML input first
  3. Publish the hardened factory librarythe fix becomes one line
  4. Scan dependencies for old XML librariesdeadlines by risk
  5. Run XXE payloads against public endpointsproves the fix works
  6. Track per team, report weeklyuntil the count reaches zero
  7. Keep the rules in CInew findings fail the build

7 steps in order. Play them, or step through them one at a time.

Each step makes the next one cheaper; the last step is what keeps the estate clean.

3Making the Fix Cheap With a Hardened Factory Library

If every team has to research the correct features for each factory, we will get 300 slightly different fixes and some will be wrong. Instead, a small platform team publishes a helper library, for example SafeXml, with one method per factory type that returns a fully hardened instance. The library has its own tests that feed it the classic XXE payloads and assert that each one is refused.

The rule for teams is then simple: never call DocumentBuilderFactory.newInstance() or its siblings directly, always use the helper. We can enforce that with the same static analysis tool, by adding a rule that flags direct factory creation outside the helper library. The reason this works is that it changes the question from 'is this parser configured correctly?', which needs expertise, to 'is this code using the helper?', which anyone can check in review.

Java
public final class SafeXml {
private SafeXml() {}
public static DocumentBuilderFactory documentBuilderFactory() {
try {
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
f.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
f.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
f.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
f.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
f.setXIncludeAware(false);
f.setExpandEntityReferences(false);
return f;
} catch (ParserConfigurationException e) {
throw new IllegalStateException("XML parser cannot be hardened", e); // fail closed
}
}
public static XMLInputFactory xmlInputFactory() {
XMLInputFactory f = XMLInputFactory.newFactory();
f.setProperty(XMLInputFactory.SUPPORT_DTD, false);
f.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
return f;
}
}

Notice the catch block: if the underlying parser does not support a feature, the helper throws instead of silently returning an unsafe factory. Failing closed is the whole point of a security helper.

4Covering Dependencies and Running Systems

Our own code is only half of the picture. Many services parse XML through libraries: SOAP stacks, SAML libraries, document converters, old versions of XStream or of Xerces bundled in the classpath. A dependency scanner, the same kind of tool we use for known vulnerabilities, lists every service that carries an XML library version with a published XXE issue. Each finding gets a patch deadline by risk, for example 7 days for internet-facing services and 30 days for internal ones.

Static analysis can miss cases, such as a parser created through reflection or a library that ignores our settings. So for every internet-facing endpoint that accepts XML, the security team runs dynamic tests: they send real XXE payloads, including an external entity pointing at a server they control, and check whether the service makes the outbound request. A request arriving at that server is undeniable proof, and no request after the fix is the evidence we report.

5Tracking Remediation and Keeping It Fixed

Every finding becomes a ticket in the owning team's backlog with a deadline, and we publish one dashboard: findings per team, how many are overdue, and the trend. A short weekly report to engineering leadership keeps the programme visible without needing meetings with all 40 teams. Teams that cannot meet a deadline must ask for an exception with a reason and a new date, which leadership approves or not. That keeps the decision about risk with the people who own it.

The programme ends when the count reaches zero, but the controls do not. The static analysis rules stay in CI, the dependency scan keeps running, new services start from a template that already uses the helper library, and the incident is written up so new engineers learn why the rule exists. Without that last step, the estate will drift back within a year as people copy parsing code from old answers on the internet.

6Follow-up questions

Why not just upgrade the JDK and rely on its defaults?

Because the defaults differ between factories, between JDK versions and between parser implementations that a library may bring onto the classpath, such as an old Xerces. Some settings only restrict external access and still process inline DTDs, which leaves entity expansion attacks possible. Explicit hardening in one helper gives the same behaviour everywhere and can be tested.

What if a partner really needs DTDs?

That is rare, but when it happens we treat it as an exception with an owner. The service still disables external entities and external DTD access, allows only a bundled local DTD through a custom entity resolver, and sets limits on entity expansion. The exception is recorded and reviewed regularly.

How do you prioritise 1,000 findings?

By exposure first and ease second. Endpoints that accept XML from the internet come first, then internal services that accept XML from other teams or partners, then code that parses only trusted bundled files. Within each group, fixes that are a one-line switch to the helper library can be done in bulk with an automated pull request.

7Conclusion

In this answer, we saw that fixing XXE across 300 services is an organisational problem built on a simple technical fix. We find every vulnerable parser with central static analysis, make the fix cheap with a hardened factory library and a rule that requires it, cover libraries with dependency scanning and running systems with dynamic XXE tests, and track each team's remediation against deadlines with regular reports to leadership. Finally, we keep the rules in CI so the problem cannot return.

What to say in the interviewAbout 80 seconds aloud

Open with

I would treat it as a programme with a clear end and permanent controls. First, I need to know the scope, so I would run Semgrep or CodeQL XXE rules centrally across all 300 repositories and rank the findings by exposure, with internet-facing endpoints that accept XML at the top.

Then, if they want more

Second, I would make the fix cheap: a small hardened XML factory library that disables DOCTYPE declarations and external entities for each factory type, with its own payload tests, plus a static rule that forbids creating factories directly. That turns a security review into a simple check.

Third, I would scan dependencies for old XML libraries and SOAP or SAML stacks with known issues, with patch deadlines by risk, for example a week for public services and a month for internal ones. Fourth, the security team would run real XXE payloads against public XML endpoints, using an out-of-band server to prove whether a service still resolves entities.

Every finding goes into the owning team's backlog with a deadline, and I would report progress per team to leadership weekly, with an exception process for anyone who cannot meet the date. When we reach zero, the rules stay in CI and the service template uses the helper, so new code starts safe.

About this answer

Last updated
12 November 2026
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 "After an XXE incident in one service, you must make sure no service in a 300-service...": https://scrivio-interview-library.netlify.app/java/xml-processing/3163a81c3c/