elijahbenizzy opened a new pull request, #818:
URL: https://github.com/apache/burr/pull/818

   ## Summary
   
   Adds an optional allowlist to the pickle deserializer used by Burr's serde 
system (`burr/integrations/serde/pickle.py`), mirroring the shape of #794's 
pydantic allowlist work.
   
   Without an allowlist: backward-compatible — `deserialize_pickle` continues 
to call `pickle.loads(...)` and emits a one-time `SecurityWarning` per 
registration site so users see the noise.
   
   With an allowlist: a `_RestrictedUnpickler(pickle.Unpickler)` subclass 
overrides `find_class(module, name)` to validate against the allowlist and 
raises `pickle.UnpicklingError` for anything not on it.
   
   ## API
   
   Three ways to set the allowlist, in resolution order (highest priority 
first):
   
   1. Per-call kwarg: `deserialize_pickle(value, allowlist=[...])`
   2. At registration time: `register_type_to_pickle(cls, allowlist=[...])`
   3. Process-wide: `set_pickle_serde_allowlist([...])`
   4. Otherwise: legacy unsafe path + `SecurityWarning`
   
   Allowlist entries are `(module, qualname)` tuples — e.g. `("myapp.models", 
"User")` — rather than prefix strings. Pickle attacks routinely reach for 
*specific symbols within otherwise-trusted modules* (e.g. `builtins.eval`, 
`os.system`, `subprocess.Popen`), so per-class granularity matters more than 
for pydantic where the registered name is already a class.
   
   ## Trust model (now in the docstring)
   
   Pickle deserialization is unsafe when the bytes come from a source the 
application doesn't fully control — including persistence backends that have a 
separate access model (SQLite files, Redis, S3, filesystems). An attacker with 
write access to the backend can plant a malicious `__reduce__` payload that 
triggers code execution when state is loaded. The allowlist closes that 
primitive.
   
   ## Tests
   
   8 tests in `tests/integrations/serde/test_pickle.py` (was 1):
   
   - `_is_allowed` truth table for allowlist matching
   - Malicious `__reduce__` payload (calling a sentinel function via 
`__reduce__`) is blocked when an allowlist is set; sentinel never runs
   - Legitimate object roundtrips when its `(module, qualname)` is on the 
allowlist
   - Module-level `set_pickle_serde_allowlist` applies to fresh registrations
   - Instance-level allowlist (at `register_type_to_pickle`) overrides module 
default
   - Per-call allowlist kwarg overrides both
   - Legacy path (no allowlist) still works and emits the `SecurityWarning` 
exactly once per registration site
   
   Wider `tests/integrations/serde/` + `tests/core/test_serde.py` runs 24/24 
green.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to