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

Blacklist pandas read_pickle and add functional test for it #710

Merged
merged 6 commits into from
Jul 8, 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
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