Repository navigation
Match the patch mirror by its base in the Pipenv, script and Hatch rewriters and the vendored Pipenv backend - #2255
Conversation
…writers and in the vendored Pipenv backend Two gaps left by the experimental patch mirror (#2180): - The Pipenv, pyproject / inline-script (PEP 723) and Hatch rewriters take over an earlier hosted pin in place when it is in the patch server's path shape for the same release, on Socket's patch server or on the grant's own origin. Under a mirror the grant's origin is an artifact host that serves the project's own packages too, so a URL in that shape in another repository of the host was rotated as if it were ours. A pin on the grant's origin now also has to sit under the base the grant is served from (origin::same_hosted_base, the rule the yarn berry, Bun, Poetry and PDM rewriters already apply). A pin on Socket's patch server is still ours and still moves onto the mirror in place. - The vendored Pipenv backend built its patch-server origins from --patch-server-url only, while the hosted-to-vendored takeover and the scan / get preview read the run's full list, the mirror's base included. VendorServiceConfig now carries that list (patch_server_origins, built by hosted_unwind::patch_server_origins), so the backend's guard names a live pin under the mirror's base as a hosted pin with the rollback remedy, and still calls a pin elsewhere on the mirror's host user-declared. The takeover itself already restored a mirrored Pipenv pin before the backend ran; a test now holds that. Tests: unit tests for replaceable_hosted_pin, the Pipenv rewriter, the pyproject / inline-script rewriter, the Hatch rewriter and the vendored Pipenv guard, and three CLI tests in mode_migration_pypi (hosted fork left alone, mirrored Pipenv takeover, vendor leaves a fork alone). Each new unit test and the hosted fork test fail with the source change reverted. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e comment - CLI_CONTRACT names the uv.lock / pylock.toml direct-URL takeover, which asks the same shared question, and the pyproject / script rewriters' second rule (the same URL with only the grant token rotated). - The Pipenv rewriter's owned_url comment says a pin on the grant's host is ours only under the base the grant is served from. - The script test also checks same_hosted_artifact directly, the check the uv.lock / pylock takeover calls. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
PR SummaryMedium Risk Overview
Reviewed by Cursor Bugbot for commit c4a4592. Configure here. |
Wenxin Jiang (Wenxin-Jiang)
left a comment
There was a problem hiding this comment.
[agent] Reviewed the base-path matching rule and the origin list given to the vendored Pipenv backend. A sibling repository, a socket-patch-2 sibling and .. escapes are all refused, and a root-served patch server behaves as before. No findings.
What this fixes
The experimental patch mirror (#2180,
--patch-mirror-url/SOCKET_PATCH_MIRROR_URL) left two items under "Not covered". Both are about matching a mirror by its full base URL (origin plus path), never by its host alone, which is how every other hosted reader already matches it.1. The Pipenv, inline-script and Hatch rewriters matched an earlier mirror pin by host
These rewriters take over an earlier hosted pin in place when it is in the patch server's path shape for the same release, on Socket's patch server or on the grant's own origin (
replaceable_hosted_pin). With a mirror, the grant's origin is an artifact host that also serves the project's own packages. So a URL in that shape in another repository of the host was rotated as if it were ours.Now a pin on the grant's origin must also sit under the base the grant is served from (
origin::same_hosted_base). That is the rule the yarn berry, Bun, Poetry and PDM rewriters already apply. URLs are compared parsed, so<base>/../other/...and%2e%2edo not count as under the base.A pin on Socket's patch server is still ours and still moves onto the mirror in place, so Pipenv's behavior for a project pinned directly on the patch server does not change.
The rule is shared, so the fix covers:
Pipfile.lock(redirect::pipenv)pyproject.toml[tool.uv.sources]and PEP 723 inline scripts (python_script::same_hosted_artifact)utils::hatch)2. The vendored Pipenv backend built its hosted origins from
--patch-server-urlonlyvendor_pypi_with_pipenv_versionbuilt its patch-server origins from--patch-server-urlalone. The hosted-to-vendored takeover and thescan/get --mode vendoredpreview already used the run's full list, with the mirror's base included.VendorServiceConfignow has apatch_server_originsfield. It is set fromhosted_unwind::patch_server_origins, which lists the mirror asmirror+<base>. The backend reads it, so:rollbackremedy;Not reproducible end to end on
main. The "refused" in #2180's note did not reproduce through the CLI. Onmain, the per-package takeover already restores a mirroredPipfile.lockentry before the backend runs.vendor,scan --mode vendoredandget --mode vendoredwith only the mirror set all vendor such a project. The backend's origin list only decided which refusal message a live pin got. This PR fixes that list and adds a CLI test that holds the takeover in place.CLI_CONTRACT.md's patch-mirror section now names the Pipenv, pyproject / inline-script and Hatch rewriters next to yarn berry, Bun, Poetry and PDM.Behavior change outside the mirror
A path-prefixed
--patch-server-urldeployment (https://host/prefix/patch/pypi/...) now has these three rewriters take over an earlier pin only under that same prefix. Before, any path on that host counted. That is how the yarn berry, Bun, Poetry and PDM rewriters already treat such a deployment. A pin on Socket's patch server, or on a--patch-server-urlserved from the root of its host, is matched as before.Tests
Unit tests (core):
replaceable_hosted_pin_under_a_mirror_needs_the_mirror_baseowned_url_under_a_mirror_needs_the_mirror_base(Pipenv, throughplan)an_earlier_source_under_a_mirror_needs_the_mirror_base(pyproject and inline script)an_earlier_reference_under_a_mirror_needs_the_mirror_base(Hatch)pipenv_guard_reads_a_mirrored_pin_as_hosted_only_under_the_mirror_base(vendored backend)Each one is checked both ways:
<base>/../other/....All five fail with the source change reverted.
CLI tests in
tests/mode_migration_pypi.rs:pipenv_hosted_through_a_mirror_leaves_a_fork_on_its_host_alone: a hosted run through a mirror refuses a same-shapedPipfile.lockpin in another repository (redirect_pipenv_refused) and leaves the lock byte-identical. It fails onmain.pipenv_hosted_through_a_mirror_to_vendored: hosted through the mirror, thenvendor --patch-mirror-urlonly, ends wired to the vendored wheel.pipenv_vendor_leaves_a_pin_elsewhere_on_the_mirrors_host_alone:vendorrefuses a fork in another repository as user-declared and leaves the lock as it was.Local runs on the head commit:
cargo clippy --locked --workspace --all-features -- -D warnings: clean.cargo check --workspace --all-targets --all-features: clean, apart from two unused-import warnings already onmainin test files this PR does not touch.mode_migration_pypi(87),patch_mirror(5),in_process_redirect_pipenv(11),in_process_vendor(157),in_process_vendor_pypi_takeover(9),command_module_layering(4) andcli_global_args(13), all passed.Code review
/code-review highreturned five findings. Three are fixed in the second commit:pylock.tomldirect-URL takeover asks the same shared question, so the contract now names it. It also states the second rule the pyproject / script rewriters apply: the same URL with only the grant token rotated. The script test also checkssame_hosted_artifactdirectly, which is the check the lock takeover calls.owned_url's doc comment still said any pin on the grant's host counts.Two are not fixed:
--patch-server-urlpin is not moved onto a mirror (marked pre-existing). The scenario: a Pipenv or script pin on the operator's own patch server, then a run that adds--patch-mirror-url. That pin is refused, while a pin on patch.socket.dev is moved. This was already the behavior before this PR: the old check only accepted Socket's host or the grant's origin, and the grant is on the mirror. Fixing it means passing the run's configured origins into the rewriters, which take only the grant's URL today. That is a separate change;rollbackand a re-run is the remedy.same_hosted_basecompares percent-encoded paths as text, sosocket%2Dpatchandsocket-patchcount as different bases. The check is shared with the yarn berry, Bun, Poetry and PDM rewriters, and the run writes every mirrored pin with the operator's base byte for byte. A base given in two spellings is not a case worth changing that shared check for here.No
CHANGELOG.mdentry, per the repository rule.🤖 Generated with Claude Code