bootstrap-sass 3.2.0.3 on RubyGems added a file that lets a remote client run code inside a Rails app, published on 26 March 2019.
The gem has about 28 million downloads in total. The bad version was live for a short time.
What happened
An attacker published bootstrap-sass 3.2.0.3 with a hidden backdoor.
- The attacker removed the clean 3.2.0.2 release first, so new installs of the 3.2.0.x line got the bad version.
- The new file
lib/active-controller/middleware.rbchanges a Rails method. - The method reads the HTTP cookie
___cfduidand decodes the value with base64. The name has three underscores and copies the real Cloudflare cookie__cfduid. - It runs the result with
eval, in production mode only. - Anyone who can send a request to the app can run commands on the server.
Derek Barnes reported the difference between the gem and the source on 26 March 2019. The bad version left RubyGems less than one hour later. Version 3.2.0.4 followed on 3 April 2019.
Affected versions
- 3.2.0.3: backdoored, published 26 March 2019.
- 3.2.0.2: the last clean release before the attack, from September 2014 per LWN.
- 3.2.0.4: clean re-release of 3.2.0.2, published 3 April 2019.
- 3.4.x: not affected.
Indicators of compromise
- A gem folder named
bootstrap-sass-3.2.0.3. - The file
lib/active-controller/middleware.rbinside the gem. - Requests with a cookie named
___cfduid(three underscores) in web server or proxy logs. - SHA256 of the 3.2.0.3 gem, per Snyk:
366d6162fe36fc81dadc114558b43c6c8890c8bcc7e90e2949ae6344d0785dc0.
How to check
Look for version 3.2.0.3 in your lock file and installed gems. Then search your logs for the three-underscore cookie.
grep -n "bootstrap-sass" Gemfile.lock gem list bootstrap-sass grep -rF "___cfduid" /var/log/
What to do now
- Run
bundle update bootstrap-sassto reach 3.2.0.4 or later. Commit the new Gemfile.lock and redeploy every production host that ran 3.2.0.3. - Search logs from 26 March 2019 onward for the
___cfduidcookie. A match means someone sent code to the app. - If a match exists, treat the server as compromised. Rotate the secrets that the app can read, such as database passwords, API keys and session secrets.
- Pin gem versions in the lock file and review each new gem version before you deploy it.
Frequently asked questions
How many installs did the bad version get?
LWN reports 1,477 downloads of 3.2.0.3. Snyk estimates about 1,670 repositories that use the gem directly.
Was the code in the GitHub repository?
No. It was only in the published gem. Derek Barnes found it by comparing the gem with the source.
Did the backdoor run in development?
No. According to the reports, the code runs only when the Rails app is in production mode.
Sources
Send this page to the person who looks after AI at your company.