Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion azure/functions/_durable_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
from importlib import import_module


_DESERIALIZATION_LIST = {
'azure.functions._cosmosdb': {'Document'},
'azure.functions._sql': {'SqlRow'},
'azure.functions._mysql': {'MySqlRow'},
}


# Utilities
def _serialize_custom_object(obj):
"""Serialize a user-defined object to JSON.
Expand Down Expand Up @@ -62,6 +69,8 @@ def _deserialize_custom_object(obj: dict) -> object:

Exceptions
----------
ValueError
If the module or class is not in the deserialization list
TypeError
If the decoded object does not contain a `from_json` function
"""
Expand All @@ -70,7 +79,23 @@ def _deserialize_custom_object(obj: dict) -> object:
module_name = obj.pop("__module__")
obj_data = obj.pop("__data__")

# Importing the clas
# Validate module and class
if module_name not in _DESERIALIZATION_LIST:
raise ValueError(
f"Deserialization of module '{module_name}' is not allowed. "
f"Only the following modules are permitted: "
f"{', '.join(_DESERIALIZATION_LIST.keys())}"
)

allowed_classes = _DESERIALIZATION_LIST[module_name]
if class_name not in allowed_classes:
raise ValueError(
f"Deserialization of class '{class_name}' from module "
f"'{module_name}' is not allowed. "
f"Only the following classes are permitted: "
f"{', '.join(allowed_classes)}"
)

module = import_module(module_name)
class_ = getattr(module, class_name)

Expand Down
Loading