-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: check path permission & other CodeQL problems (#311)
问题1:用户输入正则表达式 之前的方式: 替换用户输入的路径中的特殊字符,CodeQL 仍然认为不安全。 现在的方式,重新构造一个字符串来防止用户注入预期外的正则表达式: 按照*进行分割 *替换为.* 其余字符全部使用字面匹配,即Pattern.quote 问题2:在 FileSystem 对接层中检查非法路径 在 FileSystemManager 中,进行读写之前,对路径进行过滤 问题3:CodeQL 报告Uncontrolled data used in path expression的假阳性问题 我们对路径进行了检查,但是 CodeQL 并不感知到我们的检查操作,所以在我们检查的同时,对 CodeQL 进行欺骗,来避免假阳性问题。 CodeQL 是基于污点分析来报告Uncontrolled data used in path expression问题的,所以我们只要设法阻断污点传播,就可以欺骗 CodeQL。 我尝试了使用 @Untainted 来阻断污点传播,但是 CodeQL 似乎并不支持该标注。 然后我使用了一个并不优雅的方式来欺骗 CodeQL。 欺骗 CodeQL 由于 CodeQL 认为下面的检查方式是安全的,记为 checkNode if (node.contains("..")) { return Optional.empty(); } 所以可以把路径拆成若干个文件夹/文件名称,分别应用上述检查,然后再拼接为一个路径,来避免让 CodeQL 报告该问题。例如路径 /root/data/example.txt 被拆分为 root、data、example.txt,然后对这三个字符串分别使用checkNode进行检查,再将这三个字符串和根路径拼接为/root/data/example.txt。 由于欺骗操作是内置在路径过滤接口中的,所以这种欺骗是安全的。
- Loading branch information
Showing
10 changed files
with
237 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.