-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: CWE-552 Add sources and sinks to to detect unsafe getResource calls in Java EE applications #8706
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
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, thank you for your contribution. I added a few inline comments.
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeResourceGet.java
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeResourceGet.java
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Outdated
Show resolved
Hide resolved
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.
Found 2 vulnerabilities.
Thanks @atorralba for reviewing this PR and your help with merging with main. I've made all requested changes. Please review again. Thanks, |
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.
A couple more comments.
The PR description reads like it's purely adding more models of sources and sinks, but the test expectation changes remove a result -- is that expected? Are you fixing an FP here at the same time? |
Thanks @smowton for reviewing this PR. I think you are talking about the following test result:
Its relevant test case is no longer listed as a codeql/java/ql/test/experimental/query-tests/security/CWE-552/UnsafeServletRequestDispatch.java Lines 103 to 112 in 811a2c0
Changes in this PR seems to be irrelevant. I'm curious whether a change to a shared library somewhere caused the behaviour change. I will further investigate then report back. |
Somehow the following taint step was removed during code merge. I've put it back and the issue is resolved.
And thanks for pointing out this issue. |
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.
LGTM; started tests running.
Directly incorporating user input into the getResource call on the server side without proper validation of the input can allow any web application resource such as configuration files and source code to be disclosed.
It is very common that Java EE applications load requested resources and return file contents to clients. Constructing a server-side URI path with user input could allow an attacker to download application binaries
(including application classes or jar files) or view arbitrary files within protected directories.
This query detects unsafe usage of
getResource
orgetResourceAsStream
from both servlet context and Java Server Faces context. It utilizes the path sanitizer library to reduce FPs:Please consider to merge the PR. Thanks.