Fix Cargo hosted workspace redirects - #256
Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
Open
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
Mikola Lysenko (mikolalysenko) wants to merge 3 commits into
Conversation
Resolve inherited dependency aliases through their workspace definitions and match local lockfile owners by both package name and version. This allows valid workspace patches while refusing consumers outside the editable project. Read quoted dependency values and annotated registry tables consistently so repeated application cannot leave an alias unpatched or create an invalid duplicate TOML table. Validated with 70 Cargo redirect unit tests and real service-backed hosted, vendored service, and vendored build installs using fresh Cargo caches, locked offline builds, integrity rejection, and revert. Assisted-by: Codex:gpt-6-astra
Validate planned dependency pins against parsed TOML before writing any files. Legal root and target dotted or inline declarations that the source-preserving editor cannot rewrite now refuse the entire patch instead of leaving a mixture of original and patched sources. Validate unchanged member manifests too, while preserving workspace inheritance and declarations for other package versions. Malformed TOML is refused without changing the project. Validated with 73 Cargo unit tests and the real converter/API/CLI matrix, including an actual Cargo build proving the dotted manifest is valid and remains byte-identical after refusal. Assisted-by: Codex:gpt-6-astra
Wenxin Jiang (Wenxin-Jiang)
approved these changes
Sep 25, 2026
Collaborator
Author
|
Claude (@claude) review |
Collaborator
Author
|
BugBot review |
Combine identical refusal branches for dotted dependencies without changing which declarations are refused. Full workspace Clippy and all 73 Cargo redirect tests pass. Assisted-by: Codex:gpt-6-astra
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit a156d87. Configure here.
This branch has not been deployed
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.
LLM Description written by Codex:gpt-6-astra
Hosted Cargo patches incorrectly reject workspace-inherited dependency aliases and can mistake an editable local package for a different version outside the project. Quoted dependency values and annotated registry tables also bypass parts of the rewriter, leaving declarations unpatched or producing duplicate TOML tables on reruns.
Root Cause
Workspace references were filtered by their local alias before resolving the root definition. The lockfile ownership guard compared only package names. Several source-preserving TOML readers recognized fewer valid string and table-header forms than Cargo accepts.
Fix
Testing
cargo build --locked -p socket-patch-cli.cargo clippy --workspace --all-features -- -D warnings.Public Changelog
Hosted Cargo patches now handle inherited workspace aliases and annotated registry configuration correctly, and safely refuse dependencies outside the editable project.
Checklist
Companion to SocketDev/depscan#26792. Based on the current main commit
2390c5ff784d2a0fbca5fd13f9dff83752b7615a.Note
Medium Risk
Changes core Cargo.toml/Cargo.lock rewrite logic for hosted patches; mistakes could block valid redirects or still miss edge-case declarations, but failures are fail-closed with warnings rather than silent partial writes.
Overview
Hosted Cargo registry redirects are tightened so workspace aliases, lockfile ownership, and TOML edge cases no longer produce partial or wrong pins.
After
plan_cargo_toml, a newvalidate_cargo_toml_pinspass parses the planned manifest and refuses the whole dependency if any matching declaration (root dotted forms,target.*,workspace.dependencies, workspace-inherited keys) is still unpinned—replacing behavior that could skip garbage lines and leave a partial redirect.Workspace inheritance is resolved by alias/key before deciding whether an entry targets the patched crate (
CargoWorkspaceEntry::OtherPackage,NeedsWorkspacePinforworkspace = truein table blocks). Lock transitive checks now treat “pinned” local packages as (name, version) viacargo_manifest_package_id, including workspace-inherited versions and Cargo’s default0.0.0.TOML handling moves from narrow regexes to
toml_edit-based string/inline parsing for registry pins, renames, and.cargo/configregistry blocks (quoted headers, single-quoted values, comments). Malformed manifests that fail validation now emitredirect_cargo_toml_dep_unrewritableinstead of best-effort partial rewrites.Extensive regression tests cover partial-redirect refusal, renamed workspace deps, literal-string forms, and name+version lock matching.
Reviewed by Cursor Bugbot for commit a156d87. Configure here.