Skip to content

Instantly share code, notes, and snippets.

@ties
Created May 4, 2020 12:19
Show Gist options
  • Save ties/e2e29fa0834cd0354c6aec4acaba9376 to your computer and use it in GitHub Desktop.
Save ties/e2e29fa0834cd0354c6aec4acaba9376 to your computer and use it in GitHub Desktop.
// ...
/**
* Get an DocumentBuilder that is protected from entity injection.
* @return new DocumenBuilder
* @throws ParserConfigurationException when it feels like being peak java
*/
public DocumentBuilder newDocumentBuilder() throws ParserConfigurationException {
final var df = DocumentBuilderFactory.newInstance();
df.setAttribute(XMLConstants.ACCESS_EXTERNAL_DTD, "");
df.setAttribute(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "");
return df.newDocumentBuilder();
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment