Security: Remediation of RCE via Insecure Pickle Deserialization in Model I/O#667
Open
JoshuaProvoste wants to merge 1 commit intogoogle:mainfrom
Open
Security: Remediation of RCE via Insecure Pickle Deserialization in Model I/O#667JoshuaProvoste wants to merge 1 commit intogoogle:mainfrom
JoshuaProvoste wants to merge 1 commit intogoogle:mainfrom
Conversation
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.
Compliance with CONTRIBUTING.md:
Consistently with the project guidelines, this PR includes:
brax/io/model_test.pyto validate core security logic and prevent regressions.__reduce__payload and verified its neutralization by the new security gate.isortandpyinkacross all modified files.Description
This PR addresses a critical security vulnerability in the parameter I/O system (
brax.io.model). The current implementation relies onpicklefor deserialization, which is inherently insecure as it allows the execution of arbitrary Python code during the loading process (Remote Code Execution - RCE).To remediate this, I have transitioned the framework to use Msgpack, a data-only binary serialization format. This move aligns Brax with modern industry standards for machine learning security—similar to the transition from Pickle to
safetensorsin the Transformers ecosystem—moving the project from a "vulnerable by design" state to a "secure by default" architecture.Key Benefits:
.pklfiles are blocked by default, requiring user consent (allow_pickle=True) and triggering aSecurityWarning.RunningStatisticsState).Technical Implementation Details
_encode_pytreeand_decode_pytreefor recursive, type-preserving serialization.0x80) to theload_paramsbuffer to identify and intercept legacy Pickle headers.SecurityWarningcategory for transparent but secure backward compatibility.testNetworkEncodingfunction in all training agent suites (ppo,sac,bc,apg,es,ars) to utilize the new securemodelAPI..pklfiles.Verification Performed
.pklfile could execute system commands when loaded via the originalload_params.RuntimeError.np.testing.assert_allclose).isortandpyinkon all 8 modified files.Checklist