Skip to the page

CI/CD for developers · senior

Pipeline security: untrusted input and deploy credentials

A pipeline runs code with deploy credentials, so every input that an outsider controls is a way in: comments, pull request code, branch names and runners that keep state.

The notes

What you must know

  • issue_comment fires for any commenter on a public repository. A workflow that checks only the comment text lets any stranger start a deploy. Check the commenter's permission (author_association or a team membership call).
  • Checking out a pull request's code and running ./scripts/deploy.sh from it lets the attacker write the script that runs with deploy credentials. Run trusted code from the base branch.
  • Script injection: pasting ${{ github.event.comment.body }} into a shell command lets a comment containing a quote break out and run anything. Pass it through env: and validate against a fixed list.
  • A persistent self-hosted runner inside production keeps files and credentials between runs, so one bad run affects later runs. Use ephemeral runners and keep untrusted builds away from production networks.
  • Least privilege: set permissions: for the GITHUB_TOKEN to the minimum, use environment protection with required reviewers for production, and OIDC with a role limited to one repository, branch and environment.
  • Pin third-party actions to a commit SHA. Treat pull requests from forks as untrusted: pull_request_target and secrets are risky together.
  • Never print secrets. Masking is not complete, so also avoid passing them through logs and artifacts.

The red pen

Common traps: mistake → fix

  • Mistake: A private repository means everything in the pipeline is trusted

    Fix: Contributors, forks, comments and dependencies still bring untrusted data.

  • Mistake: If the workflow checks the text of the comment, it is safe

    Fix: It must check who wrote it.

  • Mistake: Secrets are masked in logs, so they cannot leak

    Fix: Encoding or splitting can leak them. Reduce secret exposure.

Easy to hard

Questions interviewers ask, easy to hard

  1. What is script injection in a CI workflow?
  2. Why is a comment-triggered deploy dangerous on a public repository?
  3. How do you give CI access to AWS without stored keys?
  4. Why are persistent self-hosted runners risky?
  5. Review this workflow and list every security problem.

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview