开发者

Sanitize inputs to external process

开发者 https://www.devze.com 2023-02-10 01:31 出处:网络
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, sour

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?)

0

精彩评论

暂无评论...
验证码 换一张
取 消