News for hackers. Stuff that matters.
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.
Re:Bad JSON Parsers by Spivak on Friday November 08, 2019 @12:17PM (#21484339)
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.
Re:Bad JSON Parsers by anoncake on Friday November 08, 2019 @12:15PM (#21484312)
Documented or not, you shouldn't rely on the lib only throwing JSONDecodeError in security-critical code.
Re:Bad JSON Parsers by Spivak on Friday November 08, 2019 @12:19PM (#21484370)
But what can you do instead? It’s a really hard problem to validate generic JSON without accidentally parsing it.
Re:Bad JSON Parsers by zeroimpl on Friday November 08, 2019 @02:15PM (#21485682)
Validation better be done by the parser. Otherwise, subtle differences between the validator and the parser can lead to security flaws. Your solution is to make sure you use a good parser.