Topic 3 of 5 · 5 min read
CI workflow changes and pipeline security
Goal: Spot the insecure trigger, permission or unpinned action in an AI-written CI workflow and correct it.
A CI workflow runs code with your secrets, so every line that widens its permissions or trusts outside input is a security change.
Check yourself · 1 of 3
Why is pull_request_target risky when combined with checking out the pull request's code?
Why it matters
CI is a machine that can push images, deploy and read secrets. An agent asked to "make CI faster" or "run tests on forks" will often copy a snippet from the web. A single risky trigger can let a stranger's pull request read your secrets. The GitHub documentation on secure use of Actions covers these cases; the examples here use GitHub Actions, but the ideas apply to GitLab CI and others.
What to check
- Triggers.
pull_request_targetruns with secrets and a write token in the context of the base repository. If the workflow also checks out and runs the pull request's code, untrusted code gets your secrets. Plainpull_requestfrom a fork gets no secrets, which is safer. - Token permissions. Set
permissions:explicitly and as low as possible, for examplecontents: read. A workflow with no block may get broad defaults. - Unpinned actions.
uses: some-org/action@mainor@v1can change under you. Pin third-party actions to a full commit hash. - Secrets in the wrong places. Secrets echoed to logs, passed to steps that do not need them, or exposed to a step that runs code from a pull request.
- Script injection. Putting
${{ github.event.pull_request.title }}straight into arun:step lets the title execute as shell. Pass it through an environment variable instead. - Deploy gates. Did the agent remove a required approval, a protected environment, or a failing test step "to make CI green"?
Before and after
on: pull_request_target
jobs:
test:
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
- run: npm test
This checks out the fork's code in a context that holds secrets, then runs it. The fix is to use pull_request, add permissions: contents: read, and keep any secret-using job separate from code you did not write.
What goes wrong
- The agent makes a red pipeline green by skipping or deleting the failing step.
- A new action from an unknown publisher is added with a moving tag.
- A workflow gets
permissions: write-allbecause "it was failing on permissions".
Examples
Green by deleting
The pipeline fails on a flaky integration test. The agent's diff removes the npm run test:integration step and the PR says "CI now passes". The check is green because the check was deleted. Ask for the fix of the test or a clearly tracked skip.
Title injection
A step runs echo "New PR: ${{ github.event.pull_request.title }}". A pull request titled with a shell command in quotes runs that command on the runner. Pass the title as an environment variable and quote it in the script.
Key points
- Treat edits to workflow files as security changes, even when they look like speed-ups.
- pull_request_target plus checkout of the pull request's code puts secrets within reach of untrusted code.
- Declare minimal permissions for the token in every workflow.
- Pin third-party actions to a full commit hash, not a moving tag or branch.
- Never put untrusted text such as a PR title directly into a run step.
Common mistakes
- Reviewing the application diff and waving through the
.githubfolder. - Accepting write-all permissions to silence a permission error.
- Pinning to a version tag and assuming it never moves.
- Counting a green pipeline as proof when the agent edited the pipeline.
Check yourself · 2 of 3
Which is the safest way to reference a third-party action?
Check yourself · 3 of 3
An agent fixes a failing CI job by deleting the failing test step. What is the right response?
Practice items, not counted towards your mastery.
Start here
- strong_migrations: catch unsafe migrations in development (opens in a new tab)ToolFree
A catalogue of unsafe migration operations with the safe alternative for each.
- Parallel Change (martinfowler.com) (opens in a new tab)ArticleFree
The expand, migrate, contract pattern behind safe schema changes.
- terraform plan command (HashiCorp docs) (opens in a new tab)DocsFree
What plan output means and how to save and review a plan before apply.
More for this topic
- Secure use reference (GitHub Actions) (opens in a new tab)DocsFree
Token permissions, risky triggers, pinning and secrets handling in workflows.