diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 7125dd4..cc8ef12 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -25,4 +25,4 @@ updates: schedule: interval: "weekly" cooldown: - default-days: 7 \ No newline at end of file + default-days: 7 diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index fff0865..68247ef 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -32,4 +32,4 @@ jobs: permissions: actions: read contents: read - security-events: write \ No newline at end of file + security-events: write diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 1687801..21f86f6 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -198,4 +198,4 @@ jobs: android-tests/build/outputs/androidTest-results/ android-tests/build/reports/androidTests/ if-no-files-found: ignore - retention-days: 14 \ No newline at end of file + retention-days: 14 diff --git a/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java b/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java index 9aba89f..92100a0 100644 --- a/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java +++ b/src/main/java/org/apache/commons/xml/DocumentBuilderHardener.java @@ -67,7 +67,7 @@ static DocumentBuilderFactory harden(final DocumentBuilderFactory factory) { // ACCESS_EXTERNAL_* support is the dividing capability between JAXP 1.5 implementations and older ones. if (trySetAttribute(factory, XMLConstants.ACCESS_EXTERNAL_DTD, "") && trySetAttribute(factory, XMLConstants.ACCESS_EXTERNAL_SCHEMA, "")) { - // Honoured: the JAXP 1.5 properties block external fetches, so the bare factory is already hardened. + // Honored: the JAXP 1.5 properties block external fetches, so the bare factory is already hardened. return factory; } // Rejected: external Xerces ignores ACCESS_EXTERNAL_*; install a deny-all resolver on every DocumentBuilder. diff --git a/src/main/java/org/apache/commons/xml/Limits.java b/src/main/java/org/apache/commons/xml/Limits.java index ec00834..4829711 100644 --- a/src/main/java/org/apache/commons/xml/Limits.java +++ b/src/main/java/org/apache/commons/xml/Limits.java @@ -97,7 +97,7 @@ final class Limits { */ private static final int DEFAULT_MAX_ELEMENT_DEPTH = 100; /** - * Maximum length, in characters, of an XML name (element name, attribute name, namespace prefix, etc); JDK 25 secure value. + * Maximum length, in characters, of an XML name (element name, attribute name, namespace prefix, and so on); JDK 25 secure value. * *

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 47e952e..708b989 100644 --- a/src/main/java/org/apache/commons/xml/SAXParserHardener.java +++ b/src/main/java/org/apache/commons/xml/SAXParserHardener.java @@ -158,7 +158,7 @@ static SAXParserFactory harden(final SAXParserFactory factory) { */ static XMLReader hardenReader(final XMLReader reader) { if (reader instanceof HardeningXMLReader) { - // Already hardened (e.g. handed back through XmlFactories.harden(XMLReader)); the floor is already in place. + // Already hardened (for example, handed back through XmlFactories.harden(XMLReader)); the floor is already in place. return reader; } if (ANDROID_EXPAT_READER.equals(reader.getClass().getName())) { 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 @@ *

Thread safety

* *

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 952cd75..c0ebd67 100644 --- a/src/test/java/org/apache/commons/xml/AttackTestSupport.java +++ b/src/test/java/org/apache/commons/xml/AttackTestSupport.java @@ -58,17 +58,17 @@ /** * 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:

* * * @@ -189,7 +189,7 @@ static void assertDomBlocks(final String payload) { * Asserts a hardened DOM parse completes without throwing and without leaked content. * *

{@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"); @@ -208,7 +208,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}. @@ -409,7 +409,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"); @@ -446,7 +446,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) { @@ -456,7 +456,7 @@ static void assertSchemaDoesNotLeak(final Source xsd) { /** * Asserts a hardened StAX parse of the payload throws. * - *

{@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) { @@ -467,8 +467,8 @@ 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 - * hardening guarantee is "the parse succeeds but never resolves the external resource", e.g. when the JDK's {@code ignore-external-dtd} property silently + *

{@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", 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/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:

* *