Ruby Net::HTTPS Library Insufficent Validation of Server Certificate CN
2 Oct. 2007
Summary
The Ruby Net::HTTP and Net::HTTPS library can be used to make HTTP or HTTPS connections to remote websites. There are several methods for performing these types of connections within the Ruby standard library but the Net::HTTP library is recommended going forward.
A vulnerability results from the Net::HTTPS library failing to validate the name on the SSL certificate agains the DNS name requested by the user. By not validating the name, the library allows an attacker to present a cryptographically valid certificate with an invalid CN.
Vulnerable Systems:
* Ruby version 1.8.5
* Ruby version 1.8.6
* Ruby version Trunk
The vulnerability is caused by the method connect within http.rb file failing to call post_connection_check after the SSL connection has been negotiated. Since the server certificates CN is not validated against the requested DNS name, the attacker can impersonate the target server in a SSL connection. The integrity and confidentiality benefits of SSL are removed by this vulnerability.
Example:
If the application uses the following code to connect to the ip address of https://www.citicards.com:
The connection will succeed. This is an obvious failure as the certificate presented has a CN of www.citicards.com. One caveat is that the attacker must possess a certificate signed by the CA specified in the ca_file attribute.
Fix Information:
This issue has been addressed by adding the appropriate post connection check within http.rb. These patches add the enable_post_connection parameter, which if set to true, will cause the Net::HTTP library to raise an exception when the post connection check fails.