Skip to content

Commit

Permalink
Set FEATURE_SECURE_PROCESSING for DocumentBuilderFactory to remediate…
Browse files Browse the repository at this point in the history
… XXE vulnerabilities
  • Loading branch information
JAckLosingHeart committed Nov 6, 2024
1 parent ff31226 commit d657e8a
Showing 1 changed file with 3 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import java.io.FileNotFoundException;
Expand All @@ -54,6 +55,7 @@ public AtmosphereConfig parse(AtmosphereConfig config, String filename) throws F

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
return parse(config, factory.newDocumentBuilder().parse(filename));
} catch (SAXException | IOException | ParserConfigurationException e) {
logger.error(e.getMessage(), e);
Expand All @@ -66,6 +68,7 @@ public AtmosphereConfig parse(AtmosphereConfig config, InputStream stream) throw

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
return parse(config, factory.newDocumentBuilder().parse(stream));
} catch (SAXException | IOException | ParserConfigurationException e) {
logger.error(e.getMessage(), e);
Expand Down

0 comments on commit d657e8a

Please sign in to comment.