Skip to content
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions bandit/blacklists/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
| | | - jsonpickle.unpickler.decode | |
| | | - jsonpickle.unpickler.Unpickler | |
| | | - pandas.read_pickle | |
| | | - cloudpickle.loads | |
| | | - cloudpickle.load | |
| | | - cloudpickle.Unpickler | |
+------+---------------------+------------------------------------+-----------+

B302: marshal
Expand Down Expand Up @@ -373,6 +376,9 @@ def gen_blacklist():
"jsonpickle.unpickler.decode",
"jsonpickle.unpickler.Unpickler",
"pandas.read_pickle",
"cloudpickle.loads",
"cloudpickle.load",
"cloudpickle.Unpickler",
],
"Pickle and modules that wrap it can be unsafe when used to "
"deserialize untrusted data, possible security issue.",
Expand Down
3 changes: 2 additions & 1 deletion bandit/blacklists/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
| | | - cPickle | |
| | | - dill | |
| | | - shelve | |
| | | - cloudpickle | |
+------+---------------------+------------------------------------+-----------+

B404: import_subprocess
Expand Down Expand Up @@ -272,7 +273,7 @@ def gen_blacklist():
"import_pickle",
"B403",
issue.Cwe.DESERIALIZATION_OF_UNTRUSTED_DATA,
["pickle", "cPickle", "dill", "shelve"],
["pickle", "cPickle", "dill", "shelve", "cloudpickle"],
"Consider possible security implications associated with "
"{name} module.",
"LOW",
Expand Down
14 changes: 14 additions & 0 deletions examples/cloudpickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import cloudpickle
import io

# cloudpickle
pick = cloudpickle.dumps({'a': 'b', 'c': 'd'})
print(cloudpickle.loads(pick))

file_obj = io.BytesIO()
cloudpickle.dump([1, 2, '3'], file_obj)
file_obj.seek(0)
print(cloudpickle.load(file_obj))

file_obj.seek(0)
print(cloudpickle.Unpickler(file_obj).load())
8 changes: 8 additions & 0 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,14 @@ def test_dill(self):
}
self.check_example("dill.py", expect)

def test_cloudpickle(self):
"""Test for the `cloudpickle` module."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 1, "MEDIUM": 3, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 4},
}
self.check_example("cloudpickle.py", expect)

def test_shelve(self):
"""Test for the `shelve` module."""
expect = {
Expand Down