The humble buildspec.yml
A public repository's build configuration allowed pull requests to modify deployment scripts, and the build job for pull requests used the same privileged role as production deployments. An attacker could open a pull request that runs arbitrary commands and uploads files to the production bucket, potentially taking over the site.
While developers have a keen nose for code smells us operations types have a keen nose for infrastructure smells. When I opened this git repository for first time it hit me.
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
The build job triggered by pull requests used the same privileged IAM role as production deployments, and the deployment logic was controlled by a script that could be modified in the pull request.
Impact
An attacker could upload arbitrary files to the production website, potentially defacing it or serving malicious content, and the deployment role might have had broader access to other cloud resources.
What the attacker needed
Public repository with buildspec.yml; ability to open a pull request; no approval needed for PR builds
The fix
Use a separate, limited IAM role for pull request builds and keep build scripts in a separate repository that pull requests cannot modify.
How it was found
- Find a public repository containing a buildspec.yml that references a deploy.sh script.
- Notice that the deploy.sh script checks the branch and pull request status to decide whether to deploy.
- Modify the deploy.sh script in a pull request to run arbitrary commands, such as uploading a file to the production S3 bucket.
- Open a pull request, which triggers a CodeBuild job that executes the modified script.
- Observe that the file appears on the production website.
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.
When you open a pull request on a public code repository, automated systems often run tests or builds. Here, that build process had permission to deploy to the live website, and the instructions for deployment were stored in a file that the pull request could change. So anyone could submit a pull request that quietly added commands to upload their own files to the production site.