清理外部流程的输入
我有一个 Java 程序,它使用使用 commons exec 执行的 hg 客户端与 Mercurial 存储库进行交互。由于我偶尔需要将用户输入传递给 hg(例如代理设置、源 url 等),因此可以使用哪些库来清理输入?我目前只是删除第一个“;”之后的所有内容(包括第一个“;”)字符,但不确定有人可以运行任意命令的其他方法。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通过列入黑名单无法保证您的安全(这就是您正在做的事情)。相反,您必须将允许的字符(字母、数字、空格、点...)列入白名单。抵制黑名单的诱惑,它永远不会起作用。 (例如,您的代码是否可以生存空格?它是否可以生存 \0 字符?)
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?)