---
name: review-github-actions-security
description: Reviews GitHub Actions workflow files for script injection, privileged triggers, broad token scopes and mutable action refs. Use when the user asks if a workflow is safe, wants third-party actions pinned to a commit SHA, or uses pull_request_target.
license: MIT
metadata:
  category: deployment
  tags: "security,github-actions"
  author: johnny-bravo
  version: "1.0"
  updated: "2026-11-07"
  status: published
  aliases: "harden-github-actions-workflows, actions hardening, pull_request_target, pin actions to sha"
  source_url: "https://github.com/github/awesome-copilot/tree/5269f7ea2d6c3a9bfda5ed878b6726cf509121fd/skills/github-actions-hardening"
  source_license: MIT
  copyright: "Copyright GitHub, Inc."
  original_author: "GitHub awesome-copilot contributors (github-actions-hardening)"
  modified: "Adapted by TheSkillVault: rewritten as a short review order (triggers, injection, permissions, SHA pins, secrets) with one original example; dropped the reference-file catalogue and severity emoji table; added gotchas and done-when."
  imported_on: "2026-11-07"
---

# Review GitHub Actions security

A workflow can run attacker-controlled text as shell. The risky part is the YAML, not the product code. Review the trigger, then the expressions, then the token, then the action refs.

## When to use
- Someone asks whether a workflow is safe to merge.
- A job uses `pull_request_target`, `workflow_run` or `issue_comment`.
- Third-party actions are referenced by a tag or a branch name.

## When not to use
- The task is to add lint and tests on each push. That is a CI setup task.
- The task is to cut minutes or spend. That is a cost review.
- The failure is a red check and the user wants the log explained. Fix the check first.

## Steps
1. Read every `on:` trigger. `pull_request` from a fork gets a read-only token and no secrets. `pull_request_target`, `workflow_run` and `issue_comment` run with the base repo's token and its secrets, and an outsider can fire them.
2. Flag a privileged trigger that checks out a fork ref and then runs that code (`npm install`, a build, or any lifecycle script). Split it: an unprivileged `pull_request` job runs the untrusted code, and a later job only reads its result.
3. Treat `${{ }}` inside `run:` as pasted text, not as a variable. Move untrusted values into `env:` and read them as `"$TITLE"` in the script. Issue titles, pull-request bodies, branch names and comment bodies are untrusted.
4. Set `permissions` at the top. Prefer `contents: read`. Grant a write scope only on the job that needs it. Flag a missing block and flag `write-all`.
5. Pin third-party `uses:` to a full 40-character commit SHA, with the version in a trailing comment. A tag or `@main` can be moved. First-party `actions/*` are lower risk. SHA pins are still safer.
6. Do not print secrets. Do not pass secrets into a step that runs untrusted code. Set `persist-credentials: false` on checkout when a later step runs code you do not trust.
7. Prefer GitHub-hosted runners for a public repo. A self-hosted runner can keep files from a previous untrusted job.
8. Report findings with the file, the line, the risk and a corrected snippet. Do not change the workflow until the user accepts the fix.

```yaml
permissions:
  contents: read
jobs:
  show:
    runs-on: ubuntu-latest
    steps:
      - env:
          TITLE: ${{ github.event.issue.title }}
        run: printf '%s\n' "$TITLE"
```

## Gotchas
- A normal `pull_request` job from a fork is not critical by itself. It cannot read secrets. Reserve the highest severity for privileged triggers and for injection on those triggers.
- Writing raw user text to `$GITHUB_ENV` or `$GITHUB_OUTPUT` can inject extra lines. Pass it through an env var instead.
- A secret, cloud key or API token must not be echoed. Prefer a short-lived OIDC token over a long-lived cloud key stored in the repo.
- SHA pins do not update themselves. Bump them on purpose and read the diff.

## Portability
These rules are for GitHub Actions. If you use GitLab CI or another runner, the same rule holds: untrusted input must not be pasted into a shell, and the job token should be as small as the job.

## Done when
- No untrusted `${{ }}` sits inside a `run:` script.
- Privileged triggers do not execute fork code.
- `permissions` is set, third-party actions are SHA-pinned, and no secret is printed.

## Example prompt
"Review .github/workflows/ci.yml. It uses pull_request_target and checks out the fork head. Tell me what is unsafe and show a safer snippet."

---
Adapted from "github-actions-hardening" in github/awesome-copilot (MIT, Copyright GitHub, Inc.). See LICENSE.txt.
