Safer debugging, postmortem and security reading list ? #22

Lots of web application security articles last week again. So here are the most interesting ones.

  • Phillip shares a way to color­-code the PRY console in a production environment. He always has 2 debugging consoles open side by side. One in production and one in development. You know what can happen.
  • A good example of a postmortem for the Gitlab disaster,  including the issue tickets. Similar steps might  be needed after a security incident.
  • The Mozilla Security Bytes podcast starts with an episode on the Content­Security­-Policy.
  • If you’re using Docker, there are now Docker secrets.
  • And did you ever write a commit message “remove password”? You’re not alone. Don’t use it again, it might be a public repository.

Security updates

These friends of Rails saw security updates last week:

  • Jenkins released new versions after fixing several security issues, including a high one.

A week with a Rails Security Strategy (and page update)

Two things, a page update and my new article “A week with a Rails Security Strategy“.

Page update: This site hasn’t been very active recently, I’m working to make it more useful. Enter your e-mail in the header to notify you when it’s ready.

I published a new article “A week with a Rails Security Strategy” on my site:

You’re a busy person. Security is not a very visible feature in most applications, and so sometimes it’s not a priority. Of course you know it’s important, but how can you fit it into your busy schedule?

The answer may be in the power of habits and a Rails security strategy

Two MRI security vulnerabilities in Ruby 1.8 and 1.9

Two security fixes have been released for Ruby today. The first vulnerability affects the FileUtils.remove_entry_secure method which allowed local users to delete arbitrary files and directories. The second one affects the $SAFE level.


This affects Ruby versions 1.8.6 (420), 1.8.7 (330), 1.9.1 (430), 1.9.2 (136) and the development versions. The problem has been fixed and is available for download.

$SAFE vulnerability

This affects only 1.8 Ruby versions. Exception#to_s method can be used to trick $SAFE check, which makes a untrusted codes to modify arbitrary strings. The variable $SAFE determines Ruby’s level of paranoia. This problem has also been fixed.

Several vulnerabilities in Rails 2 & 3

Two new Ruby on Rails versions have been released yesterday because of 4 security vulnerabilities in Rails.

Potential XSS Problem with mail_to :encode => :javascript
Versions Affected:  All.
Not affected:       Applications which don’t use :encode => :javascript
Fixed Versions:     3.0.4, 2.3.11

CSRF Protection Bypass in Ruby on Rails
Versions Affected:  2.1.0 and above
Not affected:       Applications which don’t use the built in CSRF protection.
Fixed Versions:     3.0.4, 2.3.11
Do read the instructions carefully because it will affect your session and may require additional steps other than just updating. More here and in the Rails Security Guide.

Potential SQL Injection in Rails 3.0.x
Versions Affected:  3.0.0-3.0.3
Not affected:       Releases before 3.0.0
Fixed Versions:     3.0.4
Unfortunately this has been fixed in earlier versions already.

Versions Affected:  3.0.0-3.0.3
Not affected:       2.3.x versions and all earlier versions. Applications deployed on case-sensitive filesystems.
Fixed Versions:     3.0.4

XSS Weakness in strip_tags and some notes on parsing HTML/XML

There is another Cross-Site Scripting (XSS) Weakness in the Rails method strip_tag(). The problem was found in the HTML::Tokenizer which has bugs when parsing non-printable ASCII characters.

According to the original post, this has been fixed in Rails 2.3.5 and there is a patch for the 2.2. branch. Earlier versions are unsupported. Upgrade to a newer version if you make use of this method.

The workaround is this:

Users using strip_tags can pass the resulting output to the regular escaping functionality:

  <%= h(strip_tag(…)) %>

However, this is not how it should be. The strip_tags() method should work correctly. The workaround does work, but strip_tags() is based on HTML::Tokenizer which uses a very naive approach to parsing HTML code. It is based on regular expressions to analyze the code. For serious/enterprise implementations, you should not use an error-prone parser library.

  • The REXML is a little better, but not very fast for large amounts of data. It has some bugs and it’s not 100% standard compliant. For larger amounts of data, it may even be used to use a pull parser: REXML::Parsers::PullParser. Some people have successfully parsed HTML with it.
  • And there is libxml, which is a real parser, now with ruby bindings. We haven’t used it with (X)HTML, though. It has a pull parser too, and its quite like the REXML pull parser. LibXML is an extensive C-library which might not available on exotic Linux-derivates or Windows. Nokogiri is also based on LibXML.
  • Update: If you’re using JRuby, you can use tried and tested Java XHTML/XML parsers. For example Apache Xerces or the pull parser Woodstox which supports “almost well-formed” documents (like legacy (X)HTML content).

DoS vulnerability in BigDecimal

A Denial of Service (DoS) vulnerability was found in the BigDecimal standard Ruby library. An attacker could cause a segmentation fault and crash the Ruby interpreter. This is due to the BigDecimal method mishandling certain large values. Almost every Rails application is vulnerable to this because ActiveRecord relies on this method.

You are advised to update your Ruby installation. There is a temporary fix on Github. This fix breaks valid formats supported by BigDecimal, so you are advised to plan migrating to a new Ruby version.

Vulnerability in Rails 2.3 HTTP Authentication

There has been a security vulnerability in Rails in the HTTP digest authentication in Rails 2.3. That way someone can authenticate without any user name and password. The HTTP basic authentication seems to be not vulnerable to this problem.

The problem arises in the authenticate_or_request_with_http_digest method which will proceed even if the user name check returns nil.

You can find out more, including countermeasures at Nate’s blog and the Rails weblog.