disable external entity resolution in log4j 1.x XmlConfiguration - #4198
disable external entity resolution in log4j 1.x XmlConfiguration#4198jmestwa-coder wants to merge 2 commits into
Conversation
80d7ca6 to
d5dd471
Compare
|
@jmestwa-coder Thanks for the PR! I appreciate your patience. I'll try to get it closed ASAP. |
|
@vy @ppkarwasz could one of you take a look? I did rather hand this over than guess on a security related things. |
| factory.setExpandEntityReferences(false); | ||
| setFeature(factory, "http://xml.org/sax/features/external-general-entities", false); | ||
| setFeature(factory, "http://xml.org/sax/features/external-parameter-entities", false); | ||
| setFeature(factory, "http://apache.org/xml/features/nonvalidating/load-external-dtd", false); |
There was a problem hiding this comment.
As the name suggests, this setting applies to non-validating parsers. Resolving the external subset is required in validating parsers and can not be turned off.
There was a problem hiding this comment.
right, missed that this feature only applies to non-validating parsers. dropped the feature-based approach entirely in favor of the resolver.
|
Hi @jmestwa-coder, Thank you for working on this. I do not think the proposed parser features are the right approach for Log4j 1 XML configuration files.
Log4j configuration files are considered trusted, operator-controlled sources. Completely disabling external resources therefore provides limited additional protection, while potentially breaking existing configurations. The Log4j 1 compatibility layer needs to account for more than 25 years of configuration files deployed in real applications. I therefore suggest that we:
For the validation issue, we should consider one of the following approaches:
Custom Log4j 1 appenders have worked again since |
|
I generally agree with @ppkarwasz. In my view, the primary consideration should be backward compatibility. When I use the Log4j 1 compatibility layer, it's because I need it, not because I want to. As a result, compatibility needs to be as robust and faithful as possible. Over time, both my transitive dependencies and my own applications will (or should) complete their migration to Log4j 2. Until then, compatibility takes precedence. |
|
makes sense, reworked it along those lines:
agreed the validation behavior is a separate topic, so I left the |
The Log4j 1.x
XmlConfigurationreader resolves external XML entities.Log4jEntityResolveronly handleslog4j.dtdand returnsnullotherwise, so the parser falls back to default resolution and fetches external entitieslog4j.xmlwith aSYSTEMentity can read local files or reach network URLsFix, per review:
Log4jEntityResolvernow resolves any external resource other than the bundledlog4j.dtdto an empty source and logs a status warning, so the parser never falls back to default resolution regardless of the JAXP providerTest loads a config with an external entity and asserts it is not resolved.
Checklist
2.xbranch./mvnw verifysucceedssrc/changelog/.2.x.xdirectory