Topic 4 of 5 · 5 min read
Permissions and guardrails for CI agents
Goal: Review a CI agent workflow and find the permission, trigger or secret exposure that lets untrusted input reach a privileged action.
Give a CI agent the smallest token it needs, never let untrusted text reach a privileged step, and keep a human between the agent and main. An agent that can write code, read secrets and push is as powerful as a developer, and it can be steered by anyone who can put text in front of it.
Check yourself · 1 of 3
Which workflow setting best limits the damage if a review bot is tricked by a crafted comment?
Why it matters
The agent reads pull requests, issues and comments. Some of that text comes from strangers. If the workflow also holds a write token or a secret, a crafted comment becomes an attack. CI pipelines are a known target: OWASP lists poisoned pipeline execution and weak access controls among its top CI/CD risks.
What to check in a workflow
- Token permissions. Set
permissions:explicitly and narrowly, for examplecontents: readandpull-requests: write. Do not leave the default broad grant. - The trigger.
pull_requestfrom a fork runs without secrets.pull_request_targetandissue_commentrun with the base repo's secrets and token, so they must never check out and run the fork's code or feed its text into a shell. - Secret exposure. Pass a secret only to the step that needs it. Never echo it, and keep it out of the agent's prompt and environment where possible.
- Script injection. Do not put
${{ github.event.pull_request.title }}directly in arun:line. Pass it through an environment variable. - Protected branches. Require a human review and passing checks, and prevent the bot's token from bypassing them.
- Who can trigger it. Limit agent runs to collaborators.
Before and after
on: issue_comment
permissions: write-all
steps:
- run: echo "${{ github.event.comment.body }}"
Anyone can comment, the token can write everything, and the comment is pasted into a shell. Fixed:
on: issue_comment
permissions:
contents: read
issues: write
jobs:
triage:
if: github.event.comment.author_association == 'MEMBER'
steps:
- env:
BODY: ${{ github.event.comment.body }}
run: ./triage.sh
What goes wrong
- Pwn requests.
pull_request_targetplus a checkout of PR code runs attacker code with secrets. - Over-wide tokens. A review bot with
contents: writecan push to branches. - Auto-merge by the agent. No human sees the change before it ships.
Examples
The pwn request
A workflow runs on pull_request_target, checks out the PR's head commit and runs npm test. A stranger's PR edits package.json so the test script prints the repository token. The fix is to run untrusted code under pull_request, with no secrets, and to keep privileged steps separate.
Narrow token, narrow damage
A review bot only needs to read code and post comments. Setting contents: read and pull-requests: write means that even a fooled bot cannot push a commit.
Key points
- Set permissions explicitly and narrowly instead of using a broad default token.
- Triggers such as pull_request_target and issue_comment carry secrets, so they must not run untrusted code or text.
- Pass untrusted values through environment variables, never straight into a shell command.
- Branch protection with required human review stops an agent from merging its own work.
- Restrict who can start an agent run, for example to repository members.
Common mistakes
- Leaving
permissionsunset and trusting the default. - Using pull_request_target and then checking out the fork's code.
- Interpolating
${{ ... }}event text directly intorun:steps. - Letting a bot approve or merge its own pull request.
Check yourself · 2 of 3
Why is checking out a fork's code under pull_request_target dangerous?
Check yourself · 3 of 3
A step runs: echo "${{ github.event.pull_request.title }}". What is the risk?
Practice items, not counted towards your mastery.
Start here
- Using GitHub Copilot code review (GitHub Docs) (opens in a new tab)DocsFree
How to request a Copilot review and tune it with custom instructions.
- Claude Code GitHub Actions (opens in a new tab)DocsFree
Setup, permissions and a CLAUDE.md-driven workflow for an agent that runs inside Actions.
- Secure use reference (GitHub Actions) (opens in a new tab)DocsFree
Script injection, secrets, GITHUB_TOKEN permissions and untrusted-input guidance for workflows.
More for this topic
- Preventing pwn requests (GitHub Security Lab) (opens in a new tab)ArticleFree
Why pull_request_target plus a checkout of PR code is dangerous, with safe patterns.
- About protected branches (GitHub Docs) (opens in a new tab)DocsFree
Required reviews and status checks that keep a bot from merging on its own.