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 2 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
4 changes: 3 additions & 1 deletion bandit/blacklists/calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
| | | - dill.Unpickler | |
| | | - shelve.open | |
| | | - shelve.DbfilenameShelf | |
| | | - pandas.read_pickle | |
+------+---------------------+------------------------------------+-----------+

B302: marshal
Expand Down Expand Up @@ -341,7 +342,8 @@ def gen_blacklist():
'dill.load',
'dill.Unpickler',
'shelve.open',
'shelve.DbfilenameShelf'],
'shelve.DbfilenameShelf',
'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))
1 change: 1 addition & 0 deletions test-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ testscenarios>=0.5.0 # Apache-2.0/BSD
testtools>=2.3.0 # MIT
beautifulsoup4>=4.8.0 # MIT
pylint==1.9.4 # GPLv2
pandas==1.2.4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't necessary as the python example is not actually compiled or run. We only run the AST parser on it to detect security issues.

ericwb marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 9 additions & 0 deletions tests/functional/test_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,3 +790,12 @@ def test_no_blacklist_pycryptodome(self):
'CONFIDENCE': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 0, 'HIGH': 0}
}
self.check_example('pycryptodome.py', expect)

def test_blacklist_pandas_read_pickle(self):
'''
Test whether the pandas read pickle is appropriately blacklisted
'''
expect = {
'SEVERITY': {'UNDEFINED': 0, 'LOW': 0, 'MEDIUM': 1, 'HIGH': 0}
}
self.check_example('pandas_read_pickle.py', expect)