Billion laughs
en.wikipedia.org
en.wikipedia.org
Even simple bash scripts can do weird things like this. And that's a lot smaller.
It shouldn't be possible to use resources exponential to the input size for just PARSING (not doing anything else with) XML. This is a great example of why you want to use simple serialization formats like JSON.
It's the same reason I never liked YAML. The spec and implementations are just way too big. There's got to be something hiding in there like this.
#define s, any kind of macro system they all suffer from this, as soon as you are allowed to define an entity referencing another defined entity you have a bomb on board.
A better analogy would be a language where you can't even parse it without executing arbitrary code (Perl is probably a good example: http://www.perlmonks.org/?node_id=663393)
Python AFAICT is quite safe to parse. It's not a common distinction because you normally parse stuff to execute it, and executing can do much worse things, of course. But where it might come into play is if you wanted to write a cloud service accepts arbitrary code and just does static analysis on python or bash. What kind of security would you need?
It's a design flaw in the format itself -- in this case, XML. A fork bomb is not a flaw in the design of bash.
It seems like the only way to totally secure an automated system against this kind of attack is to have a limit on parser memory usage and CPU cycles, and reject input when the parser breaks any of these limits.
It isn't exponential, no, but you're quite likely to still crash something if the receiver was not programmed to handle that.
lol1: &lol1
"lol"
lol2: &lol2
[*lol1,*lol1,*lol1,*lol1,*lol1,*lol1,*lol1,*lol1,*lol1,*lol1]
lol3: &lol3
[*lol2,*lol2,*lol2,*lol2,*lol2,*lol2,*lol2,*lol2,*lol2,*lol2]
lol4: &lol4
[*lol3,*lol3,*lol3,*lol3,*lol3,*lol3,*lol3,*lol3,*lol3,*lol3]
lol5: &lol5
[*lol4,*lol4,*lol4,*lol4,*lol4,*lol4,*lol4,*lol4,*lol4,*lol4]
lol6: &lol6
[*lol5,*lol5,*lol5,*lol5,*lol5,*lol5,*lol5,*lol5,*lol5,*lol5]
lol7: &lol7
[*lol6,*lol6,*lol6,*lol6,*lol6,*lol6,*lol6,*lol6,*lol6,*lol6]
lol8: &lol8
[*lol7,*lol7,*lol7,*lol7,*lol7,*lol7,*lol7,*lol7,*lol7,*lol7]
lol9: &lol9
[*lol8,*lol8,*lol8,*lol8,*lol8,*lol8,*lol8,*lol8,*lol8,*lol8]In fact, I don't even think that is legal for them to be copies, as this is the means by which YAML allows circular data structures to be represented.
As aardvark179 noted, a usage concern with YAML is more with how an unguarded application might fail to check for serialized graph cycles.
Is there a list of these reasons? Apart from graph cycles, I have only come across some gotchas (e.g. using "yes" without quotes in a translation file).
Can we move beyond this simple issue and discuss more complicated aspects of security on HN?
https://news.ycombinator.com/item?id=259458
https://news.ycombinator.com/item?id=3859853
https://news.ycombinator.com/item?id=1674911
https://news.ycombinator.com/item?id=301296
https://news.ycombinator.com/item?id=4619344
People that exploit these kinds of things continue to innovate, but HN seems to be stuck with XSS, SQLi, and malformed XML.
Edit: This does make me think that I've been meaning to write a blog post about a security issue I discovered for about 6 months now. Time to do that.
EDIT:
HN seems to be stuck with XSS, SQLi, and malformed XML
HN is not a person: half of today's HN didn't exist two years ago [1].
[1] http://blog.rjmetrics.com/surprising-hacker-news-data-analys...
Read more books.
Occasionally warning people about known dangers doesn't harm. Sure that's not exactly moving the needle but it may help to mitigate a few lurking problems that people were not yet aware of.
Think of it as a 'wear your seatbelt' advertisement. If you're already wearing your seatbelt then it wasn't meant for you.
Look, if people vote it up it means they like it. Just because its been talked about before doesn't make it less valuable.
If you would like a part of it improved & expanded, please proceed to do so.
Each line in the WP examaple amplifies by a factor of 10. It has 9 lines. It's 10e9. That's a billion times 3, which is just enough to 32-bit virtual memory space in common operating systems.
Of course the XML implementation could be smart and short-circuit this while preserving the semantics.
(And the parent actually mentioned the 3 GB minimum, I think it was essentially asking how much extra memory a real world XML parser uses.)
(news.yc used to be a Lisp hangout)
There really isn't any recursion in that XML snippet, none of the entities refers to itself, directly or transitively. If there was, the file would be invalid and the error probably caught by the parser before dying from memory exhaustion. There's no way to terminate recursion in XML entities.
As with any feature, there are possible use cases. Perhaps you want to create a form document and use custom entities that you modify later to fill the document out.
But the amount of times that's useful is not likely to be worth the potential harm of things like billion laughs. Easy to separate that functionality, and have your XML parser do an element data replace with your own custom tokens. Eg node.replace("{name}", customerName);
That being said, like many of the things in XML, DTDs and entities not very useful outside of publishing/markup use cases, and dangerous on top of it (not only for the billion laughs, e.g. including system entities).
and that's probably because macros systems typically are recursive since they are otherwise fairly limited, so this is a way to give them sufficient expressive power. so the explanation is probably "tradition" (and likely made more sense in sgml, which was the precursor to html).
I guess you could do this with YAML too?
I don't know YAML well but I believe if you tried this trick with something like alias nodes then you would end up with a lol9 node with ten separate connections to a single lol8 node with ten separate connections to a single lol7 node and so on. This would not produce the same problem in the parser, though might trigger problems in whatever processed the resulting graph.
Functional programming wins here.