Skip to content

Resolve each unresolved URI to a fresh empty document - #69

Merged
garydgregory merged 1 commit into
apache:mainfrom
ppkarwasz:fix/uri-resolver-fresh-empty-document
Sep 1, 2026
Merged

Resolve each unresolved URI to a fresh empty document#69
garydgregory merged 1 commit into
apache:mainfrom
ppkarwasz:fix/uri-resolver-fresh-empty-document

Conversation

@ppkarwasz

Copy link
Copy Markdown
Member

The URIResolver floor answered every unresolved xsl:include/xsl:import/document() reference with a DOMSource over one shared static Document. A fresh DOMSource was created per call, but DOMSource.getNode() hands out the same shared Document, which escapes to the consumer; a component mutating a document it received would surface its changes in every later resolution, process-wide.

Following the JDK's XSLTC TransformerImpl pattern, the default empty-source supplier now builds a fresh empty document per resolution, through SecureDocumentBuilderFactory.newNSInstance(boolean) — the same secured, namespace-aware, JDK-pinned-or-overridden factory selection the Source rewrite uses, an upgrade over the previous raw DocumentBuilderFactory.newInstance() lookup (which also ignored overrideDefaultParser). Creation failure now wraps in IllegalStateException per call instead of ExceptionInInitializerError at class initialization. The empty DOMSource keeps a null system id, and Saxon's EmptySource.getInstance() supplier is untouched (a content-less marker with no DOM to mutate).

The threat model gains the matching scope rule: exploiting the exposure the SpotBugs expose-internal-representation patterns warn about presumes an adversary already running in the process, a capability the model's adversary does not have — so the per-resolution isolation is robustness, not a defended boundary, and reports premised on mutating a returned object are OUT-OF-SCOPE: reconfigured.

Verified with the full surefire matrix and the GraalVM -Pnative-xalan native suite (the new default supplier passes inside the native image with no added reflection metadata); ShadingFootprintTest is unchanged, as the SecureDocumentBuilderFactory classes were already in both pinned closures.

🤖 Generated with Claude Code

The URIResolver floor answered every unresolved reference with a
DOMSource over one shared static Document; the Source escapes to the
consumer, so a component mutating a document it received would surface
its changes in every later resolution, process-wide. Follow the JDK's
XSLTC pattern and build a fresh empty document per resolution, using
the same secured, namespace-aware factory selection as the Source
rewrite (an upgrade over the previous raw JAXP lookup, and it now
honors overrideDefaultParser). Creation failure is wrapped in
IllegalStateException per call instead of ExceptionInInitializerError.

The threat model now states the matching scope rule: modifying a
mutable object a JAXP method returned or stored (the capability behind
the SpotBugs expose-internal-representation patterns) presumes an
adversary already running in the process, which the model does not
defend against — the isolation here is robustness, not a defended
boundary.

Assisted-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CLnTBsvmYtxzNTWVGNyz33
@garydgregory
garydgregory merged commit fa90fe8 into apache:main Sep 1, 2026
17 checks passed
@ppkarwasz
ppkarwasz deleted the fix/uri-resolver-fresh-empty-document branch September 1, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants