Skip to content

fix(cargo): fail crates.io lookups where configuration replaces crates.io - #174

Merged
sweepies merged 4 commits into
mainfrom
feat/cargo-origins
Nov 4, 2026
Merged

sweepies merged 4 commits into
mainfrom
feat/cargo-origins

Conversation

@sweepies

@sweepies sweepies commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

Fifth per-ecosystem fix from the registry audit, after Bundler (#168), Composer (#170), NuGet (#171) and Maven/Gradle (#173).

Why Cargo needs little

Cargo takes a crate only from the registry its dependency names: no registry key means crates.io, and Cargo never searches several registries. Alternate-registry, git and path dependencies were already listed as skipped. So the one gap is source replacement. A repository's .cargo/config.toml can replace crates.io with another source. Cargo then fetches every unnamed crate from it, while Cargo.lock still records registry+https://github.com/rust-lang/crates.io-index, so the lock can't tell.

The rule

  • A .cargo/config.toml or .cargo/config in the crate's folder or above that replaces crates.io fails that crate's crates.io lookups, for the manifest and for locked crates in its Cargo.lock.
  • Fine: a vendored directory source (what cargo vendor sets up), since it holds copies of crates.io's crates.
  • Fails: a registry, local registry or git source, or a chain the repository doesn't define (e.g. in $CARGO_HOME).
  • Over-counted: every definition of a source in any configuration that applies counts, so a definition a closer configuration overrides can only make lookups fail.
  • Fails closed: an unreadable or invalid configuration, and a symlinked .cargo folder, which counts as unreadable.

Renovate does the same in spirit: it follows replace-with and skips a crate whose registry it can't resolve.

Also fails closed

  • A configuration that includes others, or that the Count cannot read.
  • Any [patch] or [replace] entry taking a crate from another registry, in the crate's manifest, any manifest above it, or an applying configuration. It fails every crates.io lookup there, since it can stand for any crate under any name Cargo accepts for it. Manifests above a crate's are read in a follow-up pass, whatever exclude says.
  • Configurations anywhere in the crate's workspace count, since Cargo reads them from wherever it runs.

Follow-ups

  • Configuration outside the repository ($CARGO_HOME, --config or CARGO_* variables in CI) isn't seen.

View guided diff Turn on auto-fix

  • Workspace members outside the root's folder (members = ["../x"], package.workspace) aren't tied to their root.

…s.io

Cargo only takes a crate from the registry its dependency names, so
crates.io lookups were safe, except where a repository's Cargo
configuration replaces crates.io with another source: Cargo then takes
every unnamed crate from there, and Cargo.lock still records crates.io.

A .cargo/config.toml or .cargo/config in the crate's folder or above that
replaces crates.io with anything but a vendored directory source, or a
chain the repository does not define, now fails the crates.io lookups of
the manifests and lockfiles below it. Every definition of a source in any
applying configuration counts, so one a closer configuration overrides
only makes lookups fail. An unreadable configuration fails them too, and
a symlinked .cargo folder is unreadable.
@deepsource-io

deepsource-io Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

DeepSource Code Review

We reviewed changes in b87af2d...ddadaf9 on this pull request. Below is the summary for the review, and you can see the individual issues we found as inline review comments.

See full review on DeepSource ↗

PR Report Card

Overall Grade   Security  

Reliability  

Complexity  

Hygiene  

Code Review Summary

Analyzer Status Updated (UTC) Details
Rust Nov 4, 2026 3:27a.m. Review ↗
JavaScript Nov 4, 2026 3:27a.m. Review ↗
Shell Nov 4, 2026 3:27a.m. Review ↗

Important

AI Review is run only on demand for your team. We're only showing results of static analysis review right now. To trigger AI Review, comment @deepsourcebot review on this thread.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
count-patchula 877b8af Commit Preview URL

Branch Preview URL
Nov 04 2026, 03:24 AM

@context7

context7 Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Docs7 for sweepies/count-patchula

Result Status Action
Deployment ➖ Not used —
Content review ➖ Did not run. This site has no agent runs available this month. Wait for the monthly reset or check your Docs7 plan. —

Commit ddadaf9

- A configuration that includes others is not read, so it fails.
- A crate a [patch.crates-io] or [replace] entry takes from another
  registry, in the manifest, its workspace's or a configuration, fails
  its lookup; a git or path patch keeps crates.io's crate.
- A registry-index dependency is skipped like an alternate registry,
  without repeating the index URL.
- Configurations anywhere in the crate's workspace apply, since Cargo
  reads them from wherever it runs.
- A symlinked settings folder in a working tree is unreadable whenever
  its target exists, so a .cargo with only the legacy config is caught.
Matching patched crates by name kept missing forms Cargo accepts (patch
tables keyed by index URL, name@version replace keys, - and _ spelt
interchangeably). Any [patch] or [replace] entry from another registry,
in the crate's manifest, any manifest above it or an applying
configuration, now fails every crates.io lookup there, locked crates
included.

Manifests above a crate's are read in a follow-up pass whatever exclude
says, so a workspace root's patches are always seen; one that cannot be
read fails closed instead of breaking extraction. Results are cached per
lockfile.
- The manifest beside a lockfile is fetched in the follow-up pass too, so
  a lockfile selected without its manifest still sees its patches.
- Only manifests and lockfiles Cargo's selection takes are parsed for
  extraction: one fetched only for its patches no longer supplies
  workspace dependencies to members, and one that does not parse fails
  its crates' lookups rather than the whole scan.
@sweepies
sweepies merged commit fe598fc into main Nov 4, 2026
15 checks passed
@sweepies
sweepies deleted the feat/cargo-origins branch November 4, 2026 03:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant