Skip to content

Security hardening: cargo install should warn when installing binaries that conflict with existing $PATH executables #15723

Open
@rlneumiller

Description

@rlneumiller

Problem

Summary:
When a binary is installed via cargo install, Cargo does not verify whether a binary with the same name already exists elsewhere in the $PATH. This can unintentionally shadow critical system tools or other software, introducing both usability problems and potential security risks.

Security Implications:

A malicious or misnamed crate could install a binary like ls or git, which, if ~/.cargo/bin appears early in the user’s $PATH, would silently override the expected system command.
This presents a software supply chain hazard, especially in CI environments or on shared systems.
Cargo’s current behavior provides no warning or audit mechanism, leaving users unaware of the change in behavior.

Proposed Solution

Proposed Feature: Add a pre-installation hook to cargo install that:

Scans the current $PATH for binaries with the same name
Warns (or optionally halts) if another binary exists outside of the install location (e.g., /usr/bin, /usr/local/bin)
Provides flags for:
--check-conflicts (opt-in stricter enforcement)
--no-conflict-check (to suppress warnings if intentionally overwriting)
Suggested Output Example:

⚠️ Warning: A binary named mytool already exists at /usr/local/bin/mytool.
Installing this crate may override or shadow an existing command in your $PATH.
Benefits:

Improves developer trust and visibility into installed tools
Helps prevent accidental or malicious shadowing of system binaries
Aligns with secure-by-default principles seen in other ecosystems
Related Issues:

Notes

cargo install should allow renaming installed binaries with --name
Improve cargo install --list to show more install metadata

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-feature-requestCategory: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`Command-installS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions