From aed0e6da41bf0df164d4a1ada4df64280026df84 Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Sat, 27 Jun 2026 10:09:48 +0900 Subject: [PATCH] Fix DO04 dead rule: drop handlesResources from XML entity-expansion condition DO04 (XML Entity Expansion) targets Dataflow, but its condition also read target.handlesResources, an attribute that only exists on Asset subclasses. For any XML Dataflow the lookup raised AttributeError, which the broad except Exception in Threat.apply swallowed and turned into False, so DO04 never fired on the very flows it is meant to flag. Drop the handlesResources clause, leaving the format check that matches the threat description. Also remove the test line that injected handlesResources onto a Dataflow, which had been masking the bug. Fixes #272 Signed-off-by: Arpit Jain --- pytm/threatlib/threats.json | 2 +- tests/test_pytmfunc.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pytm/threatlib/threats.json b/pytm/threatlib/threats.json index 4087280..33b38aa 100644 --- a/pytm/threatlib/threats.json +++ b/pytm/threatlib/threats.json @@ -752,7 +752,7 @@ "details": "An attacker submits an XML document to a target application where the XML document uses nested entity expansion to produce an excessively large output XML. XML allows the definition of macro-like structures that can be used to simplify the creation of complex structures. However, this capability can be abused to create excessive demands on a processor's CPU and memory. A small number of nested expansions can result in an exponential growth in demands on memory.", "Likelihood Of Attack": "High", "severity": "Medium", - "condition": "any(d.format == 'XML' for d in target.data) and target.handlesResources is False", + "condition": "any(d.format == 'XML' for d in target.data)", "prerequisites": "This type of attack requires that the target must receive XML input but either fail to provide an upper limit for entity expansion or provide a limit that is so large that it does not preclude significant resource consumption.", "mitigations": "Design: Use libraries and templates that minimize unfiltered input. Use methods that limit entity expansion and throw exceptions on attempted entity expansion.Implementation: Disable altogether the use of inline DTD schemas in your XML parsing objects. If must use DTD, normalize, filter and white list and parse with methods and routines that will detect entity expansion from untrusted sources.", "example": "The most common example of this type of attack is the many laughs attack (sometimes called the 'billion laughs' attack). For example: ]>&lol9; This is well formed and valid XML according to the DTD. Each entity increases the number entities by a factor of 10. The line of XML containing lol9; expands out exponentially to a message with 10^9 entities. A small message of a few KBs in size can easily be expanded into a few GB of memory in the parser. By including 3 more entities similar to the lol9 entity in the above code to the DTD, the program could expand out over a TB as there will now be 10^12 entities. Depending on the robustness of the target machine, this can lead to resource depletion, application crash, or even the execution of arbitrary code through a buffer overflow.", diff --git a/tests/test_pytmfunc.py b/tests/test_pytmfunc.py index 7057ecf..9fec08a 100644 --- a/tests/test_pytmfunc.py +++ b/tests/test_pytmfunc.py @@ -1120,7 +1120,6 @@ def test_DO04(self): user_to_web.protocol = "HTTP" xml = Data(name="user to web data", description="textual", format="XML") user_to_web.data = xml - user_to_web.handlesResources = False threat = threats["DO04"] assert threat.apply(user_to_web)