Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 Java 程序,它使用使用 commons exec 执行的 hg 客户端与 Mercurial 存储库交互。由于我必须偶尔将用户输入传递给 hg(例如代理设置、源 url 等),哪些库可以为我清理输入?我目前只是在包括第一个';'之后剥离任何东西 字符,但不确定其他人可以运行任意命令的方法。
将您列入黑名单(这就是您正在做的事情)是无法保证安全的。相反,您必须将允许的字符(字母、数字、空格、点...)列入白名单。抵制黑名单的诱惑,它永远不会奏效。(例如,您编码的空间是否存在?它是否存在 \0 字符?)