Skip to content

Warning and disambiguation of crates that are in both crates.io and alternative registries #9162

@kornelski

Description

@kornelski

The dependency confusion attack could exploit human error in editing of Cargo.toml. If a user wrote:

[dependencies]
company-internal-utils = "1"

when they've meant:

[dependencies]
company-internal-utils = { version = "1", registry = "internal" }

cargo build could end up fetching and running code from a wrong crate in the public crates.io registry.

I think this mistake could be detected by checking whether a dependency is in both internal and public crates.io registry. I'm not sure if Cargo could treat it as a hard error — that would be a breaking change, but at least it could warn about it.

Now, if Cargo detects such accidentally-from-crates.io dependencies as ambiguous, there needs to be a way to specify that a dependency was really meant to come from crates.io. For this I suggest supporting registry="crates.io", e.g.

[dependencies]
# Not an accident, I really mean the public one:
company-internal-utils = { version = "1", registry = "crates.io" } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-crate-dependenciesArea: [dependencies] of any kindA-registriesArea: registriesA-securityArea: securityC-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions