fix: never unpickle binary request bodies unless explicitly asked - #20
Merged
Merged
Conversation
handle_binary_req now takes a keyword-only `loads` (bytes -> mapping of inputs) and raises at decoration time when it is not given. Unpickling is still available as an explicit opt-in, `loads=unsafe_pickle_loads`, for services whose clients are all trusted. The decoded body must be a mapping. Refs #18 (item 1, server side). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.
Addresses item 1 of #18 (server side).
What changes
handle_binary_req(func, *, loads): the body decoder is now a required keyword-only argument. Callinghandle_binary_req(func)raisesTypeErrorat decoration time with a message explaining why and how to opt in.unsafe_pickle_loads: the explicit, loudly named opt-in for services whose clients are all trusted (handle_binary_req(func, loads=unsafe_pickle_loads))._get_inputs_from_requestnever unpickles on its own; with no decoder it raises, and the decoded body must be a mapping.loads=pickle.loadsdirectly still works but emits a warning pointing atunsafe_pickle_loads.py2http/tests/test_binary_req.py, including an end-to-end check that a default service answers an octet-stream pickle body with an error and without unpickling it.Compatibility
Breaking only for code that called
handle_binary_req(func)without arguments. Fleet dependents of py2http (extrude, peruse) do not use it (checked by search); their test suites were run against this branch; the only failures are unrelated import errors (missing optional modules, stale internal names).send_binary_resp/binary_output(server pickling responses) are unchanged.Review
Independent refute-review by a sub-agent: no blockers. Applied: warning on bare
pickle.loads,Optionalannotation, explicit doctest+ELLIPSIS, tighter test assertions, end-to-end test, docstring note that http2py clients send pickle.Not in this PR
attr_names='*'dispatch) — left for a separate change.http2pystill unpickles binary responses and sends pickled binary requests; that belongs in the http2py repo.verifyvsverify_signature); separate follow-up.🤖 Generated with Claude Code