Skip to content

Commit

Permalink
[secure] Make sure secure processing on document builder factory
Browse files Browse the repository at this point in the history
  • Loading branch information
hazendaz committed Sep 25, 2024
1 parent 67e21de commit f885bad
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<groupId>org.mybatis</groupId>
<artifactId>mybatis-parent</artifactId>
<version>45</version>
<relativePath/>
<relativePath />
</parent>

<groupId>org.mybatis</groupId>
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/com/ibatis/common/xml/NodeletParser.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2022 the original author or authors.
* Copyright 2004-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -20,6 +20,7 @@
import java.io.Reader;
import java.util.*;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.FactoryConfigurationError;
Expand Down Expand Up @@ -195,6 +196,7 @@ private void processNodelet(Node node, String pathString) {
private Document createDocument(Reader reader)
throws ParserConfigurationException, FactoryConfigurationError, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setValidating(validation);

factory.setNamespaceAware(false);
Expand Down Expand Up @@ -241,6 +243,7 @@ public void warning(SAXParseException exception) throws SAXException {
private Document createDocument(InputStream inputStream)
throws ParserConfigurationException, FactoryConfigurationError, SAXException, IOException {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
factory.setValidating(validation);

factory.setNamespaceAware(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2004-2023 the original author or authors.
* Copyright 2004-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,6 +39,7 @@
import java.util.Arrays;
import java.util.List;

import javax.xml.XMLConstants;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

Expand Down Expand Up @@ -452,6 +453,7 @@ protected Object validateParameter(Object param) throws SQLException {
private Document stringToDocument(String s) {
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
return documentBuilder.parse(new ReaderInputStream(new StringReader(s)));
} catch (Exception e) {
Expand Down

0 comments on commit f885bad

Please sign in to comment.