Skip to content

Commit 04223a2

Browse files
authored
Merge pull request #5803 from chaen/v7r2_FIX_secuJEncode
[v7r2] Fix exploit in JEncode
2 parents 36c3cd9 + e39eaf1 commit 04223a2

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/DIRAC/Core/Utilities/JEncode.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,12 @@ def dict_to_object(dataDict):
150150
mod = importlib.import_module(modName)
151151
# import the class
152152
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+
153159
# Instantiate the object
154160
obj = cl()
155161

src/DIRAC/Core/Utilities/test/Test_Encode.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,15 @@ def test_missingAttrToSerialize():
343343
agnosticTestFunction(jsonTuple, objData)
344344

345345

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+
346355
@mark.slow
347356
@settings(suppress_health_check=function_scoped)
348357
@given(data=nestedStrategyJson)

0 commit comments

Comments
 (0)