3 ms·
The parsing of environment variables to produce functions should be disabled int bash by default, unless a loud and clear command line option is given to reques
by kazinator 12y ago
The parsing of environment variables to produce functions should be disabled int bash by default, unless a loud and clear command line option is given to request the behavior, like "bash --hit-me-with-environment-variable-stupidity-please".
Furthermore, perhaps it should only work on environment variables in a loud an clear namespace like __bash_func_foo="() { whatever }" produces a function called "foo". A variable not in this namespace like TERM or REQUEST_URL is not scanned for this function-defining syntax under any circumstances.
Lastly, perhaps the target functions should be in a namespace themselves, making it impossible to pass down a function called "echo" or "ls". For instance only functions with the "if_" prefix ("inheritable function") could be subject to inheritance. Don't like the ugly prefix? Then write your shell application so that every new execution of a script sources all the code it needs from files. Or write your personal scripts so that they use a repository of functions in your ~/.bashrc rather than passing functions down among themselves. Or use local aliases for the ugly prefixed names.
- javajosh 12y agoAgreed. It is deeply strange that bash interprets the contents of environment variables at all and, although I'm no sysadmin, it would make sense to simply disable all interpretation and deal with subsequent breakage individually. bash's implicit environment processing is the bug. A process that depends on bash's implicit environment processing is a bug by the transitive nature of bugs (newly coined by me, just now). (Of course, you have to fix bash, then you have to replace it everywhere, including on devices that might not be user-updatable. I didn't think it was possible but this is clearly worse than heartbleed.)
- nhaehnle 12y agoConfining the parser to a namespace as in your second paragraph should be a sufficient solution, because it is already a well-known fact that allowing completely arbitrary control of the environment to a potential attacker is a bad idea, and existing software is written to account for that fact by restricting which environment variables can be set. In the CGI case, for example, the environment variables in question are prefixed by HTTP_. The problem is that any fix for this bug that makes the security crowd perfectly happy is necessarily going to break compatibility for the (probably very few) people who actually use this feature.
- kazinator 12y agoHowever, a flaw in some software (failure to properly restrict environment variables) is amplified by this feature of the shell; it gives an attacker an instant way to do harm. Whereas without this feature, attackers have to find some other ways by which environment variable contents can lead to an exploit. E.g. smuggle a rogue shared library onto the system somehow, then LD_PRELOAD it or whatever.