Restrict refresh_remote to bounded HTTP(S) fetches#265
Merged
Conversation
refresh_remote passed the caller URL straight to urllib and buffered the whole response, so a file:// or ftp:// URL was silently accepted and a hostile/misbehaving policy server could stream unbounded data into memory before validation. Reject non-HTTP(S) schemes up front and cap the response body at 1 MiB. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DDSofWX5HwawsrwbN2nSXR
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.
Issue
policy.refresh_remoteis documented (API.md) as fetching policy YAML over HTTP, but it passed the caller-supplied URL straight tourllib.request.urlopenand read the response with an unboundedfh.read():file://andftp://URLs, so a mis-plumbed URL silently turns the policy fetch into a local-file read primitive.Fix
http/httpswith aValueErrorbefore opening the connection._MAX_REMOTE_POLICY_BYTES(1 MiB — generous for YAML policy documents) and raiseValueErrorwhen exceeded.Existing behavior is otherwise unchanged: timeout retries, temp-file handling, and the
refresh()pipeline are untouched.Testing
test_refresh_remote_rejects_non_http_scheme(afile://URL raises before any fetch) andtest_refresh_remote_rejects_oversized_response(a local HTTP server serving 1 MiB + 1 gets rejected).Note: while adding these tests I found that
tests/test_remote_policy.pyfails when run as a standalone file on currentmain— two pre-existing tests depend on an earlier test file leaving the global policy token set. That's unrelated to this change; fix coming in a separate PR.🤖 Generated with Claude Code
https://claude.ai/code/session_01DDSofWX5HwawsrwbN2nSXR
Generated by Claude Code