Shell Script CGI Security

232 2026-08-05 note ♈︎ ♄︎

Shell scripts are risky for CGI because sandboxing backticks against injection is close to impossible.

The Minimal CGI Script note explicitly warns against shell script CGI for this reason.

For the guestbook system, the shell script runs locally on the tilde server, not as a web CGI, which reduces the attack surface.

If you must use shell scripts for web input, filter for known patterns rather than trying to sanitize arbitrary input:

if grep -qi "viagra\|casino\|lottery\|porn" "$TEMPFILE"; then
    echo "Entry rejected: inappropriate content detected"
    rm "$TEMPFILE"
    exit 1
fi

This is a denylist approach, not real security. Python or Perl CGI with proper parameter handling is safer.