Skip to content

Commit 93caa1a

Browse files
committed
Set safe defaults for parser settings
The library should be safe by default and potentially unsafe features should be explicitly enabled by the user if needed.
1 parent bfc8957 commit 93caa1a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

shared/src/main/scala/scala/xml/factory/XMLLoader.scala

+12-3
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,18 @@ trait XMLLoader[T <: Node] {
2525

2626
/* Override this to use a different SAXParser. */
2727
def parser: SAXParser = {
28-
val f = SAXParserFactory.newInstance()
29-
f.setNamespaceAware(false)
30-
f.newSAXParser()
28+
val parser = SAXParserFactory.newInstance()
29+
30+
parser.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true)
31+
parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false)
32+
parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true)
33+
parser.setFeature("http://xml.org/sax/features/external-parameter-entities", false)
34+
parser.setFeature("http://xml.org/sax/features/external-general-entities", false)
35+
parser.setFeature("http://xml.org/sax/features/resolve-dtd-uris", false)
36+
parser.setXIncludeAware(false)
37+
parser.setNamespaceAware(false)
38+
39+
parser.newSAXParser()
3140
}
3241

3342
/**

0 commit comments

Comments
 (0)