Cloudflare Pages, part 1: The fellowship of the secret
Cloudflare Pages build environments had multiple command injection and privilege escalation flaws, allowing an attacker to execute arbitrary commands and access sensitive secrets such as GitHub private keys and Cloudflare API tokens. This could lead to read and write access to all 18,290 users' repositories connected to Cloudflare Pages.
Before we get into this lengthy post, we’d like to thank both Cloudflare and HackerOne for working with us on these vulnerabilities. The process of reporting, remediating and validating these problems was undertaken with the utmost professionalism and diligence by all parties.
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, user-controlled build settings (root directory and output directory) were passed unsafely into shell commands, and overly permissive file permissions and PATH entries allowed privilege escalation.
Impact
An attacker could gain read and write access to all 18,290 users' repositories that had granted Cloudflare Pages access, and access Cloudflare's internal API tokens.
What the attacker needed
A Cloudflare Pages account; ability to set build configuration; victim has connected a repository
The fix
The issues were fixed by adding server-side validation, escaping arguments, scoping tokens, restricting permissions, and using absolute paths.
How it was found
- Set a malicious root directory via the Cloudflare Pages UI or API, bypassing client-side validation.
- Trigger a build so the injected command runs and dumps environment variables.
- Use the leaked GitHub private key to access repositories via the GitHub API.
- Exploit a world-writable binary to regain access after the first fix.
- Hijack the PATH by creating a malicious bash binary in a writable directory.
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.
Cloudflare Pages is a service that builds and hosts websites from code repositories. The build process ran user-supplied commands without properly checking them, so an attacker could sneak in extra commands to steal secret keys. Those keys then gave access to many users' code repositories.
What is RCE?
Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.