Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): added fix for xml parser #3100

Merged
merged 2 commits into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ private static List<Region> internalParse(
Document document;
try {

DocumentBuilderFactory factory =
DocumentBuilderFactory.newInstance();

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
banji180 marked this conversation as resolved.
Show resolved Hide resolved
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
factory.setXIncludeAware(false);
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
document = documentBuilder.parse(input);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,24 @@ public class XpathUtils {
/** Shared logger */
private static Log log = LogFactory.getLog(XpathUtils.class);

private static DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
private static DocumentBuilderFactory factory = getDocumentBuilderFactory();


/**
* Creates new documentbuilderfactory object
* @return DocumentBuilderFactory.
*/
private static DocumentBuilderFactory getDocumentBuilderFactory() {
try {
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
dbf.setXIncludeAware(false); // Default false for java 8. Disable XML Inclusions leading to SSRF - https://portswigger.net/web-security/xxe/lab-xinclude-attack
return dbf;
}
catch (ParserConfigurationException exception){
return null;
}
}

/**
* InputStream to Document.
Expand Down