Skip to content

Shell Security Problems

andychu edited this page Aug 11, 2017 · 10 revisions

TODO: Link to good resources on the web.

  • rm -f * -- a file named '-r' can be interpreted as a flag

  • globbing happens after variable expansion. code as data

  • escaping from generating programs (shell, HTML, what else?)

  • bash shellshock: this was storing code in environment variables. code as data is an anti-pattern.

Examples

Pedantic Style

Motivation for Oil: get rid of pedantic style. The simple code should be correct, not be riddled with subtle bugs.

ShellCheck enforces pedantic style. Modernish developers a new pedantic style.

  • double quote everything (except it's not necessary for RHS of assignment)
  • add -- after everything, e.g. cd -- $dir not cd $dir. Except echo and others which don't support it.
Clone this wiki locally