File tree Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Expand file tree Collapse file tree 2 files changed +15
-0
lines changed Original file line number Diff line number Diff line change @@ -150,6 +150,12 @@ def dict_to_object(dataDict):
150
150
mod = importlib .import_module (modName )
151
151
# import the class
152
152
cl = getattr (mod , className )
153
+
154
+ # Check that cl is a subclass of JSerializable,
155
+ # and that we are not putting ourselves in trouble...
156
+ if not (isinstance (cl , type ) and issubclass (cl , JSerializable )):
157
+ raise TypeError ("Only subclasses of JSerializable can be decoded" )
158
+
153
159
# Instantiate the object
154
160
obj = cl ()
155
161
Original file line number Diff line number Diff line change @@ -343,6 +343,15 @@ def test_missingAttrToSerialize():
343
343
agnosticTestFunction (jsonTuple , objData )
344
344
345
345
346
+ def test_JSerializableExploit ():
347
+ """Test that we cannot execute arbitrary code with JENcode"""
348
+
349
+ exploit = '{"__dCls": "exit", "__dMod": "sys"}'
350
+
351
+ with raises (TypeError ):
352
+ jsonDecode (exploit )
353
+
354
+
346
355
@mark .slow
347
356
@settings (suppress_health_check = function_scoped )
348
357
@given (data = nestedStrategyJson )
You can’t perform that action at this time.
0 commit comments