@@ -138,26 +138,28 @@ public Schema getSchema(String schemaResource) {
138
138
}
139
139
140
140
private Schema loadSchema (String schemaResource ) {
141
- ClassLoader loader = GetClassLoader .fromClass ( XmlParserHelper .class );
142
-
143
- URL schemaUrl = GetResource .action ( loader , schemaResource );
144
- SchemaFactory sf = SchemaFactory .newInstance ( javax .xml .XMLConstants .W3C_XML_SCHEMA_NS_URI );
145
-
146
- try {
147
- sf .setFeature ( javax .xml .XMLConstants .FEATURE_SECURE_PROCESSING , true );
148
- }
149
- catch (SAXException e ) {
150
- LOG .unableToEnableSecureFeatureProcessingSchemaXml ( schemaResource , e .getMessage () );
151
- }
152
-
153
- Schema schema = null ;
154
- try {
155
- schema = NewSchema .action ( sf , schemaUrl );
156
- }
157
- catch (Exception e ) {
158
- LOG .unableToCreateSchema ( schemaResource , e .getMessage () );
159
- }
160
- return schema ;
141
+ ClassLoader loader = GetClassLoader .fromClass (XmlParserHelper .class );
142
+
143
+ URL schemaUrl = GetResource .action (loader , schemaResource );
144
+ SchemaFactory sf = SchemaFactory .newInstance (javax .xml .XMLConstants .W3C_XML_SCHEMA_NS_URI );
145
+
146
+ // Security improvement: Restrict access to external DTDs and schemas
147
+ try {
148
+ sf .setProperty (XMLConstants .ACCESS_EXTERNAL_DTD , "" );
149
+ sf .setProperty (XMLConstants .ACCESS_EXTERNAL_SCHEMA , "" );
150
+ } catch (SAXException e ) {
151
+ // Some older parsers might not support these properties
152
+ LOG .debug ("Unable to set external access restrictions on schema factory" , e );
153
+ }
154
+
155
+ Schema schema = null ;
156
+ try {
157
+ schema = NewSchema .action (sf , schemaUrl );
158
+ }
159
+ catch (Exception e ) {
160
+ LOG .unableToCreateSchema (schemaResource , e .getMessage ());
161
+ }
162
+ return schema ;
161
163
}
162
164
163
165
}
0 commit comments