Sub topic 16
Agents in CI and issue automation
This chapter assumes you can read GitHub Actions YAML and basic Python. You should also know the earlier ideas: indirect prompt injection, the combination of private data, untrusted input and an outbound channel, and least privilege.
Why CI changes the risk
An agent on your laptop has a person watching it. An agent in CI usually has none. It runs when an event fires, such as an issue opening, a pull request arriving, or a comment containing @agent. The person who triggers it may be a stranger on the internet.
Three things make this worse:
- The trigger is attacker-controlled. Anyone who can open an issue on a public repository can put text in front of your agent.
- Approval gates are usually gone. There is no human to click "deny", so the only controls are the ones you configured in advance.
- Credentials are close by. CI runners hold a repository token, often cloud credentials, and a model API key.
The dangerous combination from the previous chapters is therefore often present by default. Private data is the repository and its secrets. Untrusted input is the issue or pull request text. The outbound channel is the network, a comment, or a commit.
Which triggers carry attacker text
Not every trigger is equally risky. What matters is who controls the content and what the job can access.
| Trigger | Who controls the text | Secrets and write access | Risk |
|---|---|---|---|
| `issues`, `issue_comment` | Anyone on a public repo | Available to the job | High if the agent has tools |
| `pull_request` from a fork | Fork author | Read-only token, no secrets | Lower, but the agent still reads hostile text |
| `pull_request_target` | Fork author | Base repository token and secrets | Very high if you check out or run PR code |
| `push` to protected branches | Maintainers | Available | Lower |
| `workflow_run` after a fork PR | Fork author, indirectly | Often has secrets | High, because artifacts are attacker data |
The row to remember is pull_request_target. It exists so maintainers can label or comment on fork PRs. If the job also checks out the PR head and runs an agent or a build there, the fork author's code and text run with your secrets.
Failure modes
- Shell interpolation. Writing
${{ github.event.issue.title }}inside arun:script pastes the title into the script before the shell parses it. A title containing"; curl ...becomes commands. This is classic script injection, and it needs no language model at all. - Agent with write tools. An injected instruction in an issue tells the agent to push a commit, edit a workflow file, or comment with data from its environment.
- Poisoned context carried across jobs. One job summarizes an issue, and a later privileged job trusts the summary. The summary is still derived from attacker text.
- Over-broad tokens. The default
GITHUB_TOKENmay have write access to contents, packages, and pull requests, depending on repository settings. - Cache and artifact poisoning. A low-trust job writes a cache entry or artifact that a high-trust job later consumes.
Design pattern: split reading from acting
The most useful structure separates the job that reads untrusted text from the job that changes anything. The reading job is the only one that runs the model. It gets minimal permissions, and it can output only a small value. The acting job never sees the raw text. It validates the value against a fixed list before using it.
Here is a workflow that implements it:
name: triage
on:
issues:
types: [opened]
permissions: {}
jobs:
classify:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
label: ${{ steps.pick.outputs.label }}
steps:
- uses: actions/checkout@v4
with:
persist-credentials: false
- name: Classify issue as data
id: pick
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
run: |
label="$(python .github/scripts/classify.py | head -n 1)"
echo "label=${label}" >> "$GITHUB_OUTPUT"
apply:
needs: classify
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- name: Apply allowed label
env:
GH_TOKEN: ${{ github.token }}
LABEL: ${{ needs.classify.outputs.label }}
ISSUE: ${{ github.event.issue.number }}
REPO: ${{ github.repository }}
run: |
case "$LABEL" in
bug|feature|question)
gh issue edit "$ISSUE" --repo "$REPO" --add-label "$LABEL" ;;
*)
echo "unexpected label, refusing" >&2
exit 1 ;;
esacSeveral choices here matter:
permissions: {}at the top removes every default permission. Each job then adds back only what it needs.- Issue text reaches the shell through
env:and is only read as variables. It is never pasted into the script text. persist-credentials: falsestops the checkout step from leaving the token in the local git configuration, where a tool could read it.head -n 1limits the output to one line, so the model cannot write extraname=valuelines into$GITHUB_OUTPUT.- The
applyjob has write access to issues but runs no model. Theclassifyjob runs the model but cannot write anywhere.
A successful injection in the issue can at worst choose among three labels.
Handling the model credential
The classify job still needs a model API key, and that key is a secret the job holds. Reduce what it can cost you:
- Use a key dedicated to this workflow, with a spending cap.
- Run the job in an environment with no other secrets, so a leak exposes one cheap key.
- Never give the agent step access to cloud credentials, deploy keys, or a personal access token.
- Prefer short-lived credentials from OIDC federation over stored long-lived ones when the model provider supports it.
Further controls for agentic CI jobs
If the agent must have tools, such as running tests in a pull request:
- Run it on a fork-safe trigger (
pull_request), notpull_request_target. - Run commands through an allowlist wrapper, as in the tool-wrapper example from the least-privilege chapter.
- Block network access except to named hosts, using runner-level egress controls or a container with
--network none. - Require a maintainer to apply a label or approve a deployment environment before an agent runs on a first-time contributor's pull request.
- Keep agent output as a comment or a proposed patch. Do not let it push to protected branches. Branch protection and required human review remain the final gate.
- Log every tool call, and keep the logs where the job itself cannot edit them.
Common mistakes
- Treating "it only comments" as safe. A comment can contain a Markdown image URL with secrets in the query string, and it is visible to everyone on a public repository.
- Trusting the agent's own refusal as the control. Models can be talked out of refusing.
- Letting the agent edit
.github/workflows. A workflow change is a privilege escalation. - Reusing one token for triage, build, and release.
Exercise
A workflow triggers on issue_comment, checks out the repository, and runs an agent with a run: step containing agent --prompt "${{ github.event.comment.body }}". The job has contents: write and a cloud deploy key in its environment. Name two separate problems and one fix for each.
Show answer
First, the comment body is interpolated directly into the shell script, so a comment containing shell syntax runs commands (script injection). Fix it by passing the body through an env: variable and referencing it as a quoted variable. Second, the job combines untrusted input, powerful credentials (the deploy key and write access), and an open network, so an injected instruction can steal or misuse them. Fix it by splitting the job so the model-running part has contents: read, no deploy key, and restricted egress, with any write action done by a separate job that validates a small allowlisted output.