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 12418a987d02a89c9f8541ab7e6b26179f892227 Author: Gary Gregory <[email protected]> AuthorDate: Fri Aug 28 13:14:11 2026 -0400 Rename HardeningException to SecureException --- .../commons/xml/FallbackIgnoreEntityResolver2.java | 6 +++--- .../commons/xml/FallbackIgnoreLSResourceResolver.java | 4 ++-- .../apache/commons/xml/FallbackIgnoreURIResolver.java | 6 +++--- .../apache/commons/xml/FallbackIgnoreXMLResolver.java | 4 ++-- .../apache/commons/xml/HardeningSAXParserFactory.java | 4 ++-- .../apache/commons/xml/HardeningTransformerFactory.java | 4 ++-- src/main/java/org/apache/commons/xml/HardeningXPath.java | 2 +- .../org/apache/commons/xml/HardeningXPathFactory.java | 8 ++++---- src/main/java/org/apache/commons/xml/SaxonProvider.java | 10 +++++----- .../apache/commons/xml/SecureDocumentBuilderFactory.java | 8 ++++---- .../{HardeningException.java => SecureException.java} | 16 ++++++++-------- .../java/org/apache/commons/xml/AttackTestSupport.java | 2 +- .../java/org/apache/commons/xml/DenyUnresolvedTest.java | 6 +++--- .../org/apache/commons/xml/ShadingFootprintTest.java | 14 +++++++------- 14 files changed, 47 insertions(+), 47 deletions(-) diff --git a/src/main/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2.java b/src/main/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2.java index bda79e2..a7c3380 100644 --- a/src/main/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2.java +++ b/src/main/java/org/apache/commons/xml/FallbackIgnoreEntityResolver2.java @@ -109,12 +109,12 @@ final EntityResolver getDelegate() { * @param baseURI The base URI for relative resolution, or {@code null}. * @param systemId The system identifier of the unresolved entity. * @return An empty {@link InputSource} carrying the requested identifiers. - * @throws SAXException when {@value HardeningException#THROW_ON_UNRESOLVED} is set: unresolved references are rejected instead of resolved to empty. + * @throws SAXException when {@value SecureException#THROW_ON_UNRESOLVED} is set: unresolved references are rejected instead of resolved to empty. * @throws IOException never by the default implementation. */ protected InputSource onUnresolved(final String name, final String publicId, final String baseURI, final String systemId) throws SAXException, IOException { - if (HardeningException.throwOnUnresolved()) { - throw new SAXException(HardeningException.forbidden(name, null, publicId, systemId, baseURI)); + if (SecureException.throwOnUnresolved()) { + throw new SAXException(SecureException.forbidden(name, null, publicId, systemId, baseURI)); } final InputSource empty = new InputSource(new ByteArrayInputStream(EMPTY)); empty.setPublicId(publicId); diff --git a/src/main/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolver.java b/src/main/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolver.java index d225b07..8698e9f 100644 --- a/src/main/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolver.java +++ b/src/main/java/org/apache/commons/xml/FallbackIgnoreLSResourceResolver.java @@ -73,9 +73,9 @@ public LSInput resolveResource(final String type, final String namespaceURI, fin if (resolved != null) { return resolved; } - if (HardeningException.throwOnUnresolved()) { + if (SecureException.throwOnUnresolved()) { // The interface declares no checked exception; LSException is the DOM Load/Save runtime failure type. - throw new LSException(LSException.PARSE_ERR, HardeningException.forbidden(type, namespaceURI, publicId, systemId, baseURI)); + throw new LSException(LSException.PARSE_ERR, SecureException.forbidden(type, namespaceURI, publicId, systemId, baseURI)); } // A character stream, not setStringData(""): the JDK's DOMEntityResolverWrapper discards empty string data, leaving a source with no content and a // null system id that Xerces then fails to absolutize. The echoed identifiers give Xerces a valid base URI; the content still comes from this diff --git a/src/main/java/org/apache/commons/xml/FallbackIgnoreURIResolver.java b/src/main/java/org/apache/commons/xml/FallbackIgnoreURIResolver.java index 0b6c781..1c5a3b5 100644 --- a/src/main/java/org/apache/commons/xml/FallbackIgnoreURIResolver.java +++ b/src/main/java/org/apache/commons/xml/FallbackIgnoreURIResolver.java @@ -67,7 +67,7 @@ final class FallbackIgnoreURIResolver implements URIResolver { * Creates a new empty document. * * @return a new empty document. - * @throws HardeningException Thrown if a {@link DocumentBuilder} cannot be created which satisfies the configuration requested. + * @throws SecureException Thrown if a {@link DocumentBuilder} cannot be created which satisfies the configuration requested. * @throws ExceptionInInitializerError Thrown from a factory in case of a {@link java.util.ServiceConfigurationError service * configuration error} or if the implementation is not available or cannot be instantiated. */ @@ -127,8 +127,8 @@ public Source resolve(final String href, final String base) throws TransformerEx // The implementation parses the opted-in handle with an internal reader at its own defaults; the rewrite hands it a hardened reader instead. return HardeningSAXParserFactory.harden(resolved, overrideDefaultParser.getAsBoolean()); } - if (HardeningException.throwOnUnresolved()) { - throw new TransformerException(HardeningException.forbidden("uri", null, null, href, base)); + if (SecureException.throwOnUnresolved()) { + throw new TransformerException(SecureException.forbidden("uri", null, null, href, base)); } return emptySource.get(); } diff --git a/src/main/java/org/apache/commons/xml/FallbackIgnoreXMLResolver.java b/src/main/java/org/apache/commons/xml/FallbackIgnoreXMLResolver.java index 12dd350..42429fc 100644 --- a/src/main/java/org/apache/commons/xml/FallbackIgnoreXMLResolver.java +++ b/src/main/java/org/apache/commons/xml/FallbackIgnoreXMLResolver.java @@ -66,8 +66,8 @@ public Object resolveEntity(final String publicID, final String systemID, final if (resolved != null) { return resolved; } - if (HardeningException.throwOnUnresolved()) { - throw new XMLStreamException(HardeningException.forbidden(null, namespace, publicID, systemID, baseURI)); + if (SecureException.throwOnUnresolved()) { + throw new XMLStreamException(SecureException.forbidden(null, namespace, publicID, systemID, baseURI)); } return EMPTY; } diff --git a/src/main/java/org/apache/commons/xml/HardeningSAXParserFactory.java b/src/main/java/org/apache/commons/xml/HardeningSAXParserFactory.java index 11a8034..d3c585c 100644 --- a/src/main/java/org/apache/commons/xml/HardeningSAXParserFactory.java +++ b/src/main/java/org/apache/commons/xml/HardeningSAXParserFactory.java @@ -301,7 +301,7 @@ private static void setFeature(final SAXParserFactory factory, final String feat try { factory.setFeature(feature, value); } catch (final Exception e) { - throw HardeningException.settingFailed("feature", feature, factory, e); + throw SecureException.settingFailed("feature", feature, factory, e); } } @@ -309,7 +309,7 @@ private static void setFeature(final XMLReader reader, final String feature, fin try { reader.setFeature(feature, value); } catch (final Exception e) { - throw HardeningException.settingFailed("feature", feature, reader, e); + throw SecureException.settingFailed("feature", feature, reader, e); } } diff --git a/src/main/java/org/apache/commons/xml/HardeningTransformerFactory.java b/src/main/java/org/apache/commons/xml/HardeningTransformerFactory.java index 242c5ec..c54a0d3 100644 --- a/src/main/java/org/apache/commons/xml/HardeningTransformerFactory.java +++ b/src/main/java/org/apache/commons/xml/HardeningTransformerFactory.java @@ -176,7 +176,7 @@ private static void setFeature(final TransformerFactory factory, final String fe try { factory.setFeature(feature, value); } catch (final Exception e) { - throw HardeningException.settingFailed("feature", feature, factory, e); + throw SecureException.settingFailed("feature", feature, factory, e); } } @@ -227,7 +227,7 @@ private static final class Wrapper extends SAXTransformerFactory { * @throws TransformerConfigurationException if the source cannot be parsed. * @throws FactoryConfigurationError Thrown from a factory in case of a {@link java.util.ServiceConfigurationError service * configuration error} or if the implementation is not available or cannot be instantiated. - * @throws HardeningException Thrown if a (non-Andoid) factory cannot support the secure processing feature {@link XMLConstants#FEATURE_SECURE_PROCESSING}. + * @throws SecureException Thrown if a (non-Andoid) factory cannot support the secure processing feature {@link XMLConstants#FEATURE_SECURE_PROCESSING}. */ private Source hardenSourceToDom(final Source source) throws TransformerConfigurationException { if (source instanceof StreamSource || source instanceof SAXSource && ((SAXSource) source).getXMLReader() == null) { diff --git a/src/main/java/org/apache/commons/xml/HardeningXPath.java b/src/main/java/org/apache/commons/xml/HardeningXPath.java index 724aaa3..dae10ce 100644 --- a/src/main/java/org/apache/commons/xml/HardeningXPath.java +++ b/src/main/java/org/apache/commons/xml/HardeningXPath.java @@ -62,7 +62,7 @@ final class HardeningXPath implements XPath { * @throws XPathExpressionException if the source cannot be parsed. * @throws FactoryConfigurationError Thrown from a factory in case of a {@link java.util.ServiceConfigurationError service * configuration error} or if the implementation is not available or cannot be instantiated. - * @throws HardeningException Thrown if a (non-Andoid) factory cannot support the secure processing feature {@link XMLConstants#FEATURE_SECURE_PROCESSING}. + * @throws SecureException Thrown if a (non-Andoid) factory cannot support the secure processing feature {@link XMLConstants#FEATURE_SECURE_PROCESSING}. */ static Document parse(final InputSource source, final boolean overrideDefaultParser) throws XPathExpressionException { Objects.requireNonNull(source, "source"); diff --git a/src/main/java/org/apache/commons/xml/HardeningXPathFactory.java b/src/main/java/org/apache/commons/xml/HardeningXPathFactory.java index 0bf18ce..2d41f28 100644 --- a/src/main/java/org/apache/commons/xml/HardeningXPathFactory.java +++ b/src/main/java/org/apache/commons/xml/HardeningXPathFactory.java @@ -74,7 +74,7 @@ public final class HardeningXPathFactory { * * @param factory The factory to harden. * @return A new hardened factory or the original factory, hardened, if it is a known Saxon factory. - * @throws HardeningException Thrown if this {@link XPathFactory} or the {@code XPath}s it creates cannot support this feature. + * @throws SecureException Thrown if this {@link XPathFactory} or the {@code XPath}s it creates cannot support this feature. */ static XPathFactory harden(final XPathFactory factory) { if (SaxonProvider.isSaxon(factory.getClass())) { @@ -166,19 +166,19 @@ public static XPathFactory newInstance(final String uri, final String factoryCla } /** - * Sets a feature on the given factory, throwing a {@link HardeningException} if the implementation does not recognize it. + * Sets a feature on the given factory, throwing a {@link SecureException} if the implementation does not recognize it. * * @param factory The factory to harden. * @param feature The feature to set. * @param value The value to set. - * @throws HardeningException Thrown if this {@link XPathFactory} or the {@code XPath}s it creates cannot support this feature or if {@code feature} is + * @throws SecureException Thrown if this {@link XPathFactory} or the {@code XPath}s it creates cannot support this feature or if {@code feature} is * {@code null}. */ private static void setFeature(final XPathFactory factory, final String feature, final boolean value) { try { factory.setFeature(feature, value); } catch (final XPathFactoryConfigurationException e) { - throw HardeningException.settingFailed("feature", feature, factory, e); + throw SecureException.settingFailed("feature", feature, factory, e); } } diff --git a/src/main/java/org/apache/commons/xml/SaxonProvider.java b/src/main/java/org/apache/commons/xml/SaxonProvider.java index 13a2c22..edd9b59 100644 --- a/src/main/java/org/apache/commons/xml/SaxonProvider.java +++ b/src/main/java/org/apache/commons/xml/SaxonProvider.java @@ -64,8 +64,8 @@ private static final class HardenedConfiguration extends Configuration { /** Collection-level ignore: {@code fn:collection()} and {@code fn:uri-collection()} resolve to an empty collection instead of fetching. */ private static final CollectionFinder EMPTY_COLLECTION_FINDER = (context, collectionURI) -> { - if (HardeningException.throwOnUnresolved()) { - throw new XPathException(HardeningException.forbidden("collection", null, null, collectionURI, null)); + if (SecureException.throwOnUnresolved()) { + throw new XPathException(SecureException.forbidden("collection", null, null, collectionURI, null)); } return CollectionFn.EMPTY_COLLECTION; }; @@ -88,7 +88,7 @@ private HardenedConfiguration() { public XMLReader makeParser(final String className) throws TransformerFactoryConfigurationError { try { return HardeningSAXParserFactory.harden(super.makeParser(className)); - } catch (final HardeningException e) { + } catch (final SecureException e) { throw new TransformerFactoryConfigurationError(e); } } @@ -126,7 +126,7 @@ static TransformerFactory configure(final TransformerFactory factory) { return SaxonProviderConfigurer.configure(factory); } catch (final ClassCastException e) { // A Saxon-package factory the configurer cannot lock down; refuse it rather than returning it unhardened. - throw new HardeningException("Unsupported Saxon TransformerFactory " + factory.getClass().getName(), e); + throw new SecureException("Unsupported Saxon TransformerFactory " + factory.getClass().getName(), e); } } @@ -135,7 +135,7 @@ static XPathFactory configure(final XPathFactory factory) { return SaxonProviderConfigurer.configure(factory); } catch (final ClassCastException e) { // A Saxon-package factory the configurer cannot lock down; refuse it rather than returning it unhardened. - throw new HardeningException("Unsupported Saxon XPathFactory " + factory.getClass().getName(), e); + throw new SecureException("Unsupported Saxon XPathFactory " + factory.getClass().getName(), e); } } diff --git a/src/main/java/org/apache/commons/xml/SecureDocumentBuilderFactory.java b/src/main/java/org/apache/commons/xml/SecureDocumentBuilderFactory.java index fa8a1ef..d4942ed 100644 --- a/src/main/java/org/apache/commons/xml/SecureDocumentBuilderFactory.java +++ b/src/main/java/org/apache/commons/xml/SecureDocumentBuilderFactory.java @@ -75,7 +75,7 @@ public final class SecureDocumentBuilderFactory { * * @param factory The factory to harden. * @return A new hardened factory or the original factory, as-is, if it is a known Android factory. - * @throws HardeningException Thrown if a (non-Andoid) factory cannot support the secure processing feature {@link XMLConstants#FEATURE_SECURE_PROCESSING}. + * @throws SecureException Thrown if a (non-Andoid) factory cannot support the secure processing feature {@link XMLConstants#FEATURE_SECURE_PROCESSING}. */ static DocumentBuilderFactory harden(final DocumentBuilderFactory factory) { // Android exposes no FSP, ACCESS_EXTERNAL_* or attribute API, and KXmlParser drops user-defined entities; nothing to apply. @@ -220,19 +220,19 @@ public static DocumentBuilderFactory newNSInstance(final String factoryClassName } /** - * Sets a feature on the given factory, throwing a {@link HardeningException} if the implementation does not recognize it. + * Sets a feature on the given factory, throwing a {@link SecureException} if the implementation does not recognize it. * * @param factory The factory to harden. * @param feature The feature to set. * @param value The value to set. - * @throws HardeningException Thrown if this factory or the {@code XPath}s it creates cannot support this feature. + * @throws SecureException Thrown if this factory or the {@code XPath}s it creates cannot support this feature. * @throws NullPointerException Thrown if the {@code feature} parameter is null. */ private static void setFeature(final DocumentBuilderFactory factory, final String feature, final boolean value) { try { factory.setFeature(feature, value); } catch (final ParserConfigurationException e) { - throw HardeningException.settingFailed("feature", feature, factory, e); + throw SecureException.settingFailed("feature", feature, factory, e); } } diff --git a/src/main/java/org/apache/commons/xml/HardeningException.java b/src/main/java/org/apache/commons/xml/SecureException.java similarity index 81% rename from src/main/java/org/apache/commons/xml/HardeningException.java rename to src/main/java/org/apache/commons/xml/SecureException.java index 163ead0..bcfd9dd 100644 --- a/src/main/java/org/apache/commons/xml/HardeningException.java +++ b/src/main/java/org/apache/commons/xml/SecureException.java @@ -31,7 +31,7 @@ * * <p>Package-private by design: callers should catch {@link IllegalStateException}, which this extends.</p> */ -final class HardeningException extends IllegalStateException { +final class SecureException extends IllegalStateException { private static final long serialVersionUID = 1L; @@ -47,7 +47,7 @@ final class HardeningException extends IllegalStateException { */ static String forbidden(final String type, final String namespace, final String publicId, final String systemId, final String baseURI) { return String.format("External resource fetch forbidden by %s: type=%s, namespace=%s, publicId=%s, systemId=%s, baseURI=%s", - HardeningException.THROW_ON_UNRESOLVED, type, namespace, publicId, systemId, baseURI); + SecureException.THROW_ON_UNRESOLVED, type, namespace, publicId, systemId, baseURI); } /** @@ -59,19 +59,19 @@ static String forbidden(final String type, final String namespace, final String * @param cause the original checked or unchecked exception from the JAXP implementation. * @return the exception to throw. */ - static HardeningException settingFailed(final String kind, final String name, final Object target, final Throwable cause) { - return new HardeningException("Failed to set " + kind + " '" + name + "' on " + target.getClass().getName(), cause); + static SecureException settingFailed(final String kind, final String name, final Object target, final Throwable cause) { + return new SecureException("Failed to set " + kind + " '" + name + "' on " + target.getClass().getName(), cause); } /** * Whether unresolved external references must be rejected instead of resolved to empty content. * - * <p>Read per resolution, so the {@value HardeningException#THROW_ON_UNRESOLVED} system property also toggles factories that already exist.</p> + * <p>Read per resolution, so the {@value SecureException#THROW_ON_UNRESOLVED} system property also toggles factories that already exist.</p> * - * @return {@code true} when the {@value HardeningException#THROW_ON_UNRESOLVED} system property is set. + * @return {@code true} when the {@value SecureException#THROW_ON_UNRESOLVED} system property is set. */ static boolean throwOnUnresolved() { - return Boolean.getBoolean(HardeningException.THROW_ON_UNRESOLVED); + return Boolean.getBoolean(SecureException.THROW_ON_UNRESOLVED); } /** @@ -83,7 +83,7 @@ static boolean throwOnUnresolved() { */ static final String THROW_ON_UNRESOLVED = "org.apache.commons.xml.throwOnUnresolved"; - HardeningException(final String message, final Throwable cause) { + SecureException(final String message, final Throwable cause) { super(message, cause); } } diff --git a/src/test/java/org/apache/commons/xml/AttackTestSupport.java b/src/test/java/org/apache/commons/xml/AttackTestSupport.java index b0b95b4..dbeb17d 100644 --- a/src/test/java/org/apache/commons/xml/AttackTestSupport.java +++ b/src/test/java/org/apache/commons/xml/AttackTestSupport.java @@ -246,7 +246,7 @@ static void assertDomParses(final String payload) { * Skeleton for every {@code assert*BlocksOrDoesNotLeak} helper. * * <p>Treats a thrown exception of one of the {@code expected} types as "hardening blocked at parse" (acceptable); otherwise asserts the captured output - * omits {@link #LEAKED_MARKER}. A throw whose type does not match {@code expected} fails the test, so unrelated failures (for example, a {@link HardeningException} + * omits {@link #LEAKED_MARKER}. A throw whose type does not match {@code expected} fails the test, so unrelated failures (for example, a {@link SecureException} * because no recipe matched the JAXP implementation) cannot be silently accepted as a clean block.</p> * * @param action The parse to execute, returning the captured output text checked for {@link #LEAKED_MARKER}. diff --git a/src/test/java/org/apache/commons/xml/DenyUnresolvedTest.java b/src/test/java/org/apache/commons/xml/DenyUnresolvedTest.java index 62bee1d..aaed8b9 100644 --- a/src/test/java/org/apache/commons/xml/DenyUnresolvedTest.java +++ b/src/test/java/org/apache/commons/xml/DenyUnresolvedTest.java @@ -29,7 +29,7 @@ import org.xml.sax.SAXException; /** - * Checks that the resolver floors reject unresolved references when the {@value HardeningException#THROW_ON_UNRESOLVED} system property is set. + * Checks that the resolver floors reject unresolved references when the {@value SecureException#THROW_ON_UNRESOLVED} system property is set. * * <p>The floors are exercised directly: with the property set and no caller delegate, each must throw its hook's exception instead of resolving to empty * content. The property is read at resolution time, so setting it around a single test cannot leak into the rest of the suite.</p> @@ -40,12 +40,12 @@ class DenyUnresolvedTest { @AfterEach void clearThrowOnUnresolved() { - System.clearProperty(HardeningException.THROW_ON_UNRESOLVED); + System.clearProperty(SecureException.THROW_ON_UNRESOLVED); } @BeforeEach void enableThrowOnUnresolved() { - System.setProperty(HardeningException.THROW_ON_UNRESOLVED, "true"); + System.setProperty(SecureException.THROW_ON_UNRESOLVED, "true"); } @Test diff --git a/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java b/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java index eb90418..209db87 100644 --- a/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java +++ b/src/test/java/org/apache/commons/xml/ShadingFootprintTest.java @@ -62,14 +62,14 @@ class ShadingFootprintTest { "SecureDocumentBuilderFactory", "SecureDocumentBuilderFactory$1", "SecureDocumentBuilderFactory$Wrapper", - "HardeningException", + "SecureException", "MethodHandleFactory"); // @formatter:on // @formatter:off private static final Set<String> SAX_PARSER_FACTORY = set( "FallbackIgnoreEntityResolver2", - "HardeningException", + "SecureException", "HardeningSAXParser", "HardeningSAXParserFactory", "HardeningSAXParserFactory$1", @@ -82,7 +82,7 @@ class ShadingFootprintTest { // @formatter:off private static final Set<String> XML_INPUT_FACTORY = set( "FallbackIgnoreXMLResolver", - "HardeningException", + "SecureException", "HardeningXMLInputFactory", "HardeningXMLInputFactory$1", "HardeningXMLInputFactory$Wrapper", @@ -102,7 +102,7 @@ class ShadingFootprintTest { "SecureDocumentBuilderFactory", "SecureDocumentBuilderFactory$1", "SecureDocumentBuilderFactory$Wrapper", - "HardeningException", + "SecureException", "HardeningSAXParser", "HardeningSAXParserFactory", "HardeningSAXParserFactory$1", @@ -132,7 +132,7 @@ class ShadingFootprintTest { "SecureDocumentBuilderFactory$1", "SecureDocumentBuilderFactory$Wrapper", "MethodHandleFactory", - "HardeningException", + "SecureException", "HardeningSAXParser", "HardeningSAXParserFactory", "HardeningSAXParserFactory$1", @@ -154,7 +154,7 @@ class ShadingFootprintTest { private static final Set<String> SCHEMA_FACTORY = saxParserFactoryPlus( "FallbackIgnoreEntityResolver2", "FallbackIgnoreLSResourceResolver", - "HardeningException", + "SecureException", "HardeningSAXParser", "HardeningSAXParserFactory", "HardeningSAXParserFactory$1", @@ -218,7 +218,7 @@ private static Set<String> closureOf(final String simpleName) { @BeforeAll static void indexCompiledClasses() throws Exception { - classesDir = Paths.get(HardeningException.class.getProtectionDomain().getCodeSource().getLocation().toURI()); + classesDir = Paths.get(SecureException.class.getProtectionDomain().getCodeSource().getLocation().toURI()); clazzpath = new Clazzpath(); clazzpath.addClazzpathUnit(classesDir); }
