Skip to content

Commit d962e4c

Browse files
ppkarwaszgarydgregory
authored andcommitted
Document the ignore-all contract on the site index
Add a Configuration section: external references resolve to empty streams, applications that want rejection tighten the factory themselves (a stricter feature or a throwing resolver, with no security weight either way), and org.apache.commons.xml.throwOnUnresolved is a temporary debugging switch. Align the Usage paragraph with the same contract. Assisted-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 9278083 commit d962e4c

1 file changed

Lines changed: 42 additions & 3 deletions

File tree

src/site/markdown/index.md

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,13 @@ Add the library to your build:
5757
</dependency>
5858
```
5959

60-
Every method on `XmlFactories` returns a fresh, hardened factory. Pick the one that matches the API you already use; no
61-
other configuration is required. On hardened factories any attempt to resolve an external resource (DTD, entity, schema,
62-
stylesheet) is blocked, and DOCTYPE input is rejected wherever the underlying implementation allows it.
60+
Every method on `XmlFactories` returns a fresh, hardened factory.
61+
Pick the one that matches the API you already use;
62+
no other configuration is required.
63+
On hardened factories an external resource reference (DTD, entity, schema, stylesheet) is never fetched:
64+
it resolves to empty content,
65+
so the parse continues without it
66+
(see Configuration below).
6367

6468
### Supported implementations
6569

@@ -144,3 +148,38 @@ There is no caching or pooling inside `XmlFactories`; callers on a hot path are
144148
returned factories inherit the thread-safety properties of the underlying JAXP implementation, which in practice means
145149
they are not thread-safe. Create a new factory per thread or synchronize externally.
146150

151+
## Configuration
152+
153+
The hardened factories need no configuration.
154+
When a document references an external resource
155+
(a DTD, an external entity, a schema, an XInclude target, or an XSLT document),
156+
the hardening layer resolves the reference to an empty stream:
157+
nothing is fetched,
158+
nothing leaks into the result,
159+
and the parse continues wherever the implementation can proceed with empty content.
160+
This forgiving default accommodates documents that merely carry such references without needing them.
161+
162+
If your application should reject such documents instead of parsing them,
163+
tighten the factory yourself.
164+
The hardening floor stays underneath whatever you configure,
165+
so the tightening carries **no security weight**
166+
and can be as strict as the application needs:
167+
168+
- Set a stricter feature on the factory,
169+
for example `http://apache.org/xml/features/disallow-doctype-decl`
170+
to reject every document carrying a DOCTYPE,
171+
on implementations that support the feature.
172+
- Install a resolver that throws.
173+
A caller-supplied `EntityResolver`, `XMLResolver`, `LSResourceResolver` or `URIResolver`
174+
is consulted before the hardening floor,
175+
so an allow-list and a deny-all are both one resolver away.
176+
177+
As a temporary debugging measure,
178+
set the system property `org.apache.commons.xml.throwOnUnresolved` to `true`:
179+
every unresolved external reference is then rejected with the resolution hook's exception,
180+
and the message names the denied resource.
181+
The property is read at resolution time,
182+
so it can be toggled on a running application;
183+
treat it as a diagnostic switch,
184+
not as an application configuration.
185+

0 commit comments

Comments
 (0)