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

Fix for Bash env script injection on RPM family distros #1189

Merged
merged 1 commit into from
Jul 22, 2024
Merged

Fix for Bash env script injection on RPM family distros #1189

merged 1 commit into from
Jul 22, 2024

Conversation

Colonial-Dev
Copy link
Contributor

Resolves #1187 - this is a quick fix I hacked up that piggybacks on the existing add_install_dir_to_path function.

It works well in a Fedora container, but shell scripting is not my strong suit - I'll gladly cook up something different if there's a footgun I overlooked.

@Gankra
Copy link
Contributor

Gankra commented Jul 8, 2024

Oh wow, I super appreciate the research you did into this!

Comment on lines 445 to 446
exit1=$?
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" "sh"
shotgun_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" ".bash_profile .bash_login .bashrc" "sh"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this slightly changes behaviour here. Currently we will create .bash_profile if none of these files exist, and with shotgun we no long detect this case. Is that intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it's not - good catch, thanks! I'll fix that.

add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" "$_rcfile_relative" "$_shell"
fi
done

if [ "$_found" = false ]; then
add_install_dir_to_path "$_install_dir_expr" "$_env_script_path" "$_env_script_path_expr" "$(echo "$_rcfiles" | awk '{ print $1 }')" "$_shell"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this extra awk accomplish?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops - nothing, that was left over from the check I pasted from add_install_dir_to_path before I checked and found that var=bool is dash/POSIX compliant.

@Gankra
Copy link
Contributor

Gankra commented Jul 8, 2024

Hmm interesting it looks like rustup currently in fact doesn't create a bash file if they're all missing, so maybe your original commit should be desired behaviour? (It does unconditionally create .profile)

https://github.com/rust-lang/rustup/blob/fe99f782cf362a11609768d58ea27183ae685532/src/cli/self_update/shell.rs#L136-L156

@Colonial-Dev
Copy link
Contributor Author

Colonial-Dev commented Jul 8, 2024

I can definitely see an argument for that. Should we make the other shells behave similarly, in that case? I did notice that the Atuin installer was creating a .zshrc in my home despite zsh not even being installed on my system.

@Colonial-Dev
Copy link
Contributor Author

Alternately - I was going to ask what you thought about making .bashrc the default, instead of .bash_profile. Most people will (I'm assuming) be using non-login shells, and most (all?) distros usually source $HOME/.bashrc in their profile if it exists.

@Gankra
Copy link
Contributor

Gankra commented Jul 8, 2024

This is really interesting, it seems like rustup has tightened up how hard it shotguns since last i checked. It means that someone who installs zsh later won't see cargo on path, hmmm...

@Gankra
Copy link
Contributor

Gankra commented Jul 8, 2024

(Gonna consult with coworkers on what we wanna do here)

@mistydemeo
Copy link
Contributor

Thanks for this PR! It's a big help.

Most people will (I'm assuming) be using non-login shells

macOS's terminal uses login shells by default, so we do want to plan around it. (I don't even have a .bashrc on my system!)

I think, reading up on what rustup does, that their logic makes some sense. Plus, if we stop creating a file by default, we can completely dodge the "login shell or not login shell" question.

The "should we create .profile" question is kinda sorta separate. The answer "this is the only one standardized by POSIX, so we should always handle it" makes a certain amount of sense, but in practice absolutely nothing on my system has ever interacted with it (and only cargo-dist has ever put stuff in there, so it's a graveyard of test data). It doesn't hurt to make that the default file we create, but I'm not convinced it's actually going to affect very many users.

@Colonial-Dev
Copy link
Contributor Author

Interesting, I didn't know that about macOS.

With respect to .profile - I think it makes sense to keep it, even if just for the token POSIX acknowledgement. Best effort is better than no effort.

@mistydemeo
Copy link
Contributor

Sounds good! In that case, how about we keep what you've written except we change the order so the "write to the first in the list" is .profile?

@Colonial-Dev
Copy link
Contributor Author

Sure! Do you think we need to alter the behavior for the other shells at all? I'd need to double check, but I think ZSH etc. all match rustup.

@Colonial-Dev
Copy link
Contributor Author

Double checked, and the existing logic for POSIX/Zsh/fish seems to be valid and equivalent to rustup's implementation.

@Colonial-Dev Colonial-Dev requested a review from Gankra July 20, 2024 12:48
commit f322c7cb6f10d52bb6df0259de82b827bdd6df3b
Author: James Haywood <jameshaywood@fastmail.com>
Date:   Sat Jul 20 13:38:18 2024 +0000

    > squash commits
    > CI failure jumpscare

    many such cases

commit 64e187b5c413bb72f115c7ed2d98151981c9d9b1
Merge: 65c6c517 f18f683
Author: James Haywood <jameshaywood@fastmail.com>
Date:   Sat Jul 20 13:35:24 2024 +0000

    Merge branch 'main' into bash-fix

commit 65c6c51734b1db552688d761e2c93226523dade8
Author: James Haywood <jameshaywood@fastmail.com>
Date:   Mon Jul 8 10:23:27 2024 +0800

    Fix compatibility issues with Bash on certain distributions (Fedora, EL)

    Ensure a file is created if none are found

    Remove spurious awk usage

    Make .profile the fallback option for Bash

    Silence CI, mv $file (basename $file .new) is speaking
Copy link
Contributor

@mistydemeo mistydemeo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again!

@mistydemeo mistydemeo merged commit 818a925 into axodotdev:main Jul 22, 2024
15 checks passed
@Colonial-Dev Colonial-Dev deleted the bash-fix branch July 22, 2024 23:30
@Colonial-Dev
Copy link
Contributor Author

Thank you :D

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.

Installer Bash source injection is still insufficient on some distros (Fedora, RHEL-compatibles)
3 participants