Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b81d48b

Browse files
committed
disable XSLT extension functions by default, add more configurers
see #264
1 parent ba14909 commit b81d48b

File tree

1 file changed

+58
-2
lines changed

1 file changed

+58
-2
lines changed

xmlunit-core/src/main/java/org/xmlunit/util/TransformerFactoryConfigurer.java

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Collections;
1717
import java.util.HashMap;
1818
import java.util.Map;
19+
import javax.xml.XMLConstants;
1920
import javax.xml.transform.TransformerConfigurationException;
2021
import javax.xml.transform.TransformerFactory;
2122

@@ -88,18 +89,51 @@ public static Builder builder() {
8889
}
8990

9091
/**
91-
* The default instance which disables DTD loading but still
92+
* The default instance which disables DTD loading and extension functions but still
9293
* allows loading of external stylesheets.
9394
*/
9495
public static final TransformerFactoryConfigurer Default = builder()
9596
.withDTDLoadingDisabled()
97+
.withExtensionFunctionsDisabled()
98+
.build();
99+
100+
/**
101+
* The instance which enables secure processing thus disables all external access as well as execution of extension
102+
* functions.
103+
*
104+
* @since XMLUnit 2.10.0
105+
*/
106+
public static final TransformerFactoryConfigurer SecureProcessing = builder()
107+
.withSecureProcessingEnabled()
96108
.build();
97109

98110
/**
99111
* The instance which disables DTD loading as well as loading of
100-
* external stylesheets.
112+
* external stylesheets or extension functions.
101113
*/
102114
public static final TransformerFactoryConfigurer NoExternalAccess = builder()
115+
.withDTDLoadingDisabled()
116+
.withExternalStylesheetLoadingDisabled()
117+
.withExtensionFunctionsDisabled()
118+
.build();
119+
120+
/**
121+
* The instance which disables DTD loading but still
122+
* allows loading of external stylesheets and extension functions.
123+
*
124+
* @since XMLUnit 2.10.0
125+
*/
126+
public static final TransformerFactoryConfigurer NoDtdButExtensionFunctions = builder()
127+
.withDTDLoadingDisabled()
128+
.build();
129+
130+
/**
131+
* The instance which disables DTD loading as well as loading of
132+
* external stylesheets but allows extension functions.
133+
*
134+
* @since XMLUnit 2.10.0
135+
*/
136+
public static final TransformerFactoryConfigurer NoExternalAccessButExtensionFunctions = builder()
103137
.withDTDLoadingDisabled()
104138
.withExternalStylesheetLoadingDisabled()
105139
.build();
@@ -192,5 +226,27 @@ public Builder withExternalStylesheetLoadingDisabled() {
192226
// XMLConstants.ACCESS_EXTERNAL_STYLESHEET is not available in Java 6
193227
return withSafeAttribute("http://javax.xml.XMLConstants/property/accessExternalStylesheet", "");
194228
}
229+
230+
/**
231+
* Configures the factory to not enable extension functions.
232+
* @return this
233+
*
234+
* @since XMLUnit 2.10.0
235+
*/
236+
public Builder withExtensionFunctionsDisabled() {
237+
return withSafeAttribute("jdk.xml.enableExtensionFunctions", "false");
238+
}
239+
240+
/**
241+
* Configures the factory to enable secure processing which disables all external access as well as execution of
242+
* extension functions.
243+
* @return this
244+
*
245+
* @since XMLUnit 2.10.0
246+
*/
247+
public Builder withSecureProcessingEnabled() {
248+
return withFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
249+
}
250+
195251
}
196252
}

0 commit comments

Comments
 (0)