Re:Bad JSON Parsers
by lovasoa on Friday November 08, 2019 @11:23AM
(#21483696)
Exactly.
Another example is python's standard library json parser that is documented to throw a JSONDecodeError on invalid input. But if the invalid json contains deeply nested structures, it raises a RecursionError, and this is not documented anywhere. It's easy to imagine how a code that only catches JSONDecodeError while decoding untrusted inputs could be exploited by an attacker.
[ Parent
| on HN ]
Ugh Python exceptions are always a source of anxiety for me. Without combing through the source and locking yourself to specific versions it’s nigh impossible to be sure you’ve caught everything without a “catch everything” block.
Documented or not, you shouldn't rely on the lib only throwing JSONDecodeError in security-critical code.
But what can you do instead? It’s a really hard problem to validate generic JSON without accidentally parsing it.