2
2
3
3
import java .io .StringReader ;
4
4
5
+ import javax .xml .XMLConstants ;
5
6
import javax .xml .parsers .DocumentBuilderFactory ;
7
+ import javax .xml .parsers .ParserConfigurationException ;
6
8
7
9
import org .w3c .dom .Document ;
8
10
import org .w3c .dom .Node ;
@@ -25,6 +27,25 @@ public abstract class DOMDeserializer<T> extends FromStringDeserializer<T>
25
27
_parserFactory = DocumentBuilderFactory .newInstance ();
26
28
// yup, only cave men do XML without recognizing namespaces...
27
29
_parserFactory .setNamespaceAware (true );
30
+ // [databind#1279]: make sure external entities NOT expanded by default
31
+ _parserFactory .setExpandEntityReferences (false );
32
+ // ... and in general, aim for "safety"
33
+ try {
34
+ _parserFactory .setFeature (XMLConstants .FEATURE_SECURE_PROCESSING , true );
35
+ } catch (ParserConfigurationException pce ) {
36
+ // not much point to do anything; could log but...
37
+ } catch (Error e ) {
38
+ // 14-Jul-2016, tatu: Not sure how or why, but during code coverage runs
39
+ // (via Cobertura) we get `java.lang.AbstractMethodError` so... ignore that too
40
+ }
41
+
42
+ // [databind#2589] add two more settings just in case
43
+ try {
44
+ _parserFactory .setFeature ("http://apache.org/xml/features/disallow-doctype-decl" , true );
45
+ } catch (Throwable t ) { } // as per previous one, nothing much to do
46
+ try {
47
+ _parserFactory .setFeature ("http://apache.org/xml/features/nonvalidating/load-external-dtd" , false );
48
+ } catch (Throwable t ) { } // as per previous one, nothing much to do
28
49
}
29
50
30
51
protected DOMDeserializer (Class <T > cls ) { super (cls ); }
0 commit comments