这是你需要做的:
使用基于 Web 的反编译器 ( www.javadecompilers.com ),您可以获得 jar 文件 jackson-all-1.9.11.jar 的所有源代码。(这适用于任何版本的 Jackson )
The fixes are fairly simple!
In the 1.9.x version the following 2 files allow XML entity injection.
org/codehaus/jackson/xc/DomElementJsonDeserializer.java
org/codehaus/jackson/map/ext/DOMDeserializer.java
When you update the jar be sure to update the additional nested inner classes.
org/codehaus/jackson/map/ext/DOMDeserializer.class
org/codehaus/jackson/map/ext/DOMDeserializer$DocumentDeserializer.class
org/codehaus/jackson/map/ext/DOMDeserializer$NodeDeserializer.class
org/codehaus/jackson/xc/DomElementJsonDeserializer.class
In the 2.x.x version the package name has changed.
These files need to be modified
com/fasterxml/jackson/databind/ext/DOMDeserializer.java
com/fasterxml/jackson/dataformat/xml/XmlFactory.java
在 1.9 版本中停止实体注入的解决方案是在这两个文件中添加以下行。
.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
这里是将它添加到反编译代码的位置,然后重新编译文件,并更新 jar 文件。
public abstract class DOMDeserializer<T>
extends FromStringDeserializer<T> {
static final DocumentBuilderFactory _parserFactory;
static {
_parserFactory = DocumentBuilderFactory.newInstance();
/* CVE-2016-3720 */
try {
_parserFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
// Move this line from the static block lower in the file.
_parserFactory.setNamespaceAware(true);
}
public DomElementJsonDeserializer() {
super(Element.class);
try {
DocumentBuilderFactory bf = DocumentBuilderFactory.newInstance();
bf.setNamespaceAware(true);
/* CVE-2016-3720 */
bf.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
this.builder = bf.newDocumentBuilder();
}
catch (ParserConfigurationException e) {
throw new RuntimeException();
}
}
在 2.x 版本中,您需要稍微修改这个文件。添加行:
xmlIn.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE);
package com.fasterxml.jackson.dataformat.xml;
public class XmlFactory
extends JsonFactory {
protected XmlFactory(ObjectCodec oc, int xpFeatures, int xgFeatures, XMLInputFactory xmlIn, XMLOutputFactory xmlOut, String nameForTextElem) {
super(oc);
this._xmlParserFeatures = xpFeatures;
this._xmlGeneratorFeatures = xgFeatures;
this._cfgNameForTextElement = nameForTextElem;
if (xmlIn == null) {
xmlIn = XMLInputFactory.newInstance();
xmlIn.setProperty("javax.xml.stream.isSupportingExternalEntities", Boolean.FALSE);
}
我希望你觉得这很有帮助。