Claude Code in GitHub Actions: Lock It Down First
A pre-flight review for claude-code-action: permissions, who can trigger it, fork PRs, .mcp.json, secrets, SHA pinning and cost limits, each tied to a source.
In this post
- What went wrong in the real disclosures
- 1. Which workflow permissions does the job need?
- 2. Does it need id-token: write?
- 3. API key or OAuth token?
- 4. Who can trigger it?
- 5. Are you using pull_request_target?
- 6. Which tools can it run?
- 7. What about .mcp.json in a PR?
- 8. What secrets are in the environment?
- 9. Should you pin the action to a commit SHA?
- 10. What stops a runaway job?
- What I’d turn on first
- Before you enable it
Claude Code in GitHub Actions runs on a runner that holds a token and
your secrets, and it reads text that strangers can write: PR
descriptions, issue comments, review comments, and files like
.mcp.json in a pull request. Anything it reads can try to
give it instructions. Most of the checklist below is about shrinking
what that runner can reach and who gets to start it.
I run 6 to 10 Claude Code agents a day, locally and on cron. I don’t run it in GitHub Actions today. I was CISO at Lavender, so this is the review I’d do before turning it on. Ten checklist items, each tied to a primary source, then the narrowest job I’d start with.
What went wrong in the real disclosures
Two disclosures cover most of what you need to know.
The first is GHSA-8q5r-mmjf-575q
(CVE-2026-47751). Per the advisory, the action checked out the PR head
branch, read .mcp.json from the working directory, and
enabled all project MCP servers. So “an attacker who opened a PR
containing a malicious .mcp.json file” could run arbitrary
code on the runner and reach the workflow’s secrets, once a privileged
user or an automatic trigger invoked the action on that PR. The advisory
rates it medium (GitHub shows Moderate), CVSS v4 5.3, and lists versions
below 1.0.74 as affected. Tenable’s
write-up of the same CVE gives a different fixed version, so I’d say
it was fixed in later releases and check the advisory for the exact
number.
The second is a June 2026 write-up by RyotaK at GMO Flatt Security,
Poisoning
Claude Code: One GitHub Issue to Break the Supply Chain. The
researcher found that the permission check treated any actor whose name
ended in [bot] as having write access. RyotaK also found
that Anthropic’s own issue-triage workflow shipped with
allowed_non_write_users: "*", so anyone could trigger it.
The exfiltration path was a prompt injection that got Claude to read
/proc/self/environ, which exposes the process’s environment
variables, then write them back into an issue. Flatt says Anthropic
rated the issues 7.8 under CVSS v4.0, and that “Variants of the
misconfiguration issues described in this article were actively
exploited in the wild before this article was published.” Both are
Flatt’s claims; I haven’t verified either. Flatt also says the issues
are now mitigated. allowed_non_write_users is still a
setting you can turn on (item 4).
1. Which workflow permissions does the job need?
Probably fewer than the example grants. The example
workflow in the action’s repo sets contents: write,
pull-requests: write, issues: write,
id-token: write and actions: read. GitHub’s
advice: “As
a good security practice, you should grant the GITHUB_TOKEN the least
required access.”
For a job that only comments on PRs, I’d start here and add only what a failing run proves it needs:
permissions:
contents: read
pull-requests: write
id-token: writeThat is the block in Anthropic’s PR
review example. The general example adds actions: read
so Claude can read CI results. I’d leave it off a reviewer, because the
security doc says job logs are “text the pull request controls”. Set the
repo’s default token permission to read-only too, so a workflow that
omits the key doesn’t get a broad token.
That block scopes GITHUB_TOKEN, and it may not be the
token that matters. With github_token omitted, the action
authenticates as the Claude GitHub App, and the security
doc lists the App’s Contents permission as Read & Write. I
couldn’t find whether Anthropic’s token exchange narrows that token to
your permissions: block, so I don’t count on it. The tool
list and permission mode in item 6 are what keep a review job to
comments. The security doc does describe one token that follows the
block: passed as github_token: ${{ secrets.GITHUB_TOKEN }},
the workflow token “is scoped to the job’s declared permissions and
expires when the job completes.” The usage doc says to set
github_token only for a custom GitHub App of your own, so
I’d ask Anthropic before relying on that.
2. Does it need id-token: write?
Yes, for most setups. Anthropic’s docs say it is required for the action’s default GitHub App authentication, and the setup docs say the default path already requires it. Bedrock and Vertex OIDC and workload identity federation need it too.
GitHub says the permission “does not give the workflow permission to modify or write to any resources”. It lets the job request an OIDC token. Flatt’s attack went after the variables that request that token, which live in the process environment. So I’d grant the permission and spend the effort on what sits in the environment (item 8).
3. API key or OAuth token?
For a secret shared across repositories, use an API key from the
Claude Console. Anthropic says so
directly, because an OAuth token is tied to the subscription of the
person who ran claude setup-token. I’d add a reason the
docs leave out: a personal token in a shared secret is tied to one
person’s account, so it becomes an offboarding problem the day that
person changes roles. The docs also say that with an OAuth token, runs
use your Claude subscription instead of API billing. The cost post makes
the same point: a CI job needing a credential the whole team shares is
one of three cases that belong off the subscription.
4. Who can trigger it?
By default, only people with write access. The security doc says the action “can only be triggered by users with write access to the repository”, and that GitHub Apps and bots cannot trigger it by default. Three settings loosen that. I’d leave them alone:
allowed_non_write_users. The security doc calls it “a significant security risk” that “should only be used for workflows with extremely limited permissions”. When it is set, the action scrubs secrets from subprocess environments, which the same doc says “reduces but does not eliminate prompt injection risk”. Flatt’s advice is to expose no secrets beyond the Anthropic API key andGITHUB_TOKENwhen it is on.allowed_bots. It warns “Allowed bots are not checked for repository permissions.” It says to prefer an explicit list over'*', because any such App “can invoke this action with a prompt it controls”. Flatt’s[bot]bypass is why I’d take that literally.allow_fork_prs. The action skips PRs from forks by default. The same doc notes it used to default totrue. The skip does not fail the job: the action logs a warning and the step succeeds without Claude’s outputs, so a required check that only runs the action passes without a review.
On a public repo, also look at GitHub’s “Require approval for all external contributors” setting. Anthropic’s separate security-review action recommends it, because that action “is not hardened against prompt injection attacks and should only be used to review trusted PRs.” No source I read says whether that setting alone covers the issues above.
5. Are you using pull_request_target?
Avoid it. GitHub’s event docs say: “Avoid
using this event if you need to build or run code from the pull
request.” Anthropic’s security doc says
pull_request_target and workflow_run run with
the base repository’s secrets, and adds: “Do not check out an untrusted
ref into the workspace root before this action.” If a workflow needs
pull_request_target, I would want the reason written in the
PR that added it.
6. Which tools can it run?
Tool restriction is where most of your control sits. The action runs
Claude in auto mode by default. Anthropic’s security doc has a heading
that reads “Auto
mode is a review, not a boundary” and explains that “a call can
still run if the review passes it.” For a strict list of what Claude may
run, it points to --permission-mode acceptEdits or
default.
So pair a permission mode with an explicit allow list, and add deny rules for anything you never want:
claude_args: |
--permission-mode default
--allowedTools "Read,Grep,Glob"
--disallowedTools WebSearchThe older allowed_tools inputs are deprecated in favor
of claude_args. Per the security doc, a deny rule for git
add, commit or push passed in claude_args also covers the
action’s wrapper scripts. In a settings file it does not. That list is
read-only, and I haven’t tested it in this action. Anthropic’s PR
review examples add
mcp__github_inline_comment__create_inline_comment and
Bash(gh pr comment:*) so Claude can post what it finds. The
FAQ says most Bash commands are denied in default mode
unless allowed, so add those two for a job that comments.
Flatt’s exploit leaned on Claude Code running commands like
cat without asking, which argues for a short allow
list.
7. What about .mcp.json in a PR?
This is the advisory above, and the fix is now documented behavior.
The security doc says the action restores a fixed list of Claude
configuration paths from the PR base branch before starting Claude,
including .claude/, .mcp.json,
CLAUDE.md and AGENTS.md. So a PR can’t swap in
its own MCP servers or CLAUDE.md, on a version that has the
fix. If you pin an old SHA (item 9), you pin the bug too. The same doc
says “Issues and comments from outside contributors still reach Claude”,
so the restore doesn’t close prompt injection.
The action also has restrict_untrusted_prs, which
defaults to true. On PRs from authors without write access,
it denies commands that commonly run code from the checkout, even if
your claude_args allow them.
My checklist for vetting a Claude Code skill or plugin is the local version: read every hooks file and MCP config before it runs.
8. What secrets are in the environment?
Everything you pass to the job, and anyone who can prompt-inject the agent can ask for it. My post on the 1Password GitHub breach covers the org-level side, where 1Password says one employee’s account reached source code and CI/CD. Three moves help:
- Pass the job only what it needs. A PR reviewer needs the Anthropic credential and a token, not your deploy keys or database URL. The principle from my agent secrets post holds here: the model never needs the key, and the tools that run for it should hold the narrowest credential that does the job.
- Put anything sensitive behind a GitHub environment with required reviewers. GitHub says a job that references an environment “must follow any protection rules for the environment before running or accessing the environment’s secrets”. The secrets stay out of reach until a person approves the run.
- Prefer short-lived credentials. With OIDC your workflow exchanges a
short-lived token with the cloud provider, so no long-lived key sits in
a secret. GitHub’s secrets
doc also says that, apart from
GITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository.
Prompt injection defense for a small team names the pattern to avoid: private data, untrusted content and a way to send data out, all in one agent context. A CI job with secrets, PR text and network access has all three by default, so remove one.
9. Should you pin the action to a commit SHA?
I would, unless you adopt a lockfile. GitHub’s hardening guide now ranks a workflow dependency lockfile first and says it “supersedes SHA pinning for repositories that adopt it”. Otherwise it says to “Pin references to actions to a commit SHA in your workflow files”, because a bad actor would need a SHA-1 collision to backdoor it. A tag can be moved.
Anthropic’s docs don’t make this recommendation. Their examples use
@v1. The advisory goes the other way for one case: people
on @v1 got the .mcp.json fix automatically,
while pinned users had to update. Pinning protects you from a bad
release and delays fixes. Pin to a SHA and watch the repo’s security
advisories.
- uses: anthropics/claude-code-action@<full-commit-sha>10. What stops a runaway job?
Three of Anthropic’s cost
tips cap a run: set --max-turns in
claude_args, set workflow-level timeouts, and use GitHub’s
concurrency controls to limit parallel runs. Runs also consume GitHub
Actions minutes. The docs give no recommended numbers for any of these.
Start with limits tight enough that a normal review barely fits, and
raise them when a real run gets cut off.
What I’d turn on first
One job: review comments on pull requests from people with write access. Nothing else.
- A trimmed
permissions:block, knowing the App token can still write contents. - A short read-only tool list, with a strict permission mode.
- No
allowed_non_write_users, noallowed_bots, forks left at the default skip. - An API key scoped to this job, in a secret that holds nothing else.
- A turn limit, a job timeout and a concurrency group.
- The action pinned to a SHA.
That job fits the action’s defaults. Per the security doc, Claude
does not create pull requests automatically, and only write-access users
can trigger it. It reads, and it writes comments. If those hold and it
gets tricked, the damage is a bad comment, which is cheap compared with
a pushed commit. Issue triage, auto-fix and anything needing
contents: write would wait until that job had run for a few
weeks and I had read its logs. It should sit on top of deterministic
checks that already block merges.
Before you enable it
Open your repo’s settings and write down the default
GITHUB_TOKEN permission, whether outside contributors need
approval to run workflows, and which secrets exist at the repo level.
Those answers decide how much of this list applies to you. For another
set of eyes, a vCISO review before you turn it
on takes this checklist and applies it to your actual workflow files
and secrets.
I read the docs quoted above on November 26, 2026. They change often, so check the current text before you rely on a default.