Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add jsonpickle deserialization blacklist #707

Merged
merged 5 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 @@ -32,6 +32,9 @@
| | | - dill.Unpickler | |
| | | - shelve.open | |
| | | - shelve.DbfilenameShelf | |
| | | - jsonpickle.decode | |
| | | - jsonpickle.unpickler.decode | |
| | | - jsonpickle.unpickler.Unpickler | |
+------+---------------------+------------------------------------+-----------+

B302: marshal
Expand Down Expand Up @@ -352,6 +355,9 @@ def gen_blacklist():
"dill.Unpickler",
"shelve.open",
"shelve.DbfilenameShelf",
"jsonpickle.decode",
"jsonpickle.unpickler.decode",
"jsonpickle.unpickler.Unpickler",
],
"Pickle and modules that wrap it can be unsafe when used to "
"deserialize untrusted data, possible security issue.",
Expand Down
10 changes: 10 additions & 0 deletions examples/jsonpickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import jsonpickle


pick = jsonpickle.encode({'a': 'b', 'c': 'd'})

print(jsonpickle.decode(pick))

print(jsonpickle.unpickler.decode(pick))

print(jsonpickle.unpickler.Unpickler().restore(pick))
8 changes: 8 additions & 0 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,14 @@ def test_shelve(self):
}
self.check_example("shelve_open.py", expect)

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

def test_popen_wrappers(self):
"""Test the `popen2` and `commands` modules."""
expect = {
Expand Down