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

Issue #6133: Disable XML External Entity load in XmlUtil.java in tests #6577

Merged
merged 1 commit into from
Mar 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/puppycrawl/tools/checkstyle/XmlLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ public static final class LoadExternalDtdFeatureProvider {
public static final String ENABLE_EXTERNAL_DTD_LOAD = "checkstyle.enableExternalDtdLoad";

/** Feature that enables loading external DTD when loading XML files. */
private static final String LOAD_EXTERNAL_DTD =
public static final String LOAD_EXTERNAL_DTD =
"http://apache.org/xml/features/nonvalidating/load-external-dtd";
/** Feature that enables including external general entities in XML files. */
private static final String EXTERNAL_GENERAL_ENTITIES =
public static final String EXTERNAL_GENERAL_ENTITIES =
rnveach marked this conversation as resolved.
Show resolved Hide resolved
"http://xml.org/sax/features/external-general-entities";

/** Stop instances being created. **/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

import com.puppycrawl.tools.checkstyle.XmlLoader;

/**
* XmlUtil.
* @noinspection ClassOnlyUsedInOnePackage
Expand All @@ -49,6 +51,10 @@ public static Document getRawXml(String fileName, String code, String unserializ
try {
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(false);
factory.setFeature(
XmlLoader.LoadExternalDtdFeatureProvider.EXTERNAL_GENERAL_ENTITIES, false);
factory.setFeature(
XmlLoader.LoadExternalDtdFeatureProvider.LOAD_EXTERNAL_DTD, false);

final DocumentBuilder builder = factory.newDocumentBuilder();

Expand Down