This site is the archived OWASP Foundation Wiki and is no longer accepting Account Requests.
To view the new OWASP Foundation website, please visit https://owasp.org
Talk:XML External Entity (XXE) Processing
XXE Prevention in Java / Using an own EntiyResolver Implementation?
Context: We write Java Software, used in quite different environment (div. Operating System, OpenJDK, IBM-JDK, Sun-JDK, JDK 6 - JDK8). I am not really happy with the described solution to prevent External Entity Injection, because it is depending on some special XML parser Implementations.
To prevent External Entity Injection flaws we primarily use our own EntityResolver and we think this alone should be enough to ensure that the parser can not access resources via URL´s from SGML Entity Declarations.
Our Entity Resolver looks like:
public class SecureEntityResolver implements EntityResolver { @Override public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException { return new InputSource(new ByteArrayInputStream("".getBytes())); } }
When parsing XML we register our Entity-Resolver
DocumentBuilderFactory newFactory = DocumentBuilderFactory.newInstance(); newFactory.setNamespaceAware(true); DocumentBuilder builder = newFactory.newDocumentBuilder(); builder.setEntityResolver(new SecureEntityResolver()); /* !!!! */ Document doc = builder.parse(...);
Does anyone see problems with this way to prevent XXE Injection attacks?
--PeterPichler (talk) 10:40, 4 February 2015 (CST)
- I like your approach in general because it gets away from the silliness of each processor. Have you ran different test cases to see what happens? Even better, could you enable the Java security manager and grant only file access to the test case? I'm interested in seeing if a network connection is attempted during the resolution. --Jon Passki (talk)
- I do not have the resources to make extensive tests currently. We had an white box security review of our software, and our security review partner (SecConsult) found an XXE Entity Injection Flaw. We was able to reproduce it... When using our own EntityResolver, it was not possible any more to access local resources. With this entity resolver we passed the recheck (by the company detected the XXE bug). This summer we will have a recheck again. I will stress this topic again during recertification... and try to bring back infos to this page. --PeterPichler (talk) 10:40, 4 February 2015 (CST)