I work on a small website where users can upload custom “objects” defined in JSON. I recently learned about possible threats using JSON with automatic type deserialization: JSON problem . I think I understand the issue, but I have to ask to be sure. If I only deserialize the incoming JSON with the given specific type (here MyObject ) JsonConvert.DeserializeObject<MyObject>(json, settings); and there is no type inside MyObject , and no subtype of any member of MyObject is of type System.Object or dynamic , there is nothing that can go wrong, right?
TypeNameHandling of settings set to TypeNameHandling.Auto (do not question this solution, it may work with None , but I want to understand that the question with it is set to Auto .)
Edit: Additional info: I tested JSON from the previously mentioned website:
{ "obj": { "$type": "System.IO.FileInfo, System.IO.FileSystem", "fileName": "rce-test.txt", "IsReadOnly": true } }
If MyObject has System.Object or dynamic obj entered, I can reproduce the threat. But what I want to know: I am safe with poorly prepared user-json, even if MyObject is a very complex object with a lot of (derived) auxiliary objects, but NONE of them has or has System.Object or a dynamic field (also not something like List<Object> )? For instance. I could imagine that Json.NET was doing something like creating objects because of the $type information, even if no field was found in the MyObject field.
source share