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.
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?)
精彩评论