Repository navigation
Fix Cargo lock source look-alikes and two VEX remedies (#1933, #2045) - #2131
Conversation
Whether a Cargo.lock `source` is crates.io was decided in four places by three rules. `CargoLock::entries` used a substring test, so a source such as `sparse+https://index.crates.io.evil.example/` was recorded as crates.io and given a crates.io checksum verifier (#1933). `formats::cargo` now holds both rules. `is_crates_io_source` answers for a lock `source`: the git index behind `registry+` or the sparse index behind `sparse+`, compared as whole URLs the way cargo's `CanonicalUrl` does. `is_crates_io_patch_table` answers for a `[patch.<table>]` key: `crates-io` or the git-index URL, the only spellings cargo applies to crates.io (checked with cargo 1.98). It was a second `is_crates_io_source` in `vendor::cargo_manifest`. Two remedies `vex` prints for a vendored copy the build bypasses were wrong (#2045 items 2 and 3; item 1 was fixed by #2052): - `cargo update -p <crate>` and `cargo tree -i <crate>@<version>` are refused by cargo as ambiguous, because the lock also holds the copy at `<version>+socket.<uuid>` and cargo leaves build metadata out when it matches a spec. The commands now name the entry by its source, `"<index or repository URL>#<crate>@<version>"`. A source, name or version with a character a shell reads inside double quotes is not printed. - A stale entry locked from another registry was not recognised as stale when a `[patch]` table for that registry points at the copy, by its index URL or by the name the project config defines for it. The hosted override check keeps reading `[patch."sparse+https:// index.crates.io/"]` as a crates.io override, which is wider than cargo's reading and now says so. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
PR SummaryMedium Risk Overview VEX CLI contract documents the expanded Reviewed by Cursor Bugbot for commit 7acd65c. Configure here. |
|
[agent] PR shepherd: review brief for What it does: It adds one rule for "is this Cargo.lock Risk: Low. The changes make the checks stricter: look-alikes now fail closed with Look here
Verified
Changes I made: none. Open questions
Generated by Claude Code |
Closes #1933. Closes #2045 (item 1 was fixed by #2052; this fixes items 2 and 3).
Problems
A look-alike host was read as crates.io (#1933).
CargoLock::entriesdecided "is this lock entry from crates.io" by substring, sosource = "sparse+https://index.crates.io.evil.example/"gotSourceKind::CratesIoand a crates.io checksum verifier. Three other places answered the same question by other rules.The remedy
vexprinted for a bypassed vendored copy could not be run (#2045 item 2). It suggestedcargo update -p <crate>andcargo tree -i <crate>@<version>. The lock also holds the vendored copy at<version>+socket.<uuid>, and cargo leaves build metadata out when it matches a spec, so both commands fail:A stale entry from another registry got the wrong advice (#2045 item 3). With the copy wired under
[patch."https://my-corp.example/index"]and a stale lock entry from that registry,vexdid not see the entry as stale and sent the user tocargo tree -ifor a declaring dependency that may not exist.Fix
formats::cargo.is_crates_io_sourceanswers for a locksource: the git index behindregistry+, or the sparse index behindsparse+, compared as whole URLs the way cargo'sCanonicalUrldoes.CargoLock::entries, the vendored source refusal, the hosted override check and VEX discovery all call it.is_crates_io_patch_tableanswers for a[patch.<table>]key:crates-ioor the git-index URL. It was a second function namedis_crates_io_sourceinvendor::cargo_manifest; that module now re-exports it under the new name.cargo update -p "https://github.com/rust-lang/crates.io-index#cfg-if@1.0.4". The same spec is used in the hosted twin message, and the vendored revert warning now sayscargo update -p <crate>@<version>.[patch]table for that registry points at the copy, by the index URL or by the name the project's cargo config defines for it.Checked against real cargo (1.98.1)
cargo update -p cfg-if,cargo update -p cfg-if@1.0.4andcargo tree -i cfg-if@1.0.4are refused as ambiguous beside a1.0.4+socket.<uuid>copy. The source-qualified spec works for a crates.io entry and for a git entry.[patch]table patches crates.io undercrates-ioand under the git-index URL only. Under"sparse+https://index.crates.io/","https://index.crates.io/"or"registry+https://github.com/rust-lang/crates.io-index"cargo reports the patch as unused.sparse+included.Behaviour changes
vendorrefuses it withvendor_source_unsupported.vendorno longer refuses crates.io under a spelling cargo treats as the same source (a trailing/,.git, host case). It used to accept two exact strings.registry+https://index.crates.ioandsparse+https://github.com/rust-lang/crates.io-index(each index behind the other kind) are not crates.io.[patch]URL table with two trailing slashes is no longer a crates.io table (cargo drops one).Review
/code-review highreported nine findings. Fixed:.gitfrom the end of the whole URL, so the hostindex.crates.io.gitpassed, and it ignored the source kind. It now drops.gitfrom a repository URL only and checks the kind.sourceinto a command a user pastes. A source such asgit+https://…$(…)would run in the shell. The spec is printed only when the source, name and version consist of characters no shell reads inside double quotes. Otherwise the command takes the bare crate name, which cargo answers with the specs it accepts.entries, and a doc comment that claimed more than the git spec delivers.Not fixed:
routestill treats a registry name and its index URL as different sources. With the copy under[patch.my-corp], a member that declaresregistry-index = "<my-corp's URL>"is still reported as bypassing it. That withholds an attestation; it never grants one. Making the two equal changes whatvexattests, and I have not checked it against cargo with a real alternative registry.?reference. Two references of one repository at one version still share a spec. Cargo before 1.77 does not read thegit+…?branch=form, and the kind-less form works on every cargo.[patch."sparse+https://index.crates.io/"]is still refused as a crates.io override although cargo ignores it. The comment at the call says why: with the lock block sourceless, a pin beside the user's attempted override is refused, not guessed at.Testing
a_lock_source_is_crates_io_only_as_a_whole_urlanda_patch_table_is_crates_io_by_name_or_by_the_git_index_url: every spelling cargo reads as crates.io, and the look-alikes (a host or path that contains crates.io's,.giton a sparse host, either index behind the other kind, two trailing slashes).only_a_crates_io_entry_carries_the_crates_io_verifier: the inventory gives the look-alike sources no crates.io provenance.an_entry_of_another_registry_its_patch_table_redirects_is_stale: by index URL, by a name the project config defines, by a name it does not define, and a sparse index against its own table and against the git index's.a_lock_entry_spec_carries_the_source_cargo_compares: the spec for crates.io, another registry, a sparse index and git entries, and the sources, names and versions that are not printed.the_bypass_remedy_follows_its_evidencenow asserts the full commands.cargo test -p socket-patch-core --lib: 7,836 passed.e2e_vex_vendor,e2e_vex_redirect,e2e_vex_lockfile,vendor,in_process_vendor,in_process_redirect,mode_migration_cargo,hosted_memory_engine,scan: 1,195 passed.e2e_redirect_cargo_shapes(15),e2e_redirect_cargo_build(3),e2e_cargo(5) andin_process_cargo_apply(3) pass. Ine2e_vendor_cargo_build20 pass and 2 fail on my machine before they reach socket-patch: they run rustup's1.41.1-x86_64-apple-darwintoolchain, which this arm64 Mac no longer executes (Bad CPU type in executable).cargo fmt --checkandcargo clippy --locked --workspace --all-features -- -D warningsare clean.🤖 Generated with Claude Code