This is an automated email from the ASF dual-hosted git repository. garydgregory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/commons-xml.git
commit 28fbed4323226ce4cca1de37702c5857268975fb Author: Gary Gregory <[email protected]> AuthorDate: Fri Aug 28 13:23:12 2026 -0400 Rename HardeningXMLInputFactory to SecureXMLInputFactory. Local build OK. --- ...nputFactory.java => SecureXMLInputFactory.java} | 6 +++--- src/site/markdown/index.md | 2 +- .../org/apache/commons/xml/AttackTestSupport.java | 22 +++++++++++----------- .../commons/xml/EntityResolverFloorTest.java | 4 ++-- .../commons/xml/HardeningFactoriesSmokeTest.java | 14 +++++++------- .../apache/commons/xml/ShadingFootprintTest.java | 10 +++++----- 6 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/main/java/org/apache/commons/xml/HardeningXMLInputFactory.java b/src/main/java/org/apache/commons/xml/SecureXMLInputFactory.java similarity index 98% rename from src/main/java/org/apache/commons/xml/HardeningXMLInputFactory.java rename to src/main/java/org/apache/commons/xml/SecureXMLInputFactory.java index c438154..ba1bea3 100644 --- a/src/main/java/org/apache/commons/xml/HardeningXMLInputFactory.java +++ b/src/main/java/org/apache/commons/xml/SecureXMLInputFactory.java @@ -47,7 +47,7 @@ * * @see org.apache.commons.xml */ -public final class HardeningXMLInputFactory { +public final class SecureXMLInputFactory { /** Woodstox property: resolver consulted for the external DTD subset. */ static final String WSTX_DTD_RESOLVER = "com.ctc.wstx.dtdResolver"; @@ -147,7 +147,7 @@ public static XMLInputFactory newInstance() { return harden(XMLInputFactory.newInstance()); } - private HardeningXMLInputFactory() { + private SecureXMLInputFactory() { // static only } @@ -156,7 +156,7 @@ private HardeningXMLInputFactory() { * non-removable by the caller. * * <p>The constructor installs the floor through {@code setXMLResolver}, which every implementation routes external resolution through (Woodstox fans it out to - * both its DTD-subset and entity resolvers). Woodstox keeps one hook outside that fan-out, {@value HardeningXMLInputFactory#WSTX_UNDECLARED_ENTITY_RESOLVER}, which is + * both its DTD-subset and entity resolvers). Woodstox keeps one hook outside that fan-out, {@value SecureXMLInputFactory#WSTX_UNDECLARED_ENTITY_RESOLVER}, which is * deliberately left empty: emptying the external subset leaves any entity it declared undeclared, and Woodstox then rejects the reference. The rejection is * implementation-prescribed and keeps the resource just as unfetched as the empty resolution the other implementations produce; a caller who wants those * references resolved can still set the property, and their resolver lands behind a floor like on every other resolver hook.</p> diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index 630ea36..594b149 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -104,7 +104,7 @@ HardeningSAXParserFactory.newInstance().newSAXParser().parse(inputStream, myDefa ```java import javax.xml.stream.XMLStreamReader; -import org.apache.commons.xml.HardeningXMLInputFactory; +import org.apache.commons.xml.SecureXMLInputFactory; XMLStreamReader reader = HardeningXMLInputFactory.newInstance().createXMLStreamReader(inputStream); ``` diff --git a/src/test/java/org/apache/commons/xml/AttackTestSupport.java b/src/test/java/org/apache/commons/xml/AttackTestSupport.java index 8ed003a..3547f7a 100644 --- a/src/test/java/org/apache/commons/xml/AttackTestSupport.java +++ b/src/test/java/org/apache/commons/xml/AttackTestSupport.java @@ -519,42 +519,42 @@ static void assertSchemaDoesNotLeak(final Source xsd) { /** * Asserts a hardened StAX parse of the payload throws. * - * <p>{@link XMLStreamReader} and {@link XMLEventReader} from {@link HardeningXMLInputFactory#newInstance()}; both flavors are exercised and either must + * <p>{@link XMLStreamReader} and {@link XMLEventReader} from {@link SecureXMLInputFactory#newInstance()}; both flavors are exercised and either must * throw.</p> */ static void assertStaxBlocks(final String payload) { - assertParseFails(() -> consumeStreamReader(HardeningXMLInputFactory.newInstance(), payload), "StAX stream", XMLStreamException.class); - assertParseFails(() -> consumeEventReader(HardeningXMLInputFactory.newInstance(), payload), "StAX event", XMLStreamException.class); + assertParseFails(() -> consumeStreamReader(SecureXMLInputFactory.newInstance(), payload), "StAX stream", XMLStreamException.class); + assertParseFails(() -> consumeEventReader(SecureXMLInputFactory.newInstance(), payload), "StAX event", XMLStreamException.class); } /** * Asserts a hardened StAX parse (stream and event) either blocks at parse or completes without leaked content. See {@link #assertDomBlocksOrDoesNotLeak(String)}. */ static void assertStaxBlocksOrDoesNotLeak(final String payload) { - assertNoLeakOrThrows(() -> captureStaxStreamText(HardeningXMLInputFactory.newInstance(), payload), "StAX stream", XMLStreamException.class); - assertNoLeakOrThrows(() -> captureStaxEventText(HardeningXMLInputFactory.newInstance(), payload), "StAX event", XMLStreamException.class); + assertNoLeakOrThrows(() -> captureStaxStreamText(SecureXMLInputFactory.newInstance(), payload), "StAX stream", XMLStreamException.class); + assertNoLeakOrThrows(() -> captureStaxEventText(SecureXMLInputFactory.newInstance(), payload), "StAX event", XMLStreamException.class); } /** * Asserts a hardened StAX parse completes without throwing and without leaked content. * - * <p>{@link XMLStreamReader} and {@link XMLEventReader} from {@link HardeningXMLInputFactory#newInstance()}; both flavors are exercised. Use this when the + * <p>{@link XMLStreamReader} and {@link XMLEventReader} from {@link SecureXMLInputFactory#newInstance()}; both flavors are exercised. Use this when the * hardening guarantee is "the parse succeeds but never resolves the external resource", for example, when the JDK's {@code ignore-external-dtd} property silently * skips the external subset.</p> */ static void assertStaxDoesNotLeak(final String payload) { - assertNoLeakStrict(() -> captureStaxStreamText(HardeningXMLInputFactory.newInstance(), payload), "StAX stream"); - assertNoLeakStrict(() -> captureStaxEventText(HardeningXMLInputFactory.newInstance(), payload), "StAX event"); + assertNoLeakStrict(() -> captureStaxStreamText(SecureXMLInputFactory.newInstance(), payload), "StAX stream"); + assertNoLeakStrict(() -> captureStaxEventText(SecureXMLInputFactory.newInstance(), payload), "StAX event"); } /** * Asserts a hardened StAX parse succeeds. * - * <p>{@link XMLStreamReader} and {@link XMLEventReader} from {@link HardeningXMLInputFactory#newInstance()}; positive control for DOCTYPE-only payloads.</p> + * <p>{@link XMLStreamReader} and {@link XMLEventReader} from {@link SecureXMLInputFactory#newInstance()}; positive control for DOCTYPE-only payloads.</p> */ static void assertStaxParses(final String payload) { - assertParseSucceeds(() -> consumeStreamReader(HardeningXMLInputFactory.newInstance(), payload), "StAX stream"); - assertParseSucceeds(() -> consumeEventReader(HardeningXMLInputFactory.newInstance(), payload), "StAX event"); + assertParseSucceeds(() -> consumeStreamReader(SecureXMLInputFactory.newInstance(), payload), "StAX stream"); + assertParseSucceeds(() -> consumeEventReader(SecureXMLInputFactory.newInstance(), payload), "StAX event"); } /** diff --git a/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java b/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java index 9ad9eb2..3452bcd 100644 --- a/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java +++ b/src/test/java/org/apache/commons/xml/EntityResolverFloorTest.java @@ -119,7 +119,7 @@ private static String entityPayload(final String entitySystemId) { } private static XMLInputFactory externalEntityStaxFactory() { - final XMLInputFactory factory = HardeningXMLInputFactory.newInstance(); + final XMLInputFactory factory = SecureXMLInputFactory.newInstance(); factory.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, true); factory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true); return factory; @@ -336,7 +336,7 @@ void staxDoesNotLeakUnlisted() throws Exception { @Test @Tag("stax") void staxGetXMLResolverReportsCallerUnwrapped() { - final XMLInputFactory factory = HardeningXMLInputFactory.newInstance(); + final XMLInputFactory factory = SecureXMLInputFactory.newInstance(); final XMLResolver caller = (publicID, systemID, baseURI, namespace) -> null; factory.setXMLResolver(caller); assertSame(caller, factory.getXMLResolver(), "getXMLResolver should report the caller's resolver, not the floor wrapper"); diff --git a/src/test/java/org/apache/commons/xml/HardeningFactoriesSmokeTest.java b/src/test/java/org/apache/commons/xml/HardeningFactoriesSmokeTest.java index 5ee7a26..0b75b59 100644 --- a/src/test/java/org/apache/commons/xml/HardeningFactoriesSmokeTest.java +++ b/src/test/java/org/apache/commons/xml/HardeningFactoriesSmokeTest.java @@ -62,7 +62,7 @@ void publicClassesDoNotExtendTheirJaxpFactoryType() { assertFalse(SAXParserFactory.class.isAssignableFrom(SecureSAXParserFactory.class)); assertFalse(SchemaFactory.class.isAssignableFrom(SecureSchemaFactory.class)); assertFalse(TransformerFactory.class.isAssignableFrom(SecureTransformerFactory.class)); - assertFalse(XMLInputFactory.class.isAssignableFrom(HardeningXMLInputFactory.class)); + assertFalse(XMLInputFactory.class.isAssignableFrom(SecureXMLInputFactory.class)); assertFalse(XPathFactory.class.isAssignableFrom(HardeningXPathFactory.class)); } @@ -121,8 +121,8 @@ void newTransformerFactoryReturnsFreshInstance() { @Test void newXMLInputFactoryReturnsFreshInstance() { - final XMLInputFactory a = HardeningXMLInputFactory.newInstance(); - final XMLInputFactory b = HardeningXMLInputFactory.newInstance(); + final XMLInputFactory a = SecureXMLInputFactory.newInstance(); + final XMLInputFactory b = SecureXMLInputFactory.newInstance(); assertNotSame(a, b); assertEquals(Boolean.TRUE, a.getProperty(XMLInputFactory.SUPPORT_DTD)); assertEquals(Boolean.FALSE, a.getProperty(XMLInputFactory.IS_VALIDATING)); @@ -175,8 +175,8 @@ void explicitClassNameXPathFactoryIsHardened() throws Exception { @Test void newFactoryReturnsFreshInstance() { - final XMLInputFactory a = HardeningXMLInputFactory.newFactory(); - final XMLInputFactory b = HardeningXMLInputFactory.newFactory(); + final XMLInputFactory a = SecureXMLInputFactory.newFactory(); + final XMLInputFactory b = SecureXMLInputFactory.newFactory(); assertNotSame(a, b); assertEquals(Boolean.TRUE, a.getProperty(XMLInputFactory.SUPPORT_DTD)); } @@ -187,7 +187,7 @@ void factoryIdXMLInputFactoryIsHardened() { // XMLInputFactory.newInstance, not newFactory: Android's StAX API predates newFactory, and this file also compiles against android.jar. System.setProperty(factoryId, XMLInputFactory.newInstance().getClass().getName()); try { - final XMLInputFactory factory = HardeningXMLInputFactory.newFactory(factoryId, getClass().getClassLoader()); + final XMLInputFactory factory = SecureXMLInputFactory.newFactory(factoryId, getClass().getClassLoader()); assertEquals(Boolean.TRUE, factory.getProperty(XMLInputFactory.SUPPORT_DTD)); } finally { System.clearProperty(factoryId); @@ -304,7 +304,7 @@ void newDefaultInstanceTransformerFactoryIsHardened() { @Test void newDefaultFactoryXMLInputFactoryIsHardened() { - final XMLInputFactory factory = HardeningXMLInputFactory.newDefaultFactory(); + final XMLInputFactory factory = SecureXMLInputFactory.newDefaultFactory(); assertEquals(Boolean.TRUE, factory.getProperty(XMLInputFactory.SUPPORT_DTD)); } diff --git a/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java b/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java index 3a18143..3c5b69a 100644 --- a/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java +++ b/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java @@ -83,9 +83,9 @@ class ShadingFootprintTest { private static final Set<String> XML_INPUT_FACTORY = set( "FallbackIgnoreXMLResolver", "SecureException", - "HardeningXMLInputFactory", - "HardeningXMLInputFactory$1", - "HardeningXMLInputFactory$Wrapper", + "SecureXMLInputFactory", + "SecureXMLInputFactory$1", + "SecureXMLInputFactory$Wrapper", "MethodHandleFactory"); // @formatter:on @@ -177,7 +177,7 @@ class ShadingFootprintTest { /** * Entry points reported by the {@link #reportFootprint()} diagnostic, most-focused first, ending with the whole library. */ - private static final String[] REPORTED = {"SecureDocumentBuilderFactory", "SecureSAXParserFactory", "HardeningXMLInputFactory", + private static final String[] REPORTED = {"SecureDocumentBuilderFactory", "SecureSAXParserFactory", "SecureXMLInputFactory", "SecureTransformerFactory", "HardeningXPathFactory", "SecureSchemaFactory"}; private static Clazzpath clazzpath; @@ -284,7 +284,7 @@ void schemaFactoryFootprint() { @Test void xmlInputFactoryFootprint() { - assertEquals(XML_INPUT_FACTORY, closureOf("HardeningXMLInputFactory")); + assertEquals(XML_INPUT_FACTORY, closureOf("SecureXMLInputFactory")); } @Test
