-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: CWE-073 File path injection with the JFinal framework #7712
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Following up on the comment @smowton made with PR# 7286 that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @luchua-bc, thanks for your contribution.
I added some inline comments but, in general, I think this query mostly overlaps with java/path-injection
and they should probably be merged at some point (probably during promotion). So IMO the valuable contributions here are the JFinal sources and the PathSanitizer.qll
library. The latter I didn't review in detail again since it was mostly taken from #7286.
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
Thanks @atorralba for reviewing this PR. I'll work on suggested changes. The library PathSanitizer.qll does overlap with PR# 7286 and is actually taken from that PR then renamed. The rationale is that all queries requiring a path traversal check can use the shared library. Shall I move it to the directory And I noticed one thing when testing this query. That is, we included Once this PR is merged, I will create a separate PR to replace Thanks, |
I think it makes sense for that to be in the main library, but it probably should be in a different PR. That way, this PR would only contain the experimental query and would be easier to approve/merge. If you decide to do so, we can discuss the approach to supporting |
I like the idea. Let's complete this PR as an experimental query then I'll submit a new PR to the main directory that supports |
@atorralba - I've fixed an issue related to normalized paths in the latest commit to successfully detect the following test case: codeql/java/ql/test/experimental/query-tests/security/CWE-073/FilePathInjection.java Lines 39 to 44 in ce03aeb
As the method call is after the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I like the approach of sanitizing any sink that flows to a normalize
call. It could do so conditionally, or the normalized value could never be checked.
This is actually a shortcoming of the current java/path-injection
query too, and it needs to be fixed — but I don't think this is the proper way to do it. I can't suggest a better alternative at the moment, though.
Anyway, I added a small suggestion if you decide to keep this.
java/ql/src/experimental/Security/CWE/CWE-073/PathSanitizer.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/FilePathInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-073/JFinalController.qll
Outdated
Show resolved
Hide resolved
Also you should use that shared lib you've created in your other experimental query. Suggest moving the shared code under https://github.com/github/codeql/tree/main/java/ql/src/experimental/semmle/code/java and using it in both queries. |
Thanks @smowton for reviewing this PR. As per your advice, I've moved |
External Control of File Name or Path, also called File Path Injection, is a common attack and injection attack is listed as one of the top attacks in OWASP Top Ten 2021.
Loading files based on unvalidated user-input may cause file information disclosure and uploading files with unvalidated file types to an arbitrary directory may lead to Remote Command Execution (RCE).
JFinal is a widely used Web + ORM framework, which has 1.4K forks and 3.2k stars on GitHub. Multiple CWEs have been submitted for File Path Injection attack associated with this framework.
One sample CWE and its details can be found at Issue#115: ZrLog 2.2.2 Remote command execution vulnerability. Another one can be found at Issue #27: File reading.
This query detects unsafe file loading/downloading operations in code repositories that consume this framework. Please consider to merge this PR. Thanks.