Add cloudpickle to pickle blacklists (B403/B301)#1462
Open
rayair250-droid wants to merge 1 commit into
Open
Conversation
cloudpickle extends pickle's serialization to arbitrary Python objects, so deserializing untrusted cloudpickle data is an arbitrary-code-execution risk, exactly like pickle/dill. bandit already flags pickle, cPickle, dill, shelve, jsonpickle and pandas.read_pickle but not cloudpickle. - B403: add 'cloudpickle' to the flagged imports. - B301: add cloudpickle.loads / cloudpickle.load / cloudpickle.Unpickler to the flagged calls. - Add examples/cloudpickle.py and a functional test mirroring the dill case (1 LOW import + 3 MEDIUM calls, all HIGH confidence). Closes PyCQA#1236.
rayair250-droid
requested review from
ericwb,
lukehinds and
sigmavirus24
as code owners
July 23, 2026 21:45
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1236.
What
cloudpickleextendspickleto serialize arbitrary Python objects (lambdas, closures, dynamically-defined classes). That makes deserializing untrusted cloudpickle data an arbitrary-code-execution risk, exactly likepickleanddill— but bandit's pickle blacklists didn't cover it, while they already coverpickle,cPickle,dill,shelve,jsonpickleandpandas.read_pickle.Changes
import_pickle): addcloudpickleto the flagged imports.pickle): addcloudpickle.loads,cloudpickle.load,cloudpickle.Unpicklerto the flagged calls.examples/cloudpickle.py(mirroringexamples/dill.py) and atest_cloudpicklefunctional test.Verification
Findings match the
dillcase exactly — 1 LOW import + 3 MEDIUM calls, all HIGH confidence.test_cloudpicklepasses and the full functional suite is green (80 passed) with no regressions.