fix(utils): drop dead Xerces-1/Xerces-2 feature URIs from default DocumentBuilderFactory - #205
Merged
Merged
Conversation
…umentBuilderFactory PSDocumentBuilderFactoryImpl (the project-wide default registered via PSSecureXMLUtils.setupJAXPDefaults) was setting two legacy Xerces feature URIs -- PSSecureXMLUtils.X1_GENERAL_EXTERNAL_ENTITIES_FEATURE and X2_GENERAL_EXTERNAL_ENTITIES_FEATURE -- alongside the SAX-namespace external-entity features and JAXP's FEATURE_SECURE_PROCESSING. The X1/X2 URIs are not recognized by Xerces 2.12.x. Modern Xerces consolidated the external-entity controls into the SAX-namespace features (http://xml.org/sax/features/external-general-entities and .../external-parameter-entities) and the standard JAXP FEATURE_SECURE_PROCESSING. The legacy URIs were dead code on every PSSecureXMLUtils opt-in call site too, but PSSecureXMLUtils catches the ParserConfigurationException and logs at DEBUG, so it was silent. In the default factory the catch logs at WARN, so every DocumentBuilderFactory instantiation in the project produced two WARN lines like: WARN [com.percussion.xml.PSDocumentBuilderFactoryImpl] T2.12 hardening: could not enforce X1_GENERAL_EXTERNAL_ENTITIES_FEATURE=false on DocumentBuilderFactory: Feature 'http://xerces.apache.org/xerces-j/features.html#external-general-entities' is not recognized. The startup hits PSDocumentBuilderFactoryImpl ~10 times before the webapp is fully up, so the log gets ~20 of these lines per cold start. Removing the X1/X2 setFeatureSafe calls is safe: the SAX features (SAX_GENERAL_EXTERNAL_ENTITIES_FEATURE=false, SAX_EXTERNAL_PARAMETER_ENTITIES_FEATURE=false) and FEATURE_SECURE_PROCESSING remain set in the constructor, and they are what actually disables external entity resolution on Xerces 2.12.x. disallow-doctype-decl, load-external-dtd, XIncludeAware, and expandEntityReferences are also still set. The PSSecureXMLUtils.X1/X2_GENERAL_EXTERNAL_ENTITIES_FEATURE constants remain in PSSecureXMLUtils (the opt-in path still references them with DEBUG logging) -- this change only touches the default-factory path that the T2.12 hardening PR added. The analysis doc has a post-merge revision note documenting the 3.5.x/2.12.x API surface so the URIs don't get re-added. Refs #135 > Co-Authored by Mavis Mavis-Code using MiniMax-M3 with agent mavis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Drops two dead
setFeatureSafe(...)calls inmodules/utils/.../PSDocumentBuilderFactoryImpl.javathat targeted the legacy Xerces-1 and Xerces-2 external-entity feature URIs. These URIs are not recognized by Xerces 2.12.x, so everyDocumentBuilderFactoryinstantiation in the project produced two WARN lines on the startup log. The actual security controls (SAX-namespace features +FEATURE_SECURE_PROCESSING) remain in place.Why
PSDocumentBuilderFactoryImplwas set as the project-wide defaultDocumentBuilderFactoryby the T2.12 hardening PR (#136, issue #135). Its constructor callssetFeaturefor seven features; two of them target URIs that have been dead for years:http://xerces.apache.org/xerces-j/features.html#external-general-entities(X1, Xerces 1.x)http://xerces.apache.org/xerces2-j/features.html#external-general-entities(X2, early Xerces 2.x)Modern Xerces 2.12.x consolidated those into the SAX-namespace features (
http://xml.org/sax/features/external-general-entities,.../external-parameter-entities) and JAXP'sFEATURE_SECURE_PROCESSING. The X1/X2 URIs always throwParserConfigurationExceptionon 2.12.x.The
setFeatureSafe(...)helper catches the exception and logs at WARN.PSDocumentBuilderFactoryImplis instantiated ~10 times before the webapp finishes startup, so the log gets ~20 of these lines per cold start:(The same X1/X2 URIs are also set on the opt-in
PSSecureXMLUtils.enableDBFFeaturespath, but that path catches and logs at DEBUG, so it's silent — only the new default-factory path added by PR #136 was loud.)What stays
The actual security posture is unchanged. The remaining
setFeatureSafecalls in the constructor:XMLConstants.FEATURE_SECURE_PROCESSING=true— JAXP standard secure processingDISALLOW_DOCTYPES_FEATURE=true— no<!DOCTYPE>declarationsSAX_GENERAL_EXTERNAL_ENTITIES_FEATURE=false— no external general entitiesSAX_EXTERNAL_PARAMETER_ENTITIES_FEATURE=false— no external parameter entitiesLOAD_EXTERNAL_DTD=false— no external DTDssetXIncludeAware(false)/setExpandEntityReferences(false)— no XInclude, no entity expansionThe
PSSecureXMLUtils.X1/X2_GENERAL_EXTERNAL_ENTITIES_FEATUREconstants are untouched (the opt-in path still uses them with DEBUG logging). Only the default-factory path is changed.Verification
grep -n "X1_GENERAL_EXTERNAL\|X2_GENERAL_EXTERNAL" modules/utils/src/main/java/com/percussion/xml/PSDocumentBuilderFactoryImpl.javareturns no matches.grep -n "SAX_GENERAL\|SAX_EXTERNAL" ...confirms the SAX features remain set.rxutils-8.1.8-SNAPSHOT.jar, theT2.12 hardening: could not enforce X1/X2_..._ENTITIES_FEATURElines disappear fromjetty/base/logs/server.log. The remaining T2.12 hardening messages (FEATURE_SECURE_PROCESSING, DISALLOW_DOCTYPES, SAX_GENERAL, SAX_EXTERNAL_PARAMETER, LOAD_EXTERNAL_DTD) continue to silently no-op as they did before (Xerces already has those values set, sosetFeatureis a successful no-op).Out of scope
Ignored arg <Arg name="threadpool">inupstream/etc/jetty.xml, is from the bundled Jetty 9.4.58.v20250814 distribution (modules/perc-jettyvendor) and is not introduced by the T2.12 hardening work.Refs #135