Skip to content

Commit 60ac5b9

Browse files
authored
Merge commit from fork
adding security tests and a patch for the class pollution and remote code execution
2 parents b639fec + 683756e commit 60ac5b9

16 files changed

+178
-14
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 8.6.0
2+
current_version = 8.6.1
33
commit = True
44
tag = True
55
tag_name = {new_version}

AUTHORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,3 +75,4 @@ Authors in order of the timeline of their contributions:
7575
- [dtorres-sf](https://github.com/dtorres-sf) for the fix for moving nested tables when using iterable_compare_func.
7676
- [Jim Cipar](https://github.com/jcipar) for the fix recursion depth limit when hashing numpy.datetime64
7777
- [Enji Cooper](https://github.com/ngie-eign) for converting legacy setuptools use to pyproject.toml
78+
- [Diogo Correia](https://github.com/diogotcorreia) for reporting security vulnerability in Delta and DeepDiff that could allow remote code execution.

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# DeepDiff Change log
22

3+
- v8-6-1
4+
- Patched security vulnerability in the Delta class which was vulnerable to class pollution via its constructor, and when combined with a gadget available in DeltaDiff itself, it could lead to Denial of Service and Remote Code Execution (via insecure Pickle deserialization).
5+
6+
37
- v8-6-0
48
- Added Colored View thanks to @mauvilsa
59
- Added support for applying deltas to NamedTuple thanks to @paulsc

CITATION.cff

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ authors:
55
given-names: "Sep"
66
orcid: "https://orcid.org/0009-0009-5828-4345"
77
title: "DeepDiff"
8-
version: 8.6.0
8+
version: 8.6.1
99
date-released: 2024
1010
url: "https://github.com/seperman/deepdiff"

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# DeepDiff v 8.6.0
1+
# DeepDiff v 8.6.1
22

33
![Downloads](https://img.shields.io/pypi/dm/deepdiff.svg?style=flat)
44
![Python Versions](https://img.shields.io/pypi/pyversions/deepdiff.svg?style=flat)
@@ -17,12 +17,15 @@
1717

1818
Tested on Python 3.9+ and PyPy3.
1919

20-
- **[Documentation](https://zepworks.com/deepdiff/8.6.0/)**
20+
- **[Documentation](https://zepworks.com/deepdiff/8.6.1/)**
2121

2222
## What is new?
2323

2424
Please check the [ChangeLog](CHANGELOG.md) file for the detailed information.
2525

26+
DeepDiff 8-6-1
27+
- Patched security vulnerability in the Delta class which was vulnerable to class pollution via its constructor, and when combined with a gadget available in DeltaDiff itself, it could lead to Denial of Service and Remote Code Execution (via insecure Pickle deserialization).
28+
2629
DeepDiff 8-6-0
2730

2831
- Added Colored View thanks to @mauvilsa

deepdiff/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""This module offers the DeepDiff, DeepSearch, grep, Delta and DeepHash classes."""
22
# flake8: noqa
3-
__version__ = '8.6.0'
3+
__version__ = '8.6.1'
44
import logging
55

66
if __name__ == '__main__':

deepdiff/delta.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
)
1818
from deepdiff.path import (
1919
_path_to_elements, _get_nested_obj, _get_nested_obj_and_force,
20-
GET, GETATTR, parse_path, stringify_path,
20+
GET, GETATTR, check_elem, parse_path, stringify_path,
2121
)
2222
from deepdiff.anyset import AnySet
2323
from deepdiff.summarize import summarize
@@ -237,6 +237,11 @@ def _get_elem_and_compare_to_old_value(
237237
forced_old_value=None,
238238
next_element=None,
239239
):
240+
try:
241+
check_elem(elem)
242+
except ValueError as error:
243+
self._raise_or_log(UNABLE_TO_GET_ITEM_MSG.format(path_for_err_reporting, error))
244+
return not_found
240245
# if forced_old_value is not None:
241246
try:
242247
if action == GET:
@@ -536,6 +541,7 @@ def _get_elements_and_details(self, path):
536541
obj = self
537542
# obj = self.get_nested_obj(obj=self, elements=elements[:-1])
538543
elem, action = elements[-1] # type: ignore
544+
check_elem(elem)
539545
except Exception as e:
540546
self._raise_or_log(UNABLE_TO_GET_ITEM_MSG.format(path, e))
541547
return None

deepdiff/path.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def _path_to_elements(path, root_element=DEFAULT_FIRST_ELEMENT):
117117

118118
def _get_nested_obj(obj, elements, next_element=None):
119119
for (elem, action) in elements:
120+
check_elem(elem)
120121
if action == GET:
121122
obj = obj[elem]
122123
elif action == GETATTR:
@@ -134,11 +135,17 @@ def _guess_type(elements, elem, index, next_element):
134135
return {}
135136

136137

138+
def check_elem(elem):
139+
if isinstance(elem, str) and elem.startswith("__") and elem.endswith("__"):
140+
raise ValueError("traversing dunder attributes is not allowed")
141+
142+
137143
def _get_nested_obj_and_force(obj, elements, next_element=None):
138144
prev_elem = None
139145
prev_action = None
140146
prev_obj = obj
141147
for index, (elem, action) in enumerate(elements):
148+
check_elem(elem)
142149
_prev_obj = obj
143150
if action == GET:
144151
try:

deepdiff/serialization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ class UnsupportedFormatErr(TypeError):
5959
DELTA_IGNORE_ORDER_NEEDS_REPETITION_REPORT = 'report_repetition must be set to True when ignore_order is True to create the delta object.'
6060
DELTA_ERROR_WHEN_GROUP_BY = 'Delta can not be made when group_by is used since the structure of data is modified from the original form.'
6161

62-
SAFE_TO_IMPORT = {
62+
SAFE_TO_IMPORT = frozenset({
6363
'builtins.range',
6464
'builtins.complex',
6565
'builtins.set',
@@ -95,7 +95,7 @@ class UnsupportedFormatErr(TypeError):
9595
'ipaddress.IPv4Address',
9696
'ipaddress.IPv6Address',
9797
'collections.abc.KeysView',
98-
}
98+
})
9999

100100

101101
TYPE_STR_TO_TYPE = {

docs/authors.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ and polars support.
117117
limit when hashing numpy.datetime64
118118
- `Enji Cooper <https://github.com/ngie-eign>`__ for converting legacy
119119
setuptools use to pyproject.toml
120+
- `Diogo Correia <https://github.com/diogotcorreia>`__ for reporting security vulnerability in Delta and DeepDiff that could allow remote code execution.
120121

121122

122123
.. _Sep Dehpour (Seperman): http://www.zepworks.com

0 commit comments

Comments
 (0)