Skip to content

Commit

Permalink
OOZIE-2489 XML parsing is vulnerable (fdenes via rkanter)
Browse files Browse the repository at this point in the history
  • Loading branch information
rkanter committed Apr 12, 2016
1 parent b50d642 commit 50fef42
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/src/main/java/org/apache/oozie/cli/OozieCLI.java
Expand Up @@ -752,6 +752,8 @@ private Properties parse(InputStream is, Properties conf) throws IOException {
docBuilderFactory.setXIncludeAware(true);
// ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
docBuilderFactory.setExpandEntityReferences(false);
docBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(is);
return parseDocument(doc, conf);
Expand Down
Expand Up @@ -650,6 +650,7 @@ public void writeToXml(Properties props, OutputStream out) throws IOException {
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(out);
TransformerFactory transFactory = TransformerFactory.newInstance();
transFactory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
Transformer transformer = transFactory.newTransformer();
transformer.transform(source, result);
if (getDebugMode() > 0) {
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/java/org/apache/oozie/util/GraphGenerator.java
Expand Up @@ -101,6 +101,9 @@ public final void finalize() {
*/
public void write(OutputStream out) throws Exception {
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
spf.setNamespaceAware(true);
SAXParser saxParser = spf.newSAXParser();
XMLReader xmlReader = saxParser.getXMLReader();
Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/org/apache/oozie/util/XConfiguration.java
Expand Up @@ -259,6 +259,8 @@ private void parse(InputStream is) throws IOException {
docBuilderFactory.setXIncludeAware(true);
// ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
docBuilderFactory.setExpandEntityReferences(false);
docBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(is);
parseDocument(doc);
Expand All @@ -281,6 +283,8 @@ private void parse(Reader reader) throws IOException {
docBuilderFactory.setXIncludeAware(true);
// ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
docBuilderFactory.setExpandEntityReferences(false);
docBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder builder = docBuilderFactory.newDocumentBuilder();
Document doc = builder.parse(new InputSource(reader));
parseDocument(doc);
Expand Down
1 change: 1 addition & 0 deletions core/src/main/java/org/apache/oozie/util/XmlUtils.java
Expand Up @@ -350,6 +350,7 @@ public static String writePropToString(Properties props) throws IOException {
StringWriter stringWriter = new StringWriter();
Result result = new StreamResult(stringWriter);
TransformerFactory factory = TransformerFactory.newInstance();
factory.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
Transformer transformer = factory.newTransformer();
transformer.transform(source, result);

Expand Down
1 change: 1 addition & 0 deletions release-log.txt
@@ -1,5 +1,6 @@
-- Oozie 4.3.0 release (trunk - unreleased)

OOZIE-2489 XML parsing is vulnerable (fdenes via rkanter)
OOZIE-2485 Oozie client keeps trying to use expired auth token (rkanter)
OOZIE-2490 Oozie can't set hadoop.security.token.service.use_ip (rkanter)
OOZIE-2474 <job-xml> is not being applied to the launcher job (rkanter)
Expand Down
Expand Up @@ -103,6 +103,8 @@ static Document getDocumentFromXML(String prepareXML) throws ParserConfiguration
docBuilderFactory.setXIncludeAware(true);
// ignore all comments inside the xml file
docBuilderFactory.setIgnoringComments(true);
docBuilderFactory.setExpandEntityReferences(false);
docBuilderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
InputStream is = new ByteArrayInputStream(prepareXML.getBytes("UTF-8"));
return docBuilder.parse(is);
Expand Down

0 comments on commit 50fef42

Please sign in to comment.