Skip to content

Add cloudpickle to pickle blacklists (B403/B301)#1462

Open
rayair250-droid wants to merge 1 commit into
PyCQA:mainfrom
rayair250-droid:feat/blacklist-cloudpickle
Open

Add cloudpickle to pickle blacklists (B403/B301)#1462
rayair250-droid wants to merge 1 commit into
PyCQA:mainfrom
rayair250-droid:feat/blacklist-cloudpickle

Conversation

@rayair250-droid

Copy link
Copy Markdown

Closes #1236.

What

cloudpickle extends pickle to serialize arbitrary Python objects (lambdas, closures, dynamically-defined classes). That makes deserializing untrusted cloudpickle data an arbitrary-code-execution risk, exactly like pickle and dill — but bandit's pickle blacklists didn't cover it, while they already cover pickle, cPickle, dill, shelve, jsonpickle and pandas.read_pickle.

Changes

  • B403 (import_pickle): add cloudpickle to the flagged imports.
  • B301 (pickle): add cloudpickle.loads, cloudpickle.load, cloudpickle.Unpickler to the flagged calls.
  • Updated both inline doc tables.
  • Added examples/cloudpickle.py (mirroring examples/dill.py) and a test_cloudpickle functional test.

Verification

$ bandit examples/cloudpickle.py
>> Issue: [B403:blacklist] ... cloudpickle module.   Severity: Low    Confidence: High
>> Issue: [B301:blacklist] Pickle and modules that wrap it ...   Severity: Medium Confidence: High   (x3)

Findings match the dill case exactly — 1 LOW import + 3 MEDIUM calls, all HIGH confidence. test_cloudpickle passes and the full functional suite is green (80 passed) with no regressions.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

blacklist cloudpickle in pickle blacklist

1 participant