Skip to content
This repository has been archived by the owner on Jan 23, 2020. It is now read-only.

Commit

Permalink
Prevent XXE-vulnerability
Browse files Browse the repository at this point in the history
DEV-1863
  • Loading branch information
LodrKumquat committed Aug 1, 2017
1 parent ea25cb0 commit ac55909
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/itextpdf/rups/model/XfaFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.StringReader;

import org.dom4j.Document;
import org.dom4j.DocumentException;
Expand All @@ -55,6 +56,9 @@
import org.dom4j.io.XMLWriter;

import com.itextpdf.rups.io.OutputStreamResource;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

/** Class that deals with the XFA file that can be inside a PDF file. */
public class XfaFile implements OutputStreamResource {
Expand All @@ -76,6 +80,7 @@ public XfaFile(OutputStreamResource resource) throws IOException, DocumentExcept
resource.writeTo(baos);
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
SAXReader reader = new SAXReader();
reader.setEntityResolver(new SafeEmptyEntityResolver());
xfaDocument = reader.read(bais);
}

Expand All @@ -98,4 +103,10 @@ public void writeTo(OutputStream os) throws IOException {
XMLWriter writer = new XMLWriter(os, format);
writer.write(xfaDocument);
}

private static class SafeEmptyEntityResolver implements EntityResolver {
public InputSource resolveEntity(String publicId, String systemId) throws SAXException, IOException {
return new InputSource(new StringReader(""));
}
}
}

0 comments on commit ac55909

Please sign in to comment.