This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
Fix MiM Security vulnerability: missing SSL hostname validation #1
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.
📊 Metadata *
em-imap is a gem that allows you to connect to an IMAP4rev1 server in a non-blocking fashion.
Affected versions of this package are vulnerable to Man-in-the-Middle (MitM). The hostname in a TLS server certificate is not verified. An attacker can acquire the identity of a trusted server and implement malicious data.
Bounty URL: https://www.huntr.dev/bounties/1-rubygems-em-imap/
⚙️ Description *
SSL validation was not implemented making em-imap vulnerable to MiM attacks, fixed adding validations.
💻 Technical Description *
ssl_verify_peer param is eneabled when calling connect from EventMachine::Connection, this will call ssl_verify_peer and ssl_handshake_completed of the connection module for the calling programm to implement validation logic.
Validation of Server certificate was implemented using openssl based on code from:
lostisland/faraday@63cf47c
🐛 Proof of Concept (PoC) *
Add a fake DNS entry to /etc/hosts.
echo "127.0.0.1 test.imap.gmail.com" | sudo tee -a /etc/hosts
Create a certificate.
openssl req -x509 -newkey rsa:2048 -keyout key.pem -out cert.pem -days 365 -nodes
Listen on port 443 with TLS enabled.
openssl s_server -key key.pem -cert cert.pem -accept 443
Create sample client:
ruby clientPoc.rb
🔥 Proof of Fix (PoF) *
After fix Invalid certificate is detected and connection terminated
Valid certificate for wrong server will also be detected and connection aborted
👍 User Acceptance Testing (UAT)
After fix functionality is unafected