Skip to content

Commit

Permalink
#28 Disable downloading external resources with DocumentHelper.parseT…
Browse files Browse the repository at this point in the history
…ext() helper.
  • Loading branch information
FilipJirsak committed Jul 1, 2018
1 parent 983701f commit 8f6a7f6
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 19 deletions.
14 changes: 7 additions & 7 deletions .idea/modules/dom4j_main.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions .idea/modules/dom4j_test.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 10 additions & 5 deletions build.gradle
Expand Up @@ -19,17 +19,16 @@ repositories {

dependencies {

compileOnly(
implementation(
'jaxen:jaxen:1.1.6',
'javax.xml.stream:stax-api:1.0-2',
'net.java.dev.msv:xsdlib:2013.6.1',
'xpp3:xpp3:1.1.4c',
'pull-parser:pull-parser:2',
'javax.xml.bind:jaxb-api:2.2.12',
'pull-parser:pull-parser:2',
'xpp3:xpp3:1.1.4c',
)


testCompile(
testImplementation(
'org.testng:testng:6.8.21',

'xerces:xercesImpl:2.11.0',
Expand Down Expand Up @@ -89,6 +88,12 @@ publishing {
developerConnection = 'scm:git:git@github.com:dom4j/dom4j.git'
url = 'git@github.com:dom4j/dom4j.git'
}

withXml {
asNode().dependencies.dependency.findAll { xmlDep ->
xmlDep.appendNode('optional').value = 'true'
}
}
}
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/dom4j/DocumentHelper.java
Expand Up @@ -18,6 +18,7 @@
import org.jaxen.VariableContext;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/**
* <code>DocumentHelper</code> is a collection of helper methods for using
Expand Down Expand Up @@ -256,6 +257,8 @@ public static void sort(List<Node> list, String expression, boolean distinct) {
* <code>parseText</code> parses the given text as an XML document and
* returns the newly created Document.
* </p>
*
* Loading external DTD and entities is disabled (if it is possible) for security reasons.
*
* @param text
* the XML text to be parsed
Expand All @@ -267,6 +270,14 @@ public static void sort(List<Node> list, String expression, boolean distinct) {
*/
public static Document parseText(String text) throws DocumentException {
SAXReader reader = new SAXReader();
try {
reader.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
} catch (SAXException e) {
//Parse with external resources downloading allowed.
}

String encoding = getEncoding(text);

InputSource source = new InputSource(new StringReader(text));
Expand Down

0 comments on commit 8f6a7f6

Please sign in to comment.