How we exploited CodeRabbit: From simple PR to RCE and write access on 1M repos
CodeRabbit ran the Rubocop linter on pull request code without sandboxing, and Rubocop's config file could load an arbitrary Ruby extension, so an attacker could execute code on CodeRabbit's production servers. This leaked environment variables including the GitHub App private key, which could give read and write access to roughly one million repositories.
research.kudelskisecurity.com
Published on research.kudelskisecurity.com
In this blog post, we explain how we got remote code execution (RCE) on CodeRabbit’s production servers, leaked their API tokens and secrets, how we could have accessed their PostgreSQL database, and how we obtained read and write access to 1 million code repositories, including private ones.
The full write-up lives on its author's site
It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the external linter was executed outside a secure sandbox and was allowed to load a configuration-specified extension file from the untrusted pull request.
Impact
An attacker could run code on production servers, leak many secrets including the GitHub App private key, and potentially read or write to about one million repositories, including private ones.
What the attacker needed
A free CodeRabbit trial account; a GitHub account; a repository with CodeRabbit installed; ability to open a pull request
The fix
The issue was fixed by relocating Rubocop into a secure sandbox environment and rotating all impacted credentials.
How it was found
- Register for a free trial using a personal GitHub account
- Create a private repository and grant CodeRabbit access so it reviews pull requests
- Create a pull request containing a Rubocop config that requires an extension file, the extension file with malicious Ruby code, and a large enough dummy Ruby file
- Wait for CodeRabbit to run the code review and execute the extension file
- Collect the exfiltrated environment variables from the attacker-controlled server
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.
CodeRabbit is a bot that reviews code changes on GitHub. It ran a checking tool called Rubocop on the submitted code, and that tool could be told to load extra Ruby code from the repository. Because the tool ran on CodeRabbit's own servers, the attacker's code ran there too and could read the server's secret settings.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.