Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions src/main/java/org/takes/rs/xe/RsXembly.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,20 @@ private static InputStream render(final Node dom,
return new ByteArrayInputStream(baos.toByteArray());
}

/**
* Create empty DOM Document.
* @return Document
*/
private static Document emptyDocument() {
private static Document emptyDocument() {
try {
return DocumentBuilderFactory.newInstance()
.newDocumentBuilder()
.newDocument();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

// Disable external entity processing to prevent XXE attacks
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
factory.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");

// For enhanced security, also consider:
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setXIncludeAware(false);
factory.setExpandEntityReferences(false);

return factory.newDocumentBuilder().newDocument();
} catch (final ParserConfigurationException ex) {
throw new IllegalStateException(
"Could not instantiate DocumentBuilderFactory and build empty Document",
Expand Down
Loading