Skip to content

Commit bc4e7be

Browse files
authored
Fix DO04 dead rule by dropping handlesResources from its condition (#335)
Fixes #272. DO04 ("XML Entity Expansion") targets Dataflow, but its condition also reads target.handlesResources, which only exists on Asset subclasses, not on a plain Dataflow. So for any XML dataflow the lookup raises AttributeError, and the broad `except Exception: return False` in Threat.apply swallows it into a False. The rule has been silently dead, never firing on the flows it's meant to flag. Per @raphaelahrens' suggestion in the issue, I dropped the `and target.handlesResources is False` clause so the condition is just `any(d.format == 'XML' for d in target.data)`, which matches the threat's description. I also removed the `handlesResources = False` line in test_DO04, since that assignment was injecting the missing attribute and masking the bug. Tested on Python 3.13: the issue repro now flags DO04, `pytest -k DO04` passes, and the full suite (243 tests) is green. Heads-up: #328 reworks the threat library into Python classes, so if it lands first this'll need a small rebase. Happy to redo it whichever way is easier. Thanks for taking a look. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
1 parent 9412ef4 commit bc4e7be

2 files changed

Lines changed: 1 addition & 2 deletions

File tree

pytm/threatlib/threats.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,7 @@
752752
"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.",
753753
"Likelihood Of Attack": "High",
754754
"severity": "Medium",
755-
"condition": "any(d.format == 'XML' for d in target.data) and target.handlesResources is False",
755+
"condition": "any(d.format == 'XML' for d in target.data)",
756756
"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.",
757757
"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.",
758758
"example": "The most common example of this type of attack is the many laughs attack (sometimes called the 'billion laughs' attack). For example: <?xml version=1.0?><!DOCTYPE lolz [<!ENTITY lol lol><!ENTITY lol2 &lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;><!ENTITY lol3 &lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;><!ENTITY lol4 &lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;><!ENTITY lol5 &lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;><!ENTITY lol6 &lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;><!ENTITY lol7 &lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6><!ENTITY lol8 &lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;><!ENTITY lol9 &lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;> ]><lolz>&lol9;</lolz> 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.",

tests/test_pytmfunc.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,6 @@ def test_DO04(self):
11201120
user_to_web.protocol = "HTTP"
11211121
xml = Data(name="user to web data", description="textual", format="XML")
11221122
user_to_web.data = xml
1123-
user_to_web.handlesResources = False
11241123
threat = threats["DO04"]
11251124
assert threat.apply(user_to_web)
11261125

0 commit comments

Comments
 (0)