4 ms·
> Instead, code that shells out with programmatically constructed commands is typically riddled with potential bugs in the best case and massive security holes
by billyhoffman 11y ago
> Instead, code that shells out with programmatically constructed commands is typically riddled with potential bugs in the best case and massive security holes in the worst case.
This sentence sounds eerily similar to what we have with SQL Injection. Same concept: constructing raw commands for untrusted user input. The solution is equally simple: input validation (where possible), parameterized queries/shellescape.
The barriers to people shelling out securely are the same we had/have with SQL Injection:
1- Education: Many people are unaware of these solutions.
2- Bad habits reenforced by bad code examples. People don't use these security best practices in the simplified code examples included in a blog post, documentation, or a Stack Overflow answer. I joke that the only SQL code example on MSDN that isn't SQL Injectable was the example for parameterized queries (I'm not that far off). Sadly It's not much better for escaping/defanging shell code.
Shelling out also had the added problem that far fewer people do it than use SQL, so the propagation of security best practices is going to be slower. Luckily it also means there are fewer places that screw it up.
- StefanKarpinski 11y agoThere is a common denominator between shelling out and making SQL queries: using strings to construct executable code. Metaprogramming with strings and eval, e.g. in Perl/Python/Ruby, is another place where this is done – and is fraught with similar issues. Lisp has metaprogramming, yet doesn't have this problem. Why? Because you don't do unstructured metaprogramming with strings in Lisp. Instead you do structured metaprogramming using lists and symbols. Julia also has structured metaprogramming [1]. For running external commands, Julia gives you a structured metaprogramming solution: the `cmd` form is really a list construct in disguise – one that understands shell syntax and is therefore easy and intuitive to use. The same approach can and probably should be used to make SQL query construction both convenient and safe. [1] http://julia.readthedocs.org/en/latest/manual/metaprogramming/ http://julia.readthedocs.org/en/latest/manual/metaprogrammin...