|
22 | 22 | import java.io.InputStream;
|
23 | 23 | import java.io.Reader;
|
24 | 24 |
|
| 25 | +import javax.xml.XMLConstants; |
25 | 26 | import javax.xml.parsers.DocumentBuilder;
|
26 | 27 | import javax.xml.parsers.DocumentBuilderFactory;
|
| 28 | +import javax.xml.parsers.ParserConfigurationException; |
27 | 29 |
|
28 | 30 | import org.apache.ibatis.builder.BuilderException;
|
29 | 31 | import org.apache.ibatis.io.Resources;
|
@@ -156,11 +158,29 @@ private Document getDocument(String resource) {
|
156 | 158 | try {
|
157 | 159 | InputSource inputSource = new InputSource(Resources.getResourceAsReader(resource));
|
158 | 160 | DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
| 161 | + String feature = null; |
| 162 | + try { |
| 163 | + feature = "http://xml.org/sax/features/external-parameter-entities"; |
| 164 | + factory.setFeature(feature, false); |
| 165 | + |
| 166 | + feature = "http://apache.org/xml/features/nonvalidating/load-external-dtd"; |
| 167 | + factory.setFeature(feature, false); |
| 168 | + |
| 169 | + feature = "http://xml.org/sax/features/external-general-entities"; |
| 170 | + factory.setFeature(feature, false); |
| 171 | + |
| 172 | + factory.setXIncludeAware(false); |
| 173 | + factory.setExpandEntityReferences(false); |
| 174 | + |
| 175 | + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); |
| 176 | + |
| 177 | + } catch (ParserConfigurationException e) { |
| 178 | + throw new IllegalStateException("The feature '" + feature + "' is not supported by your XML processor.", e); |
| 179 | + } |
159 | 180 | factory.setNamespaceAware(false);
|
160 | 181 | factory.setIgnoringComments(true);
|
161 | 182 | factory.setIgnoringElementContentWhitespace(false);
|
162 | 183 | factory.setCoalescing(false);
|
163 |
| - factory.setExpandEntityReferences(true); |
164 | 184 | DocumentBuilder builder = factory.newDocumentBuilder();
|
165 | 185 | return builder.parse(inputSource);// already closed resource in builder.parse method
|
166 | 186 | } catch (Exception e) {
|
|
0 commit comments