-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Java: CWE-273 Unsafe certificate trust #3550
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
Unsafe SSL configurations have been the cause of quite a few CVEs . I wanted to share a couple I ran into when investigating past CVEs. I don't expect this query to find all the cases listed below, but they might be a good starting point for more queries in this area. CVE-2020-1929 apache/beam@a7dd23d CVE-2018-17187 apache/qpid-proton-j@0cb8ca0 CVE-2018-8034 apache/tomcat@2835bb4 CVE-2018-10936 pgjdbc/pgjdbc@cdeeaca |
Thanks @aibaars for the CVEs. The apache/tomcat one can be detected with the existing query while three others can be detected with some new code. Two of them (apache/qpid-proton-j and apache/activemq) utilize the mechanism setEndpointIdentificationAlgorithm of SSLEngine and the spring-projects/spring-amqp one uses a third-party com.rabbitmq.client.ConnectionFactory library. For pgjdbc/pgjdbc, the fix to the CVE is not to take an external hostname verifier that could be too lenient. As the code of external hostname verifier is not available in the repository, it cannot be detected with this query. And the first one apache/beam doesn't have a Java database (only JavaScript and Python) so probably there is something wrong with its file structure thus it cannot be analyzed. In summary, the query is being updated to handle four of these CVEs and I'm in the middle of finalizing code changes and thorough testing. I will commit the code when it's done, probably in the next two days. |
Really great! I had not expected that this query (with some additions) would be able to find all those CVEs . I have two CodeQL databases for You can also create databases with the CodeQL CLI. Building old commits of a project can be tricky, they often require older versions of Java and maven. Also the maven central repository does not allow |
@aibaars Thanks for generating the apache/beam databases. I've committed new code to detect all scenarios discussed above.
Regards, |
@luchua-bc Oh, wow, nice work! |
Amazing work, @luchua-bc! |
Thanks for the nice comments. With those CVEs I can train and test my query, now I'm a little more fluent with CodeQL and I love it:-) |
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've added a number of inline comments to clean up the QL code a bit, but otherwise the QL code looks good.
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql
Outdated
Show resolved
Hide resolved
Thanks @aschackmull a lot for all your help with this PR. |
Java offers two mechanisms for SSL authentication - trust manager and hostname verifier. Trust manager validates the peer's certificate chain while hostname verification establishes that the hostname in the URL matches the hostname in the server's identification.
Unsafe implementation of the interface X509TrustManager and HostnameVerifier ignores all SSL certificate validation errors when establishing an HTTPS connection, thereby making the app vulnerable to man-in-the-middle attacks. This is a very common issue with web development.
The query checks whether trust manager is set to trust all certificates or the hostname verifier is turned off. I've tested it against some GitHub projects, and a test case has been created.
Please consider to merge the PR. Thanks.