Skip to content

Commit

Permalink
Blacklist pandas read_pickle and add functional test for it (#710)
Browse files Browse the repository at this point in the history
* Blacklist pandas read_pickle and add functional test for it

* Update test-requirements.txt

* Update test_functional.py

* Update test_functional.py

Co-authored-by: Jasper Sival <jasper.sival@rabobank.com>
Co-authored-by: Eric Brown <ericwb@users.noreply.github.com>
  • Loading branch information
3 people committed Jul 8, 2022
1 parent f909a7d commit 128b236
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
2 changes: 2 additions & 0 deletions bandit/blacklists/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
| | | - jsonpickle.decode | |
| | | - jsonpickle.unpickler.decode | |
| | | - jsonpickle.unpickler.Unpickler | |
| | | - pandas.read_pickle | |
+------+---------------------+------------------------------------+-----------+
B302: marshal
Expand Down Expand Up @@ -358,6 +359,7 @@ def gen_blacklist():
"jsonpickle.decode",
"jsonpickle.unpickler.decode",
"jsonpickle.unpickler.Unpickler",
"pandas.read_pickle",
],
"Pickle and modules that wrap it can be unsafe when used to "
"deserialize untrusted data, possible security issue.",
Expand Down
12 changes: 12 additions & 0 deletions examples/pandas_read_pickle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pickle
import pandas as pd


df = pd.DataFrame(
{
"col_A": [1, 2]
}
)
pick = pickle.dumps(df)

print(pd.read_pickle(pick))
8 changes: 8 additions & 0 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,14 @@ def test_jsonpickle(self):
}
self.check_example("jsonpickle.py", expect)

def test_pandas_read_pickle(self):
"""Test for the `pandas.read_pickle` module."""
expect = {
"SEVERITY": {"UNDEFINED": 0, "LOW": 1, "MEDIUM": 1, "HIGH": 0},
"CONFIDENCE": {"UNDEFINED": 0, "LOW": 0, "MEDIUM": 0, "HIGH": 2},
}
self.check_example("pandas_read_pickle.py", expect)

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

0 comments on commit 128b236

Please sign in to comment.