aws-sdk-java: "Unable to configure DocumentBuilderFactory to protect against XXE attacks", 1.1.709+
While working with a complex legacy project I’m running into the following exception when calling receiveMessage to grab messages from an SQS queue.
Relevant stack trace:
[08:31:58.924 WARN pair-718-27 mazonaws.util.XpathUtils] Unable to configure DocumentBuilderFactory to protect against XXE attacks
java.lang.IllegalArgumentException: Property 'http://xml.org/sax/features/external-general-entities' is not recognized.
at org.apache.xerces.jaxp.DocumentBuilderFactoryImpl.setAttribute(Unknown Source)
at com.amazonaws.util.XpathUtils.configureXercesFactory(XpathUtils.java:674)
at com.amazonaws.util.XpathUtils.initialConfigureDocumentBuilderFactory(XpathUtils.java:655)
at com.amazonaws.util.XpathUtils.configureDocumentBuilderFactory(XpathUtils.java:643)
at com.amazonaws.util.XpathUtils.documentFrom(XpathUtils.java:178)
at com.amazonaws.util.XpathUtils.documentFrom(XpathUtils.java:192)
at com.amazonaws.http.DefaultErrorResponseHandler.parseXml(DefaultErrorResponseHandler.java:124)
at com.amazonaws.http.DefaultErrorResponseHandler.documentFromContent(DefaultErrorResponseHandler.java:105)
at com.amazonaws.http.DefaultErrorResponseHandler.createAse(DefaultErrorResponseHandler.java:84)
at com.amazonaws.http.DefaultErrorResponseHandler.handle(DefaultErrorResponseHandler.java:71)
at com.amazonaws.http.DefaultErrorResponseHandler.handle(DefaultErrorResponseHandler.java:47)
at com.amazonaws.http.AwsErrorResponseHandler.handleAse(AwsErrorResponseHandler.java:53)
at com.amazonaws.http.AwsErrorResponseHandler.handle(AwsErrorResponseHandler.java:41)
at com.amazonaws.http.AwsErrorResponseHandler.handle(AwsErrorResponseHandler.java:26)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleErrorResponse(AmazonHttpClient.java:1724)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.handleServiceErrorResponse(AmazonHttpClient.java:1371)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeOneRequest(AmazonHttpClient.java:1347)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeHelper(AmazonHttpClient.java:1127)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.doExecute(AmazonHttpClient.java:784)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.executeWithTimer(AmazonHttpClient.java:752)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.execute(AmazonHttpClient.java:726)
at com.amazonaws.http.AmazonHttpClient$RequestExecutor.access$500(AmazonHttpClient.java:686)
at com.amazonaws.http.AmazonHttpClient$RequestExecutionBuilderImpl.execute(AmazonHttpClient.java:668)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:532)
at com.amazonaws.http.AmazonHttpClient.execute(AmazonHttpClient.java:512)
at com.amazonaws.services.sqs.AmazonSQSClient.doInvoke(AmazonSQSClient.java:2207)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2174)
at com.amazonaws.services.sqs.AmazonSQSClient.invoke(AmazonSQSClient.java:2163)
at com.amazonaws.services.sqs.AmazonSQSClient.executeReceiveMessage(AmazonSQSClient.java:1607)
at com.amazonaws.services.sqs.AmazonSQSClient.receiveMessage(AmazonSQSClient.java:1578)
Rolling back to 1.1.708 appears to fix the issue.
It looks like this is coming from the additional DocumentBuilderFactory configuration added in XPathUtils in 1.1.709.
This project has its xerces:xercesImpl pinned at 2.12.0 in the Maven POM but there are a ton of XML-related transitives and force-pins in other project submodules it needs to import. I’ve tried a few paths, like excluding XML-related imports and overriding transitive versions with newer (or older) versions, to see if those imports are causing problems to no avail.
The project’s dependency tree is attached for reference.
aws-sdk-xml-documentbuilderfactory-issue-maven-dependency-tree.txt
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Comments: 21 (6 by maintainers)
Just ran into this warning as well. Per this and OWASP, you should use the setFeature method and not the setAttribute method with an empty string :
We have updated the AWS SDK for Java, version 1.11.925 and newer, to correct instances where the Apache Xerces library was used incorrectly when parsing XML documents.
@dagnir no POM to speak of, since it’s (a) gradle and (b) a transitive dependency, but the jar that’s pulled in is xerces:xercesImpl:2.11.0. the dependency tree shown by
gradle dependencyInsight --dependency xercesImpllooks like this: