Skip to content

Commit

Permalink
add jsonpickle deserialization blacklist (#707)
Browse files Browse the repository at this point in the history
* add jsonpickle deserialization blacklist

add jsonpickle deserialization blacklist

* Update calls.py

* Update test_functional.py

* Create jsonpickle.py

Co-authored-by: Eric Brown <ericwb@users.noreply.github.com>
  • Loading branch information
SugarP1g and ericwb committed Jul 7, 2022
1 parent 5aae21e commit 9832461
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
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

0 comments on commit 9832461

Please sign in to comment.