Expand description
.cargo/config.toml discovery and [registries.*]/[source.*] resolution.
Resolves a Cargo registry = "<alias>" dependency’s alias into a concrete, fetchable
sparse index URL by reading the same .cargo/config.toml hierarchy (and
$CARGO_HOME/config.toml) Cargo itself consults, plus the
CARGO_REGISTRIES_<NAME>_INDEX/_TOKEN environment variable overrides Cargo
documents. Also resolves a [source.crates-io] replace-with chain into a mirror index
for plain (Registry-sourced) dependencies (spec FR-005/006/007).
§Security model (read before touching this module)
A workspace’s own Cargo.toml/.cargo/config.toml is attacker-controlled the moment a
hostile repository is cloned and opened — this LSP parses on file open, before any build
ever runs. Two, related, threats this module closes:
- Credential exfiltration.
AuthTokenmust never be attachable to a request whose destination URL provenance traces to a workspace file. This is enforced structurally, not by a runtime check:parse_workspace_registries_rawhas no return type capable of expressing a token — its value type is a bareString, with no token field anywhere. There is notokenfield lookup anywhere in that function’s body.- Only
parse_cargo_home_registries_raw(fed$CARGO_HOME/config.toml’s content) and the environment-variable lookup inresolveever constructSome(AuthToken). Provenanceexists purely for logging/diagnostics. Nothing in this crate branches on it to decide whether to attach a credential — grepping forProvenanceoutside this module should find no such branch (verified in this PR’s security review).
- Internal-network reachability (SSRF-adjacent, #443).
RegistryIndex::newrequires anIndexTrustand adeps_core::net_policy::RegistryAccessPolicy: aWorkspaceDeclaredURL is checked against the live policy before it can ever become a fetchable index, while aTrusted($CARGO_HOME-provenance) URL is never policy-checked at all — it is the user’s own configuration, not something a cloned repository controls. See.local/specs/023-cargo-custom-registries/plan-1b.md§1-§2.
See spec .local/specs/023-cargo-custom-registries/spec.md FR-008/FR-009 and the design
review handoffs cited there for the two rounds of critique the credential boundary
survived.
Structs§
- Auth
Token - A registry bearer-token credential, redacted everywhere except the one call site that
formats it into an
Authorizationheader. - Cargo
Config - The merged, resolved view of a workspace’s
.cargo/config.tomlhierarchy plus$CARGO_HOME/config.toml, for the aliases a manifest actually referenced. - Config
File Cache - Per-config-file memoization for
.cargo/config.toml/$CARGO_HOME/config.tomlparsing (spec NFR-005, plan-1b §1.5). - Registry
Index - A validated,
sparse+-prefix-stripped sparse-index URL:httpsscheme, no userinfo, and (for aWorkspaceDeclaredcandidate) a host the livedeps_core::net_policy::RegistryAccessPolicyallows. - Resolved
Registry Entry - One resolved
[registries.<name>]entry.
Enums§
- Index
Trust - Whose input a candidate registry index URL is, for
RegistryIndex::new’sdeps_core::net_policy::RegistryAccessPolicygate. - Provenance
- Where a
ResolvedRegistryEntrycame from. - Registry
Index Error - Why a candidate index URL failed
RegistryIndex::new’s validation. - Source
Replacement - Where a
[source.crates-io] replace-withchain resolved to, for plain (Registry-sourced) dependencies (spec FR-005/FR-006/FR-007).
Functions§
- cargo_
home_ config_ path $CARGO_HOME/config.toml’s path, orNoneif$CARGO_HOMEis not set.- referenced_
aliases - Every distinct alias
dependenciesdeclares viaregistry = "<alias>". - resolve
- Resolves
referenced_aliasesagainst the.cargo/config.tomlhierarchy and$CARGO_HOME/config.toml.