Skip to content

Commit

Permalink
Fix a potential XXE Vulnerability
Browse files Browse the repository at this point in the history
Without this one con possible include files from the web or the local system like //etc/passwd in an XML file and read it in e.g. an import job or in the frontend or pdf in an svg

via setting Feature Secure Processing
https://docs.oracle.com/javase/8/docs/technotes/guides/security/jaxp/jaxp.html#feature-for-secure-processing as recommended in https://cheatsheetseries.owasp.org/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.html#jaxb-unmarshaller

- fixes: SIRI-1037
  • Loading branch information
ymo-sci committed Dec 10, 2024
1 parent 06e9569 commit 0fba6c5
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import sirius.web.resources.Resource;

import javax.annotation.Nullable;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
Expand Down Expand Up @@ -104,6 +105,7 @@ protected Document parseDocument(InputSource source) {
protected Document parseDocument(InputSource source, @Nullable String expectedRootElement) {
try {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Document document = factory.newDocumentBuilder().parse(source);

if (Strings.isFilled(expectedRootElement) && !Strings.areEqual(expectedRootElement,
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/sirius/web/security/SAMLHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.xml.XMLConstants;
import javax.xml.crypto.AlgorithmMethod;
import javax.xml.crypto.KeySelector;
import javax.xml.crypto.KeySelectorException;
Expand Down Expand Up @@ -256,6 +257,7 @@ private SAMLResponse parseAssertion(Element assertion, String fingerprint) {
private Document getResponseDocument(InputStream inputStream)
throws SAXException, IOException, ParserConfigurationException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setNamespaceAware(true);
return factory.newDocumentBuilder().parse(inputStream);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import sirius.web.templates.pdf.handlers.PdfReplaceHandler;

import javax.annotation.Nonnull;
import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
Expand Down Expand Up @@ -84,6 +85,7 @@ private Optional<ReplacedElement> tryCreateReplacedSvgElement(@Nonnull Element e

try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();

Document svgDocument = documentBuilder.newDocument();
Expand Down

0 comments on commit 0fba6c5

Please sign in to comment.