From 613bb636513741c7801a44f78275fec0ef7c1394 Mon Sep 17 00:00:00 2001
From: "Piotr P. Karwasz" Two flavours are exposed, each as a typed singleton field per resolver interface: Two flavors are exposed, each as a typed singleton field per resolver interface: {@link XMLResolver} and {@link EntityResolver2} both declare a 4-arg {@code resolveEntity(String, String, String, String)} with identical erasure but
* different parameter semantics, return types ({@link Object} vs {@link InputSource}) and throws clauses ({@link XMLStreamException} vs {@link SAXException}),
- * so they cannot coexist on the same class. Each flavour therefore exposes its {@code XMLResolver} and {@code EntityResolver2} singletons separately.
*
Only an {@link XMLResolver} flavour is exposed: schema and XSLT compile paths must always deny imports, and SAX/DOM use the deny-all hooks.
+ *Only an {@link XMLResolver} flavor is exposed: schema and XSLT compile paths must always deny imports, and SAX/DOM use the deny-all hooks.
*/ static final class IgnoreAll { diff --git a/src/main/java/org/apache/commons/xml/SAXParserHardener.java b/src/main/java/org/apache/commons/xml/SAXParserHardener.java index 7b1fb7d..8f6684f 100644 --- a/src/main/java/org/apache/commons/xml/SAXParserHardener.java +++ b/src/main/java/org/apache/commons/xml/SAXParserHardener.java @@ -175,7 +175,7 @@ static XMLReader hardenReader(final XMLReader reader) { // ACCESS_EXTERNAL_* support is the dividing capability between JAXP 1.5 implementations and older ones. if (trySetProperty(reader, XMLConstants.ACCESS_EXTERNAL_DTD, "") && trySetProperty(reader, XMLConstants.ACCESS_EXTERNAL_SCHEMA, "")) { - // Honoured (stock JDK): the JAXP 1.5 properties block external fetches, so the bare reader is already hardened. + // Honored (stock JDK): the JAXP 1.5 properties block external fetches, so the bare reader is already hardened. return reader; } // Rejected: external Xerces ignores ACCESS_EXTERNAL_*; install a deny-all resolver, the only block. diff --git a/src/main/java/org/apache/commons/xml/XmlFactories.java b/src/main/java/org/apache/commons/xml/XmlFactories.java index 41056ff..a5b5c6d 100644 --- a/src/main/java/org/apache/commons/xml/XmlFactories.java +++ b/src/main/java/org/apache/commons/xml/XmlFactories.java @@ -67,7 +67,7 @@ *The returned factories inherit the thread-safety properties of the underlying JAXP implementation, which in practice means they are not - * guaranteed to be thread-safe. Create a new factory per thread or synchronise externally.
+ * guaranteed to be thread-safe. Create a new factory per thread or synchronize externally. * *This class itself is thread-safe: all methods are static and stateless.
*/ diff --git a/src/site/markdown/index.md b/src/site/markdown/index.md index daa877b..98cc59e 100644 --- a/src/site/markdown/index.md +++ b/src/site/markdown/index.md @@ -30,7 +30,7 @@ stock JDK and external JAXP implementations. Any Java library that parses XML has to harden JAXP before handing a factory to user code, and every library ends up copy-pasting the same hardening snippet. The snippet is fragile: the attributes and features needed to harden a factory -are not standardised, each JAXP implementation exposes a slightly different set, and setting an unknown one throws an +are not standardized, each JAXP implementation exposes a slightly different set, and setting an unknown one throws an exception that callers routinely swallow. Writing this block correctly for every implementation is real work, and duplicating it across projects means every project owns the maintenance burden on its own. @@ -142,5 +142,5 @@ pass the result as a `DOMSource` or `SAXSource`. There is no caching or pooling inside `XmlFactories`; callers on a hot path are responsible for their own caching. The returned factories inherit the thread-safety properties of the underlying JAXP implementation, which in practice means -they are not thread-safe. Create a new factory per thread or synchronise externally. +they are not thread-safe. Create a new factory per thread or synchronize externally. diff --git a/src/test/java/org/apache/commons/xml/AttackTestSupport.java b/src/test/java/org/apache/commons/xml/AttackTestSupport.java index 9b6c07f..b64751a 100644 --- a/src/test/java/org/apache/commons/xml/AttackTestSupport.java +++ b/src/test/java/org/apache/commons/xml/AttackTestSupport.java @@ -54,7 +54,7 @@ /** * Shared fixtures for attack tests. * - *The hardened-side helpers come in three flavours, distinguished by their suffix:
+ *The hardened-side helpers come in three flavors, distinguished by their suffix:
* *{@link XMLStreamReader} and {@link XMLEventReader} from {@link XmlFactories#newXMLInputFactory()}; both flavours are exercised and either must + *
{@link XMLStreamReader} and {@link XMLEventReader} from {@link XmlFactories#newXMLInputFactory()}; both flavors are exercised and either must * throw.
*/ static void assertStaxBlocks(final String payload) { @@ -463,7 +463,7 @@ static void assertStaxBlocks(final String payload) { /** * Asserts a hardened StAX parse completes without throwing and without leaked content. * - *{@link XMLStreamReader} and {@link XMLEventReader} from {@link XmlFactories#newXMLInputFactory()}; both flavours are exercised. Use this when the + *
{@link XMLStreamReader} and {@link XMLEventReader} from {@link XmlFactories#newXMLInputFactory()}; both flavors are exercised. Use this when the * hardening guarantee is "the parse succeeds but never resolves the external resource", e.g. when the JDK's {@code ignore-external-dtd} property silently * skips the external subset.
*/ diff --git a/src/test/java/org/apache/commons/xml/BillionLaughsTest.java b/src/test/java/org/apache/commons/xml/BillionLaughsTest.java index eb18e72..164839a 100644 --- a/src/test/java/org/apache/commons/xml/BillionLaughsTest.java +++ b/src/test/java/org/apache/commons/xml/BillionLaughsTest.java @@ -45,7 +45,7 @@ *Which fixture each test uses:
* *Override with system property {@value #SP_MAX_NAME_LIMIT}.
* diff --git a/src/main/java/org/apache/commons/xml/SAXParserHardener.java b/src/main/java/org/apache/commons/xml/SAXParserHardener.java index 8f6684f..ea76066 100644 --- a/src/main/java/org/apache/commons/xml/SAXParserHardener.java +++ b/src/main/java/org/apache/commons/xml/SAXParserHardener.java @@ -154,7 +154,7 @@ static SAXParserFactory harden(final SAXParserFactory factory) { */ static XMLReader hardenReader(final XMLReader reader) { if (reader instanceof ExpatReaderWrapper) { - // Already hardened (e.g. handed back through XmlFactories.harden(XMLReader)); applying the Expat fixups again would be redundant. + // Already hardened (for example, handed back through XmlFactories.harden(XMLReader)); applying the Expat fixups again would be redundant. return reader; } if (ANDROID_EXPAT_READER.equals(reader.getClass().getName())) { diff --git a/src/test/java/org/apache/commons/xml/AttackTestSupport.java b/src/test/java/org/apache/commons/xml/AttackTestSupport.java index b64751a..32997b2 100644 --- a/src/test/java/org/apache/commons/xml/AttackTestSupport.java +++ b/src/test/java/org/apache/commons/xml/AttackTestSupport.java @@ -60,11 +60,11 @@ *{@link DocumentBuilder#parse(InputSource)} via {@link XmlFactories#newDocumentBuilderFactory()}; use this when the hardening guarantee is "the parse - * succeeds but never resolves the external resource", e.g. when {@code XERCES_LOAD_EXTERNAL_DTD=false} silently skips the external subset.
+ * succeeds but never resolves the external resource", for example, when {@code XERCES_LOAD_EXTERNAL_DTD=false} silently skips the external subset. */ static void assertDomDoesNotLeak(final String payload) { assertNoLeakStrict(() -> domParseAndCaptureText(payload), "DOM"); @@ -204,7 +204,7 @@ static void assertDomParses(final String payload) { * Skeleton for every {@code assert*BlocksOrDoesNotLeak} helper. * *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 (e.g. 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 HardeningException} * because no recipe matched the JAXP implementation) cannot be silently accepted as a clean block.
* * @param action the parse to execute, returning the captured output text checked for {@link #LEAKED_MARKER}. @@ -405,7 +405,7 @@ static void assertSaxBlocks(final String payload) { * Asserts a hardened SAX parse completes without throwing and without leaked content. * *{@link XMLReader#parse(InputSource)} on a parser from {@link XmlFactories#newSAXParserFactory()}; use this when the hardening guarantee is "the parse - * succeeds but never resolves the external resource", e.g. when {@code XERCES_LOAD_EXTERNAL_DTD=false} silently skips the external subset.
+ * succeeds but never resolves the external resource", for example, when {@code XERCES_LOAD_EXTERNAL_DTD=false} silently skips the external subset. */ static void assertSaxDoesNotLeak(final String payload) { assertNoLeakStrict(() -> captureCharacters(strictXMLReader(XmlFactories.newSAXParserFactory()), payload), "SAX"); @@ -442,7 +442,7 @@ static void assertSchemaCompiles(final Source xsd) { * Asserts a hardened Schema compilation completes without throwing. * *{@link SchemaFactory#newSchema(Source)} via {@link XmlFactories#newSchemaFactory()}; use this when the hardening contract guarantees the compile - * succeeds but never resolves the external resource (e.g. {@code XERCES_LOAD_EXTERNAL_DTD=false} silently skipping the external subset, with the body's + * succeeds but never resolves the external resource (for example, {@code XERCES_LOAD_EXTERNAL_DTD=false} silently skipping the external subset, with the body's * undeclared entity reference dropped per XML 1.0 §4.1).
*/ static void assertSchemaDoesNotLeak(final Source xsd) { @@ -464,7 +464,7 @@ static void assertStaxBlocks(final String payload) { * Asserts a hardened StAX parse completes without throwing and without leaked content. * *{@link XMLStreamReader} and {@link XMLEventReader} from {@link XmlFactories#newXMLInputFactory()}; both flavors are exercised. Use this when the - * hardening guarantee is "the parse succeeds but never resolves the external resource", e.g. when the JDK's {@code ignore-external-dtd} property silently + * 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.
*/ static void assertStaxDoesNotLeak(final String payload) { diff --git a/src/test/java/org/apache/commons/xml/NoDoctypeTest.java b/src/test/java/org/apache/commons/xml/NoDoctypeTest.java index a6536e0..e95335b 100644 --- a/src/test/java/org/apache/commons/xml/NoDoctypeTest.java +++ b/src/test/java/org/apache/commons/xml/NoDoctypeTest.java @@ -24,7 +24,7 @@ * Checks that a plain document without a {@code DOCTYPE} declaration parses cleanly through every hardened JAXP surface. * *This is the realistic 99% case for hardened input; the hardening contract being verified is "documents without a DOCTYPE parse cleanly through every - * JAXP surface" so accidental tightening (e.g. a resolver that refuses the synthetic-external-subset hook) is caught.
+ * JAXP surface" so accidental tightening (for example, a resolver that refuses the synthetic-external-subset hook) is caught. */ class NoDoctypeTest { diff --git a/src/test/java11/org/apache/commons/xml/DescriptorIT.java b/src/test/java11/org/apache/commons/xml/DescriptorIT.java index f275018..28a1c96 100644 --- a/src/test/java11/org/apache/commons/xml/DescriptorIT.java +++ b/src/test/java11/org/apache/commons/xml/DescriptorIT.java @@ -118,7 +118,7 @@ private static JarEntry findModuleInfo(final JarFile jar) { } /** - * Returns whether {@code pkg} is exported by an OSGi system bundle, i.e. it sits under one of {@link #PLATFORM_PACKAGE_PREFIXES}. + * Returns whether {@code pkg} is exported by an OSGi system bundle, that is, it sits under one of {@link #PLATFORM_PACKAGE_PREFIXES}. */ private static boolean isPlatformPackage(final String pkg) { for (final String prefix : PLATFORM_PACKAGE_PREFIXES) { @@ -150,7 +150,7 @@ private static List