-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: CWE-552 Query to detect unsafe resource loading in Java Spring applications #9199
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
Java: CWE-552 Query to detect unsafe resource loading in Java Spring applications #9199
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, thanks for your contribution. I added a couple comments that should be addressed if you're still interested in merging this PR regardless of bounty status.
java/ql/test/experimental/query-tests/security/CWE-552/UnsafeLoadSpringResource.java
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Outdated
Show resolved
Hide resolved
Hi @atorralba, I think this query will be beneficial so I'd like to have it merged. I've made requested changes. |
/** | ||
* Resource loading method declared in Spring `Resource` with `getInputStream` inherited from the parent interface. | ||
*/ |
Check warning
Code scanning / CodeQL
Class QLDoc style.
/** | ||
* Resource loading method declared in Spring `ResourceUtils`. | ||
*/ |
Check warning
Code scanning / CodeQL
Class QLDoc style.
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Outdated
Show resolved
Hide resolved
Hi! after reviewing the LGTM run results, I spot a number of FPs caused by:
@luchua-bc would you mind taking a look please? |
Hi @pwntester, As per your suggestion, I've removed |
Thanks a lot! |
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 sorry that this stalled for so long. I think if we remove the commented code and address the QLDoc style warnings above, this should be ready to be merged.
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
java/ql/src/experimental/semmle/code/java/frameworks/SpringResource.qll
Outdated
Show resolved
Hide resolved
Hi @atorralba, No problem and I know you are busy. Those text changes are pretty simple to make but it seems that there were other changes in that directory and in the main branch that impacts this query. When I run the query, I got some warnings like:
And the expected query results don't match actual results. I think I need to synchronize with the main branch then add changes on top of it. I will further investigate and get it done before next Monday. |
8a5622a
to
8effbff
Compare
Thank @atorralba for reviewing this PR. Actually a simple I've committed all the requested changes. Please merge the PR. Thanks, |
java/ql/src/experimental/Security/CWE/CWE-552/UnsafeUrlForward.qll
Fixed
Show resolved
Hide resolved
Thank @atorralba for committing the change. |
Directly incorporating user input into loading resource calls 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 Spring 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 resource loading in Spring including the following APIs:
It utilizes the path sanitizer library to reduce FPs:
Please consider to merge the PR. Thanks.