Hacking Rails (and GitHub)
A GitHub user exploited a security vulnerability in the public key update form in order to add his public key to the rails organization. He was then able to push a new file to the project as a demonstration of this vulnerability.
As soon as we detected the attack we expunged the unauthorized key and suspended the user.
My confidence in the clarity of GitHub's side of the story dissipated when I read one of the comments:
You didn't really "detect" anything. You were informed. It also wasn't an attack.
Not only did the "attacker" not do any actual damage, but he was continually ignored.
The author of this comment, Chris Acky, also made a more comprehensive blog post about the incident.
The "attacker" in question is Egor Homakov (his account has been reinstated), and he did in fact disclose the vulnerability a few days before he demonstrated it. There are a few facts worth noting up front:
- This was not a public key security vulnerability as the title of GitHub's post suggests.
- Egor is not a native English speaker, which might have made the potential impact of his discovery difficult to appreciate.
- He was not actually ignored, but he was pretty firmly dismissed (citing a prior discussion).
Telling someone they're wrong only fuels their desire to prove they're right. It's not a huge surprise that Egor's next step was to demonstrate the vulnerability.
I'd like to explain the vulnerability, but rather than show you any code, I want you to understand the nuts and bolts, because it's extraordinarily simple. If you have a GitHub account, you can manage your SSH keys. The form to add a new key looks something like this (edited for clarity):Title Key Add key
The authenticity_token is almost certainly an anti-CSRF token, so it doesn't complicate this exploit at all.
All Egor did was modify his own form to add the following:
The user_id of the Rails project is 4223, so that's why he chose it. (He believes this is a Rails issue, and it's hard to argue that.) By sending along this user_id, his public key was added to another account. Yikes!
For those of you more familiar with PHP, imagine a feature like register_globals, but instead of injecting arbitrary form data into the global namespace, it injects arbitrary form data into the database. It might as well be called opt-in SQL injection, but even that's being too generous, because this is much easier to exploit than an SQL injection vulnerability.
Egor points out that this vulnerability is unique to Rails:
Only Rails app have this kind of bug.
If you're using Rails and you want to be secure, you shou
Truncated by Planet PHP, read more at the original (another 3027 bytes)