Sub topic 16
Agents in CI and issue automation
This chapter assumes you can read GitHub Actions YAML and Python. It also assumes you know indirect prompt injection, least privilege, and the combination of private data, untrusted input, and an outbound channel from earlier chapters.
Why CI raises the risk
On a laptop, a developer watches the agent and can refuse an action. In CI, an event such as "issue opened" starts the agent, and nobody reviews each step. Anyone who can open an issue can put text in front of it. The job usually also carries a token, and sometimes secrets.
That setup contains all three parts of the dangerous combination. The secrets and token are the private data. The issue text is the untrusted input. Comments, commits, and network calls are the outbound channel.
Common mistakes
- Putting
${{ github.event.issue.title }}directly inside arun:script. The text becomes shell code, so no model is needed for the attack. - Leaving the token's default permissions broad, so a hijacked agent can write code.
- Giving the agent job secrets it does not need.
- Running triggers that check out pull request code while secrets are available.
- Executing the agent's output, such as a suggested command, without checking it.
- Letting the agent post free-form comments. A comment containing a crafted URL can leak data.
A safer baseline
This workflow grants only the permissions it needs. It passes the title through an environment variable, so the shell treats it as data.
name: triage
on:
issues:
types: [opened]
permissions:
contents: read
issues: write
jobs:
label:
runs-on: ubuntu-latest
steps:
- name: Handle issue title as data
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
run: printf 'Title: %s\n' "$ISSUE_TITLE"Any agent step you add should follow the same pattern: minimal permissions, untrusted text only as data, and no secrets in its environment.
Design rules
- Split reading from writing. Run the agent in a job with a read-only token. It returns a structured result, such as a label name. A second job with no model checks that result and applies it.
- Validate output against a fixed list. If the only valid labels are
bug,docs, andquestion, reject anything else. - Limit who can start the agent. Require a maintainer to add a label before the agent reads an outside contributor's issue.
- Keep secrets out of the agent job. Use scoped, short-lived tokens where you need credentials.
- Combine this with a sandbox and a network allowlist, as in earlier chapters.
Review the result
Log every action the agent takes, and check that the second job rejects out-of-list output. Test with a harmless injected issue and confirm nothing changes except an allowed label.
Exercise
A workflow runs an agent when any issue is opened. The job has a write-scoped token and a cloud deployment secret, and the agent can post comments. Name two changes that reduce the risk most.
Show answer
Remove the deployment secret from the agent job, and give the agent a read-only token. Have a separate job without a model apply only validated output, such as an allowed label. Gating the trigger on a maintainer label also helps.