Great question! You might enjoy this writeup, which in one section explores avoiding the use of shell variables that are not exported as a method of mitigating this risk.
https://linus.schreibt.jetzt/posts/shell-secrets.html