Sanitize inputs to external process

237 Views Asked by At

I have a Java program that interacts with Mercurial repositories using the hg client executed using commons exec. Since I will have to occasionally pass user inputs to hg (such as proxy settings, source url, etc.), what libraries are available to sanitize the inputs for me? I'm currently just stripping anything after and including the first ';' character but am unsure of other methods where someone can run arbitrary commands.

1

There are 1 best solutions below

0
On

You cannot be safe by blacklisting (thats what you are doing). Instead you have to whitelist the allowed chars (letters, numbers, space, dot, ...). Resist the temptation to blacklist, it never works. (For example does you code survive spaces? Does it survive \0 chars?)