Skip to content

Prevent XML External Entity injection and DTD expansion (Coverity) - #7169

Open
stweil wants to merge 2 commits into
kitodo:mainfrom
stweil:harden_xml_code
Open

Prevent XML External Entity injection and DTD expansion (Coverity)#7169
stweil wants to merge 2 commits into
kitodo:mainfrom
stweil:harden_xml_code

Conversation

@stweil

@stweil stweil commented Aug 10, 2026

Copy link
Copy Markdown
Member

Introduce a shared XMLSecurity utility class providing hardened DocumentBuilder, Transformer, Schema, SAXParser and XMLInputFactory instances that reject DOCTYPE declarations and disable external entity resolution to prevent XML External Entity (XXE) and entity expansion attacks.

Use the hardened factories in all XML parsing and transformation code paths and null-check the Transformer returned by the factory.

CIDs: 486979, 486985, 486986, 486976, 486990, 487007, 454260, 454251, 431632, 431623, 431616, 431601, 431588, 431586, 431585, 431567, 501288, 501287, 501299, 501300, 501305, 501296, 501292, 501285, 415127, 415247, 415087, 501286, 501294, 501303, 503907, 503911

Assisted-by: OpenCode / big-pickle (opencode)

Introduce a shared XMLSecurity utility class providing hardened
DocumentBuilder, Transformer, Schema, SAXParser and XMLInputFactory
instances that reject DOCTYPE declarations and disable external entity
resolution to prevent XML External Entity (XXE) and entity expansion
attacks.

Use the hardened factories in all XML parsing and transformation code
paths and null-check the Transformer returned by the factory.

CIDs: 486979, 486985, 486986, 486976, 486990, 487007, 454260, 454251,
431632, 431623, 431616, 431601, 431588, 431586, 431585, 431567, 501288,
501287, 501299, 501300, 501305, 501296, 501292, 501285, 415127, 415247,
415087, 501286, 501294, 501303, 503907, 503911

Assisted-by: OpenCode / big-pickle (opencode)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
@codacy-production

codacy-production Bot commented Aug 10, 2026

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 10 complexity · 0 duplication

Metric Results
Complexity 10
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

XMLSecurity.newSecureSource() did not enable namespace awareness on the
SAX parser, so XSLT transformations that depend on namespaced elements
produced output without namespace URIs. This broke the conversion of
old Goobi format metadata files in Kitodo-DataEditor (CI failure).

CIDs: 501288, 501292, 501305

Assisted-by: OpenCode / big-pickle (opencode)
Signed-off-by: Stefan Weil <sw@weilnetz.de>
@solth
solth self-requested a review August 10, 2026 13:13
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.

1 participant