Skip to content

Commit 63a3819

Browse files
simei2kmarko-bekhta
andcommitted
HV-2102 Disable external schema loading
Adjusted/reworked version of https://github.com/hibernate/hibernate-validator/pull/1612/files Co-authored-by: marko-bekhta <[email protected]>
1 parent 00fa6c2 commit 63a3819

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

engine/src/main/java/org/hibernate/validator/internal/util/logging/Log.java

+4
Original file line numberDiff line numberDiff line change
@@ -942,4 +942,8 @@ ConstraintDefinitionException getConstraintValidatorDefinitionConstraintMismatch
942942
@Message(id = 268, value = "The default group sequence provider %s does not implement neither `getValidationGroups(Class<?> klass, T object)` nor `getValidationGroups(T object)` methods."
943943
+ " One of them has to be implemented for the default group sequence provider to be correctly defined.")
944944
GroupDefinitionException getDefaultGroupSequenceProviderTypeDoesNotImplementAnyMethodsException(@FormatWith(ClassObjectFormatter.class) Class<?> klass);
945+
946+
@LogMessage(level = DEBUG)
947+
@Message(id = 269, value = "Unable to enable secure XML feature processing when loading %1$s: %2$s")
948+
void unableToEnableSecureFeatureProcessingSchemaXml(String fileName, String message);
945949
}

engine/src/main/java/org/hibernate/validator/internal/xml/XmlParserHelper.java

+10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import org.hibernate.validator.internal.util.logging.Log;
3030
import org.hibernate.validator.internal.util.logging.LoggerFactory;
3131

32+
import org.xml.sax.SAXException;
33+
3234
/**
3335
* Provides common functionality used within the different XML descriptor
3436
* parsers.
@@ -140,6 +142,14 @@ private Schema loadSchema(String schemaResource) {
140142

141143
URL schemaUrl = GetResource.action( loader, schemaResource );
142144
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+
143153
Schema schema = null;
144154
try {
145155
schema = NewSchema.action( sf, schemaUrl );

0 commit comments

Comments
 (0)