Security/safe pickle loader #460
Open
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.
Overview
This PR eliminates the only medium-severity Bandit findings in the code-base by introducing a restricted-capability pickle loader and replacing import-time
pickle.load/loads
calls.Motivation
The repo ships
.pickle
files that are deserialized at import time.Unrestricted
pickle.load
can execute arbitrary code if the file is ever tampered with (CWE-502). While the pickles are trusted in normal use, hardening this path removes a potential supply-chain attack vector.Key Changes
src/alphafold3/common/safe_pickle.py
safe_load
using a customUnpickler
that only allows harmless built-in container / primitive types (dict
,list
,tuple
,str
,int
, etc.).pickle.UnpicklingError
.Replaced unsafe loads
constants/chemical_component_sets.py
constants/chemical_components.py
constants/converters/chemical_component_sets_gen.py
These modules now read their pickle files via
safe_pickle.safe_load
.Security scan result
No medium or high findings remain; low-severity items are stylistic.
Testing
python -m py_compile
on all modified files => passes..pickle
files present – loads cleanly.safe_pickle.safe_load
:datetime.datetime
withUnpicklingError
.Impact
Checklist