GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java: CWE-273 Unsafe certificate trust by luchua-bc · Pull Request #3550 · github/codeql

Conversation

@luchua-bc

@luchua-bc luchua-bc commented May 24, 2020

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@luchua-bc
Java: CWE-273 Unsafe certificate trust
6d1ba3f
@luchua-bc
luchua-bc requested a review from a team as a code owner May 24, 2020 16:49
@luchua-bc luchua-bc mentioned this pull request May 24, 2020
Java: CWE-273 Unsafe certificate trust github/securitylab#102
Closed
@aschackmull aschackmull added the Java label May 25, 2020
@aibaars

aibaars commented May 25, 2020

Copy link
Copy Markdown
Contributor

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

CVE-2018-11087 spring-projects/spring-amqp@444b74e

CVE-2018-11775 apache/activemq@69fad2a

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@luchua-bc

luchua-bc commented May 27, 2020

Copy link
Copy Markdown
Contributor Author

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.

@luchua-bc

greysteil reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@aibaars

aibaars commented May 27, 2020

Copy link
Copy Markdown
Contributor

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 apache/beam. One before and one after the fix:

  • apache/beam@a7dd23d^
  • apache/beam@a7dd23d

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 http downloads anymore, so you might need to search and replace http: -> https: in pom files.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@intrigus-lgtm intrigus-lgtm mentioned this pull request May 27, 2020
[Java] CWE-295 - Incorrect Hostname Verification #3581
Closed
@luchua-bc
Add validation query for SSL Engine/Socket and com.rabbitmq.client.Co…
104f1c3
…nnectionFactory
@luchua-bc

luchua-bc commented May 28, 2020 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

@aibaars Thanks for generating the apache/beam databases. I've committed new code to detect all scenarios discussed above.

  • CVE-2020-1929 apache/beam@a7dd23d - The query can detect its insecure trustAllCerts implementation in both the before and after images. Since the CVE is to fix a configuration error that the implementation was invoked when it should not, the query still helps although it doesn't directly detect the configuration issue with the old version.

apache_beam

  • CVE-2018-17187 apache/qpid-proton-j@0cb8ca0 - The CVE is for possible misconfiguration with an externally created hostname verifier that doesn't validate hostname. The fix is to use the setEndpointIdentificationAlgorithm("HTTPS") method to enforce hostname verification when the application mode is SslDomain.VerifyMode.VERIFY_PEER_NAME. A new MethodAccess SSLEndpointIdentificationNotSet has been added to validate configuration of SSLEngine. Support to SSLSocket is also added since it's commonly used too.

apache_qpid-proton-j_0 29 0

  • CVE-2018-8034 apache/tomcat@2835bb4 - The issue with the WebSocket container can be detected with the new query.

apache_tomcat_9 0 8

  • CVE-2018-10936 pgjdbc/pgjdbc@cdeeaca - The fix is not to take an external hostname verifier that could be too lenient by default. As the code of external hostname verifier is not available in the repository, it cannot be detected with this query.

  • CVE-2018-11087 spring-projects/spring-amqp@444b74e - The fix is to invoke the enableHostnameVerification() method of com.rabbitmq.client.ConnectionFactory to enforce hostname verification. A new MethodAccess has been added to check this misconfiguration.

spring-amqp_v2 0 5

  • CVE-2018-11775 apache/activemq@69fad2a - Issues with the SSL engine configuration in the classes AutoInitNioSSLTransport and NIOSSLTransport can be detected by the new query now.

apache_activemq_5 15 5

Regards,
@luchua-bc

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@p-

p- commented May 28, 2020

Copy link
Copy Markdown
Member

@luchua-bc Oh, wow, nice work!
I discovered several of those 2018 CVE's 😉
CVE-2020-11050 is one from this year, but I think you've already got it covered. (It was fixed with setEndpointIdentificationAlgorithm("HTTPS"))

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@sj

sj commented May 28, 2020

Copy link
Copy Markdown
Contributor

Amazing work, @luchua-bc!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@luchua-bc

luchua-bc commented May 29, 2020

Copy link
Copy Markdown
Contributor Author

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:-)

matthewmccullough reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

luchua-bc added 2 commits June 23, 2020 12:24
@luchua-bc
Adjust id tag and fix ending line error
deabfe6
@luchua-bc
Fix ending line error
f8c4947
aschackmull
aschackmull requested changes Jun 24, 2020
View reviewed changes

@aschackmull aschackmull left a comment

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread java/ql/src/experimental/Security/CWE/CWE-273/UnsafeCertTrust.ql Resolved

Uh oh!

There was an error while loading. Please reload this page.

@luchua-bc
Clean up the QL code
0779aab
@luchua-bc

luchua-bc commented Jun 24, 2020

Copy link
Copy Markdown
Contributor Author

Thanks @aschackmull a lot for all your help with this PR.

@luchua-bc

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

aschackmull
aschackmull approved these changes Jun 25, 2020
View reviewed changes
@aschackmull
aschackmull merged commit b53b905 into github:master Jun 29, 2020
@luchua-bc
luchua-bc deleted the java-unsafe-cert-trust branch June 29, 2020 16:05
@atorralba atorralba mentioned this pull request Jun 28, 2021
Java: Promote Unsafe certificate trust query from experimental #6171
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@aschackmull aschackmull aschackmull approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

Java

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@luchua-bc @aibaars @p- @sj @aschackmull
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.