Skip to content

fix(sessions): prevent BUILD opcode from mutating allowlisted classes in _restricted_pickle - #8385

Open
amirulian wants to merge 1 commit into
google:mainfrom
amirulian:fix-restricted-pickle-class-build
Open

amirulian wants to merge 1 commit into
google:mainfrom
amirulian:fix-restricted-pickle-class-build

Conversation

@amirulian

Copy link
Copy Markdown

Summary

  • _RestrictedUnpickler.find_class() returns live class objects for allowlisted globals (such as pathlib.PurePosixPath, uuid.UUID, collections.OrderedDict, etc.).
  • Because classes without __setstate__ fall back to setattr(target, key, value) when the pickle BUILD (b) opcode is executed with a (None, slot_state) tuple, a crafted legacy session pickle payload could apply BUILD directly to an allowlisted class object on the stack and overwrite its methods/attributes in-process.
  • Subclass pickle._Unpickler and override load_build to raise pickle.UnpicklingError whenever BUILD targets a class object (isinstance(self.stack[-2], type)).

Testing Plan

  • Added test_build_opcode_cannot_mutate_allowlisted_class_attributes in tests/unittests/sessions/test_dynamic_pickle_type.py.
  • Ran pytest tests/unittests/sessions/test_dynamic_pickle_type.py (50 passed).

@google-cla

google-cla Bot commented Nov 27, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

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.

1 participant