-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: Experimental query for Log4j JNDI Injection #7354
Java: Experimental query for Log4j JNDI Injection #7354
Conversation
Good job @atorralba was looking for that throughout the day =) |
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
Outdated
Show resolved
Hide resolved
Is this based on / related to #7054? Would it make sense to use a kind other than Though I assume this query here is mostly only useful for security researchers to find attack vectors (which can still be valuable); it should not be used to reason about whether an application is affected by the Log4j 2 vulnerability because:
|
Have we considered looking at this open source query as an alternative way of finding this vulnerability in code? |
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.
Few suggestions for improvements to the documentation
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
Outdated
Show resolved
Hide resolved
Co-authored-by: Bas van Schaik <5082246+sj@users.noreply.github.com> Co-authored-by: Marcono1234 <Marcono1234@users.noreply.github.com>
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.qhelp
Outdated
Show resolved
Hide resolved
Co-authored-by: Bas van Schaik <5082246+sj@users.noreply.github.com>
Thank you so much for your review @Marcono1234 and @sj!
This query is intended to be short-lived and remain in experimental. The intention is to provide a tool for users to check for potential exploitation paths in their code if they need it, but not to run it continuously as part of code scanning. As such, we don't intend to merge the Log Injection query for the moment, which should avoid potential clashes. Of course, if this was going to be merged into the main query set, your suggestion would make total sense, so thank you!
As stated above, this query is intended to be a tool to help users evaluating their code, but of course it's not a silver bullet. For instance, Dependabot is actually more useful for detecting the issue, because it'll report if the vulnerable version is used. But for those that aren't able to activate Dependabot (or additionally to it), this query should provide a good alternative to obtain some information. Regarding bindings, while you're right that they could be also sinks, we've discussed it internally and, for the moment, we are going to try to maintain a high TP ratio in this query. If we added this without knowing whether the binding is actually bridging to Log4j, we'd be raising FP alerts. |
Yes, thanks @securingdev! There are several community-provided queries that do similar things out there. In this case, we decided to keep the explicit CSV format for defining sinks, because we think it's more comprehensive. Is there anything that you think our query is lacking compared to those? |
I would recommend we look at merging in the following section of code (or something similar) to catch any edge cases we might have missed:
The following idea was also worth considering in some capacity:
|
The problem with that approach is that it would probably introduce some FPs like, as stated above, Happy to change it, though, if several of us think the risk of raising some FP is acceptable in exchange of having less potential FNs. |
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-020/Log4jJndiInjection.ql
Outdated
Show resolved
Hide resolved
Do I understand correctly - these queries are to detect whether a project is vulnerable to specifically CVE-2021-44228? Are there queries that should/would have detected the vulnerability inside of log4j2? |
That's correct. And it will detect other cases of Log4j log injection (which is something you might generally want to avoid).
That's under active investigation. If you have any suggestions on how to approach this with CodeQL we'd love to hear from you! |
Will this query also catch cases of CVE-2021-45046 related to Log4J? |
Yes, the vulnerability pattern remains the same (untrusted data written to logs), it's just that the patch was incomplete for certain non-default configurations. |
@ambiso, might be good to clarify here, as mentioned by atorralba, that this is no "silver bullet". If this query does not have any findings, you should not interpret that as not being vulnerable. If you have
CVE-2021-45046 seems to be caused by legitimate usage of lookups in the log config (e.g. That vulnerability is normally not triggered directly by log message injection (unless someone uses |
That's what I was referring to with non-default configurations, in the sense that the CVE mentioned an "incomplete fix" of the original vulnerability.
But you're right, there are more sinks that could be modeled to cover CVE-2021-45046 (e.g. Thanks for the clarification @Marcono1234. |
Also, there seems to be a third vulnerability affecting |
is anyone working on that atm? @atorralba |
#7423 aims to cover CVE-2021-45046 completely. |
This is an experimental query for detecting CVE-2021-44228.