Closed morris821028 closed 1 year ago
Actually the code was written 19 years ago (predates my time with XStream), but I confess the current implementation is unfortunate for elements with a lot of children.
This can be considered as a security issue. An attacker can send XML with many elements to perform DOS attack on a server.
This can be considered as a security issue. An attacker can send XML with many elements to perform DOS attack on a server.
No, but you're free to prove it. DOM is a memory-based model. You'll never get an XML structure loaded with so many elements to slow down this code significantly enough for a DOS attack. You'll run into an OOME first.
Target Object
Source Code
The parser will achieve $O(n^2)$ time when switching context.
https://github.com/x-stream/xstream/blob/master/xstream/src/java/com/thoughtworks/xstream/io/xml/DomReader.java#L135
Because the parser will move down and up, the
DomReader.reassignCurrentElement
in linear time $O(n)$. For each element, this function will be called in $O(n)$. Finally, complete in $O(n^2)$.Then, I'm not sure the implementation of
Element.item(int)
. In my understanding, some of implementations used linked list and make it worse in $O(n^2)$ in oneDomReader.reassignCurrentElement
.Here is my workaround for your reference.