清理外部流程的输入

发布于 2024-10-17 04:45:51 字数 172 浏览 16 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏了南城 2024-10-24 04:45:51

通过列入黑名单无法保证您的安全(这就是您正在做的事情)。相反,您必须将允许的字符(字母、数字、空格、点...)列入白名单。抵制黑名单的诱惑,它永远不会起作用。 (例如,您的代码是否可以生存空格?它是否可以生存 \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?)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文