Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustup configure an insecure PATH by default. #2922

Open
sha0coder opened this issue Dec 9, 2021 · 6 comments
Open

rustup configure an insecure PATH by default. #2922

sha0coder opened this issue Dec 9, 2021 · 6 comments

Comments

@sha0coder
Copy link

Problem

Configuring the cargo path in the first section of the $PATH creates an extra insecurity on the system, as the comment says it's overriding the system binaries.
It would be more secure to put the "$HOME/.cargo/bin" at last section of the $PATH.

.cargo$ cat env
#!/bin/sh
# rustup shell setup
# affix colons on either side of $PATH to simplify matching
case ":${PATH}:" in
    *:"$HOME/.cargo/bin":*)
        ;;
    *)
        # Prepending path in case a system-installed rustc needs to be overridden
        export PATH="$HOME/.cargo/bin:$PATH"
        ;;
esac

This gives to a local attacker the possibility of overriding sudo or other binaries to get user password or root access.
For sure having access to the account there are other attack vectors, but this open an extra attack vector.

Steps

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Possible Solution(s)

export PATH="$PATH:$HOME/.cargo/bin"

Notes

No response

Rustup version

rustup 1.24.3 (ce5817a94 2021-05-31)                                                                      
info: This is the version for the rustup toolchain manager, not the rustc compiler.                       
info: The currently active `rustc` version is `rustc 1.56.1 (59eed8a2a 2021-11-01)`

Installed toolchains

Default host: x86_64-unknown-linux-gnu                                                                    
rustup home:  /home/sha0/.rustup                                                                          
                                                                                                          
stable-x86_64-unknown-linux-gnu (default)                                                                 
rustc 1.56.1 (59eed8a2a 2021-11-01)
@sha0coder sha0coder added the bug label Dec 9, 2021
@rbtcollins
Copy link
Contributor

rbtcollins commented Dec 10, 2021 via email

@asukaminato0721
Copy link

I check the position, seems that by default rustup and cargo installed at the same place, so maybe need to work on that.

ref https://stackoverflow.com/questions/46739842/where-does-rustup-install-itself-to

@rami3l
Copy link
Member

rami3l commented Jan 23, 2025

I check the position, seems that by default rustup and cargo installed at the same place, so maybe need to work on that.

ref https://stackoverflow.com/questions/46739842/where-does-rustup-install-itself-to

As mentioned in https://stackoverflow.com/a/67095192, $RUSTUP_HOME (instead of $CARGO_HOME) is the installation directory of rustup; we merely put some shortcuts in $CARGO_HOME for convenience.

I believe our policy has remained unchanged over the years: we assume you have direct control over these two directories. If not, you should set them to places you currently directly control.

cc @weihanglo @epage for potential comments on your plan of potentially splitting $CARGO_HOME

@sha0coder
Copy link
Author

sha0coder commented Jan 24, 2025 via email

@ChrisDenton
Copy link
Member

ChrisDenton commented Jan 24, 2025

The only problem of fixing this, is that the system installed cargo will override the home installed cargo in the case of two cargo binaries exist.

That would be a serious problem for many.

@weihanglo
Copy link
Member

An alternative way to mitigate shadowing would be for there to be two path entries, one for rustups proxies, and one for cargo installed programs, and that second one could be placed at the rear of the path.

This has been brought up in the Pre-RFC of splitting CARGO_HOME. We tend to have a separate CARGO_BIN_HOME. The unresolved part is whether RUSTUP has a separate RUSTUP binary/proxy directory and how that would work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants