-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Adding ./bin
to your PATH is a bad practice
#309
Comments
The page on understanding binstubs also encourages this practice at the end of the section titled |
It does pose a concern in production or when you're sharing a development machine with untrusted users and For personal dev machines, home to a single user, doing away with the leading Updated the wiki to clarify. Thanks @nate! |
Thanks for fixing this, although I'm not sure we're exactly on the same page, or maybe I just don't follow. Even on personal dev machines it's risky to use relative paths in Suppose for a moment that PATH has
Now suppose that the This is one of the major reasons why |
@nate: we understand. However I usually don't download and untar projects that want to hack my system. Not terribly concerned about that. In the guide, I only suggested putting |
Even if we set aside deliberate hacking, and I don't think that's a good idea, this still leaves the system open for accidental overrides of commands, even with important, basic POSIX commands. There is still substantial risk there, risk that the wider community has deemed too much to tolerate (see '.'). I don't think it sounds like a suggestion in the wiki, and even if it was it sets a bad precedent. This is a major project, a respected project, built by people who are respected in the community, and it's recommending a relatively dangerous practice. Those who aren't acutely aware of the risks will be led to believe this is ok. I feel like this isn't going anywhere so I won't push it anymore, but just please consider your position and the risk involved. |
What about rbenv-vars plugin?, you could have something like: PATH=$PATH:$PWD/bin inside a |
That's a bit of an improvement, but I think they're trying to avoid having to type anything extra to have the correct gem loaded. I think the best way to do this and avoid having |
@nate: well, as far as i know with rbenv There's nothing to "trust." so no magic-automation would be added to "fix" this, but JMHO. BTW, it should be: PATH=$PWD/bin:$PATH |
With rbenv-vars, there is a project specific |
@nate: with rbenv-vars you would get a new value in PATH but not with |
My whole argument is based around explicitly granting trust, in this case to directories. Defaulting to trusting nothing and explicitly granting trust is a security posture known as default deny. rbenv-vars seems to implicitly trust any |
@nate Agreed. Letting the current working dir alter your env is great for the 99% case but can really burn in the 1% case. Setting Check out zimbatm/direnv#23 for similar considerations with direnv's Volunteers welcome to help flesh out the Right Way to do convenient app executables in dev without compromising security (or unexpectedly stubbing your toes). |
I'll move this over to to the rbenv-vars project then and see if anyone wants to chime in. I'd love to help out but I'd like to get feedback on my idea (or outright rejection of it) before I start in on it, if for no other reason than I'm not the world's greatest shell programmer. Thanks for all the feedback, everyone. |
rbenv's philosophy is to avoid shell hacks such as hooking into What I consider to be safe behavior: when you change into a directory that has a My implementation (zsh only): if [[ -n $ZSH_VERSION ]]; then
[[ -z $AUTOBIN_LIST ]] && AUTOBIN_LIST=~/.config/autobin
_autobin_hook() {
if [[ -n $AUTOBIN_DIR ]]; then
# remove old dir from path
path=(${path:#$AUTOBIN_DIR})
unset AUTOBIN_DIR
fi
if [[ -d "${PWD}/bin" ]] && grep "${PWD}/bin" "$AUTOBIN_LIST" >/dev/null 2>&1; then
# add whitelisted dir to path
AUTOBIN_DIR="${PWD}/bin"
path=($AUTOBIN_DIR $path)
fi
}
[[ -z $chpwd_functions ]] && chpwd_functions=()
chpwd_functions=($chpwd_functions _autobin_hook)
fi |
@nate: could you please give a concrete example-situation so i can be on the same page? Maybe we could get a more reasoned solution if actually there is a security problem. "If so, you could just as easily run a file you hadn't intended to because a .rbenv-vars could modify PATH to point somewhere you didn't want it to." A .rbenv-vars is going to modify your PATH because that what you want. You are explicitly asking for that if you follow my instructions. If you do not know why and with what you are modifying your PATH then i think there is a PEBKAC. @mislav: with your suggestion i think all you are going to get is a "false sense of security". The problem is not in trusting directories but trusting their content.. If there is a Anyway, remember KISS. |
I don't think whitelisting project directories on my machine is a false sense of security. By whitelisting a directory, I'm making myself aware that this This approach should be as secure as putting any other system dir in my PATH via |
@nihilismus: I don't know about you, but I download a lot of projects to check them out. If they happen to have a Regarding trusting directories, this is how I would like to see this work, more or less. Suppose that this is how directories and filemd5=$(cat .rbenv-vars | md5)
pathmd5=$(echo `pwd` | md5)
trusted=true
mkdir -p "~/.rbenv-vars/trusted_paths/$pathmd5"
echo $trusted > "~/.rbenv-vars/trusted_paths/$pathmd5/$filemd5" A trust check might look like: filemd5=$(cat .rbenv-vars | md5)
pathmd5=$(echo `pwd` | md5)
if [ -f "~/.rbenv-vars/trusted_paths/$pathmd5/$filemd5" && `cat ~/.rbenv-vars/trusted_paths/$pathmd5/$filemd5` == "true" ]; then
# load .rbenv-vars file
else
echo "Untrusted file found, do you want to trust this file?"
read trusted
if [ $trusted == "true" ]; then
# do the code to store that this file is trusted
# load .rbenv-vars file
else
echo "k then, later"
exit 1
fi
fi With this you could confirm at runtime whether a file is trusted or not and it should offer much better security. The bonus is that you only have to confirm trust on changes and in new projects, so it's low burden. Thoughts? |
@nate: It's an interesting approach. However, I wouldn't want to be nagged with "do you want to trust this file?" for every change made to |
I can definitely see the value in just trusting the project altogether. For most projects this is probably fine. How often do As with most security concerns it's a matter of balancing risk with convenience. I can see three issues with trusting directories, and they're possibly non-issues:
So, anyways, I think this hinges on how often I would be fine with either way of doing things. |
Assuming the binstubs for a project are in the local bin/ directory, you can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" However, doing so on a system that other people have write access to (such as a shared host) is a security risk. rbenv/rbenv#309
Assuming the binstubs for a project are in the local bin/ directory, you can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" However, doing so on a system that other people have write access to (such as a shared host) is a security risk. rbenv/rbenv#309 Put this in `zprofile` because Arch (and Fedora/Debian) puts `PATH` manipulation in `/etc/zsh/zprofile`, which is sourced after `~/.zshenv` (our preference). We chose `~/.zprofile` because we were sick of getting command-not-found errors in non-interactive settings. If the system-level zprofile (`/etc/zsh/zprofile`) sets a `PATH`, it will clobber anything you do in `~/.zshenv` since it's sourced after. We also like that `~/.zprofile` is sourced less frequently so moving what you can there will speed up terminal launch, by however small an amount. It should not be `zlogin` because: http://zsh.sourceforge.net/Intro/intro_3.html > `.zlogin` is not the place for alias definitions, options, environment > variable settings, etc.; as a general rule, it should not change the > shell environment at all. Rather, it should be used to set the > terminal type and run a series of external commands (fortune, msgs, > etc).
Assuming the binstubs for a project are in the local bin/ directory, you can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" However, doing so on a system that other people have write access to (such as a shared host) is a security risk. rbenv/rbenv#309 Put this in `zshenv` because: http://zsh.sourceforge.net/Intro/intro_3.html > `.zshenv' is sourced on all invocations of the shell, unless the -f > option is set. It should contain commands to set the command search > path.
Assuming the binstubs for a project are in the local bin/ directory, you can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 Put this in `zshenv` because: http://zsh.sourceforge.net/Intro/intro_3.html > `.zshenv' is sourced on all invocations of the shell, unless the -f > option is set. It should contain commands to set the command search > path. Load `zshenv.local` config at the end of the file so that users can extend their `zshenv` needs in their personal dotfiles using `rcup`.
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment We load rbenv and add `.git/safe/../../bin:$PATH` to our $PATH in: https://github.com/thoughtbot/dotfiles/blob/master/zshrc Loading rbenv in `zshrc` is recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment This commit loads rbenv in `zshrc` as recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we can even go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
Assuming the binstubs for a project are in the local `bin/` directory, we can add the directory to shell `$PATH` so that `rspec` can be invoked without the `bin/` prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 I used to do this manually before, as I have it in my `$PATH` https://github.com/mehlah/dotfiles/blob/master/zshenv#L12-13
Assuming the binstubs for a project are in the local `bin/` directory, we can add the directory to shell `$PATH` so that `rspec` can be invoked without the `bin/` prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 I used to do this manually before, as I have it in my `$PATH` https://github.com/mehlah/dotfiles/blob/master/zshenv#L12-13
Some Ruby gems provide an executable to run its contained Ruby program. We most commonly use `rails`, `rspec`, and `rake`. When we type `rspec` within the root of our project, Rubygems will use the latest version of the RSpec gem, not the version specified in the project's `Gemfile`. That's a problem that Bundler's `bundle exec` solves. It's tedious to type `bundle exec`, however. We previously solved that problem via a directory convention for Bundler's binstubs and adding that directory to our shell's `PATH`. Running `bundle binstub rspec` generates a binstub file in the `bin` directory. Running `./bin/rspec` is now the same thing as running `bundle exec rspec`. Adding `export PATH=".git/safe/../../bin:$PATH"` and running `mkdir .git/safe` in the root of repositories you trust lets us just type `rspec`, have the binstub be invoked, and therefore the correct version of RSpec be used for the project. rbenv/rbenv#309 We previously used `./bin/stubs` as our binstubs directory convention and ignored the directory in version control. We used that convention instead of `./bin` because we didn't want to gitignore the already-existing `./bin` directory and we didn't want to replace the critical `bin/rails`. The community is moving towards a convention of using `./bin`: * Rails is using `./bin` instead of `./script` starting with Rails 4. * The default Bundler behavior is to use `./bin`.
Our expected way of managing Rubies is with rbenv: https://github.com/thoughtbot/laptop/blob/master/common-components/ruby-environment We load rbenv and add `.git/safe/../../bin:$PATH` to our $PATH in: https://github.com/thoughtbot/dotfiles/blob/master/zshrc Loading rbenv in `zshrc` is recommended by the rbenv docs: https://github.com/sstephenson/rbenv#basic-github-checkout Assuming the binstubs for a project are in the local bin/ directory, we go a step further to add the directory to shell $PATH so that rspec can be invoked without the bin/ prefix: export PATH="./bin:$PATH" Doing so on a system that other people have write access to (such as a shared host) is a security risk: rbenv/rbenv#309 The `.git/safe` convention addresses the security problem: https://twitter.com/tpope/status/165631968996900865 This zsh fix may be necessary for OS users in order to fix a bug: https://github.com/thoughtbot/laptop/blob/master/mac-components/zsh-fix
On the wiki page on plugins under the section
Bundler integration
, it is recommended to stay away from the rbenv-bundler plugin and instead use bundler's binstubs. What concerns me is that it also encourages users to put./bin
in their PATH. This is not much better than having.
in your path.http://www.faqs.org/faqs/unix-faq/faq/part2/section-13.html
The text was updated successfully, but these errors were encountered: