Skip to content

Commit f3136a3

Browse files
committed
agent Spotbugs Fixes: XXE_DOCUMENT
Add secure processing feature to DocumentBuilder. Ignore false positives.
1 parent 349cc58 commit f3136a3

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

agent/spotbugs.exclude.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,10 @@
3232
</And>
3333
</Or>
3434
</Match>
35+
<Match>
36+
<Bug pattern="XXE_DOCUMENT" />
37+
<!-- False Positive. This feature is set in createDocumentBuidler() -->
38+
<Class name="com.microsoft.applicationinsights.agent.internal.config.builder.XmlAgentConfigurationBuilder" />
39+
<Method name="getTopTag" />
40+
</Match>
3541
</FindBugsFilter>

agent/src/main/java/com/microsoft/applicationinsights/agent/internal/config/builder/XmlAgentConfigurationBuilder.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import java.io.IOException;
2727
import java.util.HashMap;
2828
import java.util.Map;
29+
import javax.xml.XMLConstants;
2930
import javax.xml.parsers.DocumentBuilder;
3031
import javax.xml.parsers.DocumentBuilderFactory;
3132
import javax.xml.parsers.ParserConfigurationException;
@@ -238,8 +239,8 @@ private void addMethods(ClassInstrumentationData classData, Element classNode) {
238239
}
239240

240241
private Element getTopTag(File configurationFile) throws ParserConfigurationException, IOException, SAXException {
241-
DocumentBuilder builder = createDocumentBuilder();
242242
try (final FileInputStream fis = new FileInputStream(configurationFile)) {
243+
DocumentBuilder builder = createDocumentBuilder();
243244
Document doc = builder.parse(fis);
244245
doc.getDocumentElement().normalize();
245246

@@ -261,6 +262,7 @@ private DocumentBuilder createDocumentBuilder() throws ParserConfigurationExcept
261262
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
262263
// mitigates CWE-611: https://cwe.mitre.org/data/definitions/611.html
263264
dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
265+
dbFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
264266
dbFactory.setXIncludeAware(false);
265267
dbFactory.setExpandEntityReferences(false);
266268
return dbFactory.newDocumentBuilder();

0 commit comments

Comments
 (0)