Ruby Net::HTTPS library does not validate server certificate CN

iSEC Partners Security Advisory - 2007-006-RubySSL

Ruby Net::HTTPS library does not validate server certificate CN

Vendor: Ruby
Vendor URL:
Versions affected: 1.8.5, 1.8.6, Trunk Ruby
Systems Affected: All Ruby Platforms
Severity: Medium - Compromise of SSL connection integrity
Author: Chris Clark <cclark[at]isecpartners[dot]com>

Vendor notified: Yes
Public release: Yes
Advisory URL:

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.

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.


If the application uses the following code to connect to the ip address of

url = "" IP
path = "/"
http =, 443)
http.use_ssl = true
http.ca_file = "verisign.pem"
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
resp, data = http.get(path, nil)

The connection will succeed. This is an obvious failure as the certificate
presented has a CN of 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.

The following trunk Ruby checkin contains the related changes:

Ruby 1.8.5:

Ruby 1.8.6:

Thanks to:
Rachel Engel, GOTOU Yuuzou, and Minero Aoki

About iSEC Partners:
iSEC Partners is a full-service security consulting firm that provides
penetration testing, secure systems development, security education
and software design verification, with offices in San Francisco,
Seattle, Ewa Beach, and Los Angeles.

Relevant Pages

  • [UNIX] Ruby Net::HTTPS Library Insufficent Validation of Server Certificate CN
    ... The following security advisory is sent to the securiteam mailing list, and can be found at the SecuriTeam web site: ... Ruby Net::HTTPS Library Insufficent Validation of Server Certificate CN ... failing to call post_connection_check after the SSL connection has been ...
  • Re: Connect Pocket PC to desktop without ActiveSync?
    ... Certificate mechanism? ... There's nothing built into ActiveSync to validate ... You can't restrict the connection in that way with anything that is built ...
  • Re: Ruby Certification
    ... > impression, can only benefit your interview, if not their final decicion ... > are as core in Ruby community as you are clearly announcing. ... > inherant credibility of a certification would ensure that all topics are ... I got a MSc CS certificate somewhere. ...
  • Re: Ruby Black Belt
    ... When I have posted at Ruby group I have expected far more "blunt" ... However, some weeks ago gave Ruby a try (I did know about Ruby for years, but i said Python is essentially just the same with different syntactic sugar, so why waste time to learn the same thing twice) - but now, to say the least i am really happy that i did sacrifice some time to read the pickAxe. ... they did not even explain him what they do not really like about such a certificate. ... Of course i do not like it's certificate approach, which values lexical knowledge of idiotic obscure language details over natural talent/creativity. ...
  • Re: how to detect used protocol (SOAP, JSON, XML etc.)
    ... adding your own proprietary encapsulation/framing protocol around it. ... initiate a new connection for every request). ... connection and send a series of requests one after the other. ... which is basically an Apache module for running a Ruby ...