Menu

🧾 XXE in Python: Turn Off the DTD, Then Prove the Fix
📰

🧾 XXE in Python: Turn Off the DTD, Then Prove the Fix

DEV Community: appsec·Krishna Kumar·1 day ago
#Dp4gXBWM
#devtoappsec#devto#dev#parser#entity
Long article (2148 words) — no AI summary yet.
Reading 0:00
15s threshold

XML External Entity injection (XXE) is one of those bugs where the fix is a one-line setting, and the hard part is knowing whether your parser needs it. In Python the answer depends on which library parses the XML, which version it is, and which of its parser classes you picked. "We use the default" is not an answer you can stop at.

This article covers what XXE is in one paragraph, what Python's parsers actually do by default (I ran it, so the output below is real), where a parser you'd call "safe" has still bitten people, a small parser wrapper that rejects the whole feature, and how to prove the fix with a canary file and a regression test.

Only test applications you own or are authorized to test. Every example uses stand-in data: a canary file I planted and a server on 127.0.0.1 .

What XXE is

XML lets a document declare its own entities in a document type definition (DTD). An external entity says "replace &x; with whatever lives at this URI", and that URI can be a local file or a URL.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.