0

I've added the current directory to my $PATH (PATH="$PATH":.) to make it easier to run shell scripts in the current folder.

Now I often see the following output before a shell command is executed:

❯ cd Sites/project-a

❯ colorls

# /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/universal-darwin20/rbconfig.rb:229:
# warning: Insecure world writable dir /Users/philipp/Sites/project-a in PATH, mode 040777
#
# ... output of the colorls command ...

(colorls is a ruby gem that I use instead of ls, but I also use other gems in many scripts)

I am aware of the meaning and the reason behind it, but I do not want a ruby script to dictate how I should configure my local system.

Is there a way to suppress the warning without changing the directory permissions?

Marlon Richert
  • 5,250
  • 1
  • 18
  • 27
Philipp
  • 10,240
  • 8
  • 59
  • 71
  • Does this answer your question? [Erroneous "Insecure world writable dir foo in PATH" when running ruby script](https://stackoverflow.com/questions/5708806/erroneous-insecure-world-writable-dir-foo-in-path-when-running-ruby-script) (However, you should probably fix the pretty major security issue). – Schwern Jan 12 '21 at 01:02

1 Answers1

0

I could not find a way to globally disable the "Insecure world writable dir" warning.

Another answer suggests replacing the ruby executable with a shell script or to recompile ruby with different options. Both options are difficult and could lead to other unexpected problems, in my opinion.

However, I found a way to disable the warning for individual scripts/gems:

In my case, I use the gem colorls to generate a nicer ls output. So far, this gem is the only one the frequently triggers the warning. I solved it, by adding the following alias to my .zshrc file (or .bash_profile)

Solution 1

# Inside .zshrc

alias colorls='colorls --color=always 2>/dev/null'

The important part is the error redirection 2>/dev/null.

Good: This alias allows me to add custom parameters to the command, like colorls --report

Bad: This alias will mask any error or warning that the command produces. I want to specifically remove the "Insecure world writable dir" warning.

Solution 2

# Inside .zshrc

alias colorls='colorls --color=always 2>&1 | grep "warning: Insecure world writable dir" -v'

Good: Instead of redirecting all errors to /dev/null, my second attempt redirects all output to grep, which strips out the individual warning message.

Bad: That solution does not recognize any colorls parameters; any parameter will be passed to grep instead of colorls...

Solution 3 (best)

# Inside .zshrc

colorls() {
    /usr/bin/colorls --color=always $@ 2>&1 | grep "warning: Insecure world writable dir" -v
}

This is the best solution: We replace the colorls binary with a shell function. That shell function calls the binary. The $@ variable passes all parameters to the binary, while grep removes the specific warning from the output.

Philipp
  • 10,240
  • 8
  • 59
  • 71