JSONObject contains this logic to prevent a key in a JSON object from being another JSON object or an array:
case '{':
case '[':
if(prev=='{') {
throw x.syntaxError("A JSON Object can not directly nest another JSON Object or JSON Array.");
}
However this doesn't cover all cases. For example, JSONObject currently accepts this string:
which it interprets as an object with two keys, one that is the string a and one that is the string [{"b":2}].
Strict JSON, of course, only accepts string literals as keys in objects. JSON-java is more liberal, but it does balk at nested objects since the fix for #654. The example above suggests that that fix was incomplete. I think it would make sense to disallow nested objects or arrays as keys always. They're not valid JSON and it's unlikely that anyone is relying on them for legitimate purposes. Meanwhile they can straightforwardly be used for DoS attacks, similar to #654 and #758.
I have a proposed fix which I will send shortly.
JSONObjectcontains this logic to prevent a key in a JSON object from being another JSON object or an array:However this doesn't cover all cases. For example,
JSONObjectcurrently accepts this string:which it interprets as an object with two keys, one that is the string
aand one that is the string[{"b":2}].Strict JSON, of course, only accepts string literals as keys in objects. JSON-java is more liberal, but it does balk at nested objects since the fix for #654. The example above suggests that that fix was incomplete. I think it would make sense to disallow nested objects or arrays as keys always. They're not valid JSON and it's unlikely that anyone is relying on them for legitimate purposes. Meanwhile they can straightforwardly be used for DoS attacks, similar to #654 and #758.
I have a proposed fix which I will send shortly.