I guess calling that risky is fair. I have not adequately shown that this covers every possible case. If I was great at formal verification, I could attempt to prove that. Albeit, that would be more work than just using a better method. I viewed this as essentially escaping input. For example, in HTML it is sufficient to escape something like 3 symbols. Here's the filter:
cat | sed -r 's/\$\([^)]+\)//g
s/`[^`]+`//g
s/;.*//g'
Though, there are some filters that I would not view as risky (provided sed does exactly what the regular expression states):
cat | sed -r 's/.*//g'
Maybe a whitelist approach would have been better. In any case, I went with the Bash code you provided. Thanks for the bug report. Fixed.