Skip to navigation

Claude Code GitHub Actions: Keeping Secrets Away from Prompt Injection

In short: Microsoft documented a prompt-injection pathway that could expose CI/CD secrets. Separate untrusted content from credentials and default tokens.

Published 19 min read
On this page

Direct answer

Isolate untrusted issue, pull-request and repository content from any job that holds CI/CD secrets or broad write tokens. Give the agent a read-only workspace, explicit tool limits and a separate approval boundary before privileged work runs.

Security research. Microsoft documented a prompt-injection pathway in the Claude Code GitHub Action that could expose workflow secrets. That finding does not establish an Anthropic infrastructure breach. It shows why credentials must be separated from content the model can read. The practical win is a smaller blast radius. The honest loss is a more complicated pipeline: untrusted analysis and privileged actions should not share one environment.

Why CI changes the security problem

A local coding session usually runs with a developer’s context and credentials nearby. CI adds automation, service identities and repository-wide tokens. A prompt-injected action may run without a person watching, and it may execute with permissions that the triggering user does not personally hold.

Untrusted content enters through familiar surfaces: issue titles, issue bodies, pull-request descriptions, comments, diffs and repository files. The model may treat that content as instructions instead of data. If the same job can read a secret and make an external request, a bad model decision can become a credential-exposure event.

Security research. The supplied Microsoft report on the Claude Code GitHub Action documents a prompt-injection pathway that could expose CI/CD workflow secrets. The source does not establish that Anthropic infrastructure was compromised. Preserve that attribution exactly.

The Claude Code harness security boundaries provide the mental model: model output becomes dangerous only when the harness grants authority. CI security therefore starts with authority, not with a better prompt. List what the job can read, what it can change and which network destinations it can reach.

CI evidence map connecting untrusted issue content, agent prompt, workflow token and possible secret exposure
Editorial threat map based on Microsoft security research. The documented pathway concerns workflow secrets and does not establish an Anthropic infrastructure breach.

Understand the documented pathway

Prompt injection happens when untrusted text tries to redirect a model’s behavior. In CI, the text may ask the agent to reveal an environment variable, ignore earlier instructions, call a tool or send data to an external service. The model’s resistance matters, but the security design should not depend on perfect resistance.

The workflow token is part of the path. GitHub Actions jobs receive a token whose permissions depend on configuration. A broad token can turn a read-only task into repository changes or other privileged actions. Secrets add a separate risk because their values may be available to process steps even when the token is narrow.

Microsoft’s documented case is a warning about composition. Untrusted content reached an agent, the agent had tool authority, and the workflow contained credentials or token access that could be exposed. The exact exploit details are not needed to design the defense. The defense is to prevent untrusted content and privileged authority from sharing the same execution boundary.

Path stage Untrusted or privileged element Failure mode Primary control
Trigger Issue, comment or pull request Attacker controls text entering the job Treat trigger content as data
Checkout Repository files and diff Instructions hidden in source or docs Read-only workspace and scoped review
Agent Model proposes tool calls Injected text redirects behavior Narrow tools and explicit permission policy
Process Workflow token and secrets Credentials available to the same runtime Separate privileged job and secret scope
Network External tools and endpoints Data leaves the workflow Allowlisted destinations and egress controls
Output Logs, comments and artifacts Sensitive values are published Redaction and output review

Community. Claude Code Action issue #1817 reports installer false success in CI. That is a reliability report, not proof of the secret-exposure pathway. It matters because a pipeline can continue after setup appears successful when the agent is not actually ready. Fail the job on an unverified install instead of assuming later steps ran.

The Claude Code repository-hook security review explains another executable surface. Hooks can run commands or HTTP calls at session events. A repository-controlled hook should not inherit production secrets merely because the workflow uses an agent.

Start with GitHub token scope

Give each job only the permissions it needs. A job that reads code and posts a review does not automatically need workflow administration, repository administration or broad write access. The exact permissions depend on the task, so write them explicitly and review them when the workflow changes.

Avoid broad workflow permissions. They make the blast radius hard to reason about and can allow one compromised step to affect resources unrelated to the task. A read-only default is easier to audit. Add a narrow write permission only where a specific step requires it.

Do not confuse token scope with secret scope. A read-only token can coexist with a powerful secret in the environment. Conversely, a write token may not need any long-lived secret if it can perform the task through its narrowly scoped identity. Inspect both dimensions separately.

Permission layer Question Safer default Review evidence
Workflow token Which repository operations can this job perform? Explicit minimum permissions Workflow diff and job test
Secret access Which steps receive secret values? No secrets in untrusted jobs Environment and step map
Environment identity What can the runtime process access? Disposable, least-privilege identity Runner and container configuration
Network egress Where can the job connect? Required endpoints only Egress rules and observed traffic
Output rights What can the job publish? Scoped comments or artifacts Output allowlist and redaction

Official. Claude Code’s permissions documentation says rules evaluate deny, then ask, then allow. Enforcement is handled by Claude Code, not the model. It also warns that Bash rules do not stop commands invoked through full paths or wrappers such as sh -c. CI policy should not rely on a single command-string rule.

The Claude Code auto-mode classifier limitations reinforce that point. Auto mode can reduce prompts, but the classifier can block benign actions or allow risky ones when intent is ambiguous. A CI job that must not publish secrets needs deterministic controls, not a general safety judgment.

Hardened CI workflow separating untrusted analysis from privileged approval and secret-bearing jobs
Editorial least-privilege workflow derived from Microsoft’s documented pathway. Exact GitHub permissions and action inputs must be verified against the workflow in use.

Separate the untrusted job from the privileged job

A two-job design is easier to reason about than one job that does everything. The first job checks out code, reads untrusted content and produces a review artifact. It has no deployment secrets and no broad write token. The second job runs only after a trusted approval or a strict policy check and receives only the authority needed for its action.

The artifact crossing the boundary is still untrusted. A review produced by an agent can contain injected instructions or malformed data. Validate its schema, size and allowed fields before a privileged step consumes it. Do not let the artifact choose a shell command, a target repository or a credential.

Approval should be a real boundary. If the same untrusted job can approve its own next step, the separation is cosmetic. Use a protected environment, a trusted reviewer or a deterministic policy gate that the agent cannot modify. The exact mechanism depends on the repository’s risk model.

# Illustrative shape, not a complete production workflow.
permissions:
  contents: read

jobs:
  untrusted_review:
    runs-on: ubuntu-latest
    env:
      AGENT_MODE: read-only
    steps:
      - name: Produce a structured review artifact
        run: ./scripts/review-untrusted-content.sh

  privileged_action:
    needs: untrusted_review
    environment: protected-approval
    permissions:
      contents: read
    steps:
      - name: Validate the artifact before any privileged action
        run: ./scripts/validate-review-artifact.sh

This skeleton deliberately omits secret values and broad write permissions. It is an engineering pattern, not an official Claude Code Action configuration. Adapt it to the action version and repository policy, then test the actual permission map.

The Claude Code proof-of-work packet is useful for the handoff. Require a structured result with evidence references, not a free-form instruction that the next job executes. Validate changed paths, test output and the requested action against an allowlist.

Keep secrets out of prompts and tool output

Secrets should enter the process only when a trusted step needs them. Do not export an entire secret bundle into the agent environment. Use a narrow wrapper or a separate service that receives the minimum value and performs the privileged operation without returning the credential to the model.

Logs deserve the same care. A command that prints an environment variable, a tool that echoes headers or an action that writes a debug dump can expose a secret even when the prompt never contains it. Disable verbose debugging for secret-bearing steps and review logs before publishing artifacts.

The Claude Code settings-file secret exposure guide shows how saved approvals can retain sensitive values. In CI, generated settings files should be treated as artifacts that may contain credentials. Exclude them from the repository and from the review output.

Secret surface Exposure path Control
Environment variables Process or debug output reveals values Scope to trusted steps and redact logs
Settings files Saved rule contains a literal credential Generate outside the repo and scan before upload
Tool configuration MCP or HTTP hook carries a token Separate config and restrict tool scope
Artifacts Debug bundle includes environment data Allowlist files and scan before publication
Comments or reviews Agent repeats sensitive content Structured output with redaction
Caches Workspace or dependency cache stores secrets Exclude sensitive paths and use isolated caches

The Claude Code privacy and retention rules describe provider-side handling, but they do not remove the local CI exposure path. A provider can receive a prompt under one policy while a workflow log publishes a secret to repository readers. Inspect both boundaries.

Official. Claude Code supports command, HTTP, MCP tool, prompt and agent hooks. An HTTP hook can send data to an external service, so its destination and payload become part of the secret boundary. Inspect repository hooks before giving them a secret-bearing environment.

Treat prompt injection as an authority problem

A safer test does not try to find a magic phrase that always defeats the model. It checks whether injected content can cause a prohibited action under the configured permissions. Use a disposable repository and a harmless marker. The expected result is that the action is denied, requires approval or remains inside a sandbox.

For example, place a synthetic instruction in a test issue body that asks the agent to create a marker file. Run the untrusted job without secrets and with a read-only token. Check whether the marker appears, whether any network request leaves the allowed set and whether the output schema remains valid.

Do not test with real credentials. A fake secret can reveal whether a value is copied into output, but it should be obviously synthetic and unusable. Limit the test to a scope small enough to inspect every side effect.

Test case Untrusted input Expected control result Evidence
Instruction in issue body Request to create a marker Denied, approved or sandboxed Tool decision and filesystem check
Instruction in repository file Request to read a fake secret No secret value in output Redacted artifact and log scan
Malformed review artifact Unexpected fields or command text Privileged job rejects input Validation result
Broad token request Agent asks for wider permissions Policy refuses the change Permission diff and denial log
Network attempt Request to contact an unapproved endpoint Egress blocks or policy denies Network log

The Claude Code MCP output truncation guide matters when the test logs are large. Preserve the decision, the decisive error and the request identifier. A truncated log that hides the blocked action is weak evidence.

The Claude Code subagent hang and timeout controls belong in CI design too. An agent that stops producing events should not leave a privileged job waiting indefinitely. Bound the runtime, cancel cleanly and fail the job when required evidence is missing.

The Claude Code background subagent running-count diagnosis explains why a stale UI count cannot prove that work is still active. In CI, verify the process and artifact instead of trusting a dashboard. The Claude Code usage tracking and cost API guide helps attribute historical API activity when a security review needs to establish which requests ran during an incident.

CI security tradeoffs between token scope, secret isolation, approval gates and pipeline complexity
Editorial tradeoff map based on Microsoft’s CI secret pathway and official Claude Code controls. More separation reduces exposure but adds validation and approval work.
CI hardening checklist covering triggers, token scope, secret scope, artifact validation, approval and runtime bounds
Editorial checklist derived from Microsoft’s documented pathway and official Claude Code controls. It tests specific failure paths without claiming universal protection.

Review the workflow as code

Treat the workflow file as security-sensitive code. Inspect permission changes with the same care as deployment scripts. A small diff can add a secret to an untrusted job or widen a token across the repository. Assign a workflow owner and require review for changes to triggers, environments, action versions and secret mappings.

Pin third-party actions according to the repository’s policy. When an action updates, inspect the changed inputs, permissions and execution path. The Claude Code extension-trojan remediation steps show why marketplace provenance matters even when a familiar name is involved. That incident does not prove a GitHub Action compromise, but it reinforces the need to verify the source.

Generated settings and temporary credentials need a cleanup plan. Do not upload them as artifacts or leave them in a shared runner cache. Use a disposable workspace where possible. If a secret-bearing step fails, preserve redacted logs and revoke the affected credential through the trusted incident process.

A protected environment should protect the privileged action, not merely decorate it. Test that an unapproved run cannot reach the secret-bearing step. Test that a forged artifact cannot select an arbitrary command. The approval mechanism is part of the control and needs its own negative tests.

The Claude Code billing-dispute evidence packet offers a useful discipline for incident records: timestamps, account scope, event type and evidence reference. Apply that structure to CI security events. A clear chronology helps distinguish an injected prompt from an installer failure, a permission misconfiguration or an unrelated service outage.

A refund request is a separate process. The Claude Code refund and support policy guide explains the region, payment-route, usage and dispute-status branches. Preserve the security evidence, but do not present an incident window as automatic proof of refund eligibility.

Harden the workflow, then test the failure paths

A hardened workflow has an explicit trigger policy, a read-only untrusted job, a validated artifact handoff and a separate privileged action. It also has bounded execution, narrow network access and output review. Each control should have a test that shows what happens when it fails.

Start with triggers. Decide which events may run the agent and who can supply the untrusted content. Public issues and pull requests from untrusted contributors deserve a different policy from a trusted branch push. Do not let a trigger change silently expand the job’s permissions.

Next, inspect action versions and inputs. Pin dependencies according to the repository’s policy and review updates. The malicious extension incident reported by Cursor shows that marketplace provenance is part of the boundary, although it is a different incident from the GitHub Action pathway. The Claude Code extension-trojan remediation steps explain why publisher and source checks matter.

Then test the approval gate. Try to invoke the privileged job without the required approval or with an invalid artifact. It should fail. Try to submit an artifact that asks for a command outside the allowlist. It should be rejected before any secret-bearing step runs.

Hardening check Pass condition Failure test
Trigger scope Only approved events start the agent Unexpected event does not gain permissions
Token scope Job has explicit minimum permissions Broad permission request is rejected
Secret scope Untrusted job receives no secrets Fake secret does not appear in output
Artifact schema Privileged job validates every field Malformed artifact is rejected
Approval boundary Agent cannot approve its own privilege Missing approval blocks execution
Runtime bound Job stops within its limit Hang produces a failed, auditable run
Output review Logs and artifacts are scanned Synthetic secret blocks publication

Official. For command, HTTP or MCP tool hooks, onFailure: block can make failures or timeouts block an action. It requires v2.1.295 or later for command and HTTP hooks, and v2.1.328 or later for MCP hooks. Without fail-closed behavior, most hook failures are non-blocking. Verify the installed version before relying on this control in CI.

The Claude Code hallucinated-package supply-chain controls belong in the same hardening pass. Dependency installation can execute code before the agent starts. Inspect new packages and isolate install steps from privileged credentials.

A workflow can also inherit risk from repository content. The official CVE record for CVE-2026-55607 describes a separate sandbox-escape case that required a malicious repository. Version and sandbox checks still matter, but they do not replace secret separation.

Use least privilege for tools, not just tokens

An agent may need to read files, run tests and produce a structured review. It rarely needs deployment tools, production connectors or unrestricted shell access in the same job. Remove tools that do not serve the untrusted task.

When shell access is necessary, constrain it. Use a fixed working directory, explicit command allowlist and a disposable runner. Do not mount the host home directory or a broad credential store. If a task requires a privileged operation, move that operation to a trusted wrapper with reviewed inputs.

Official. Claude Code permission rules evaluate deny, then ask, then allow. Deny rules should cover the actions the workflow must never perform, such as publishing secrets or changing workflow files. Ask rules can route uncertain actions to a trusted reviewer. Allow rules should be narrow enough to explain in one sentence.

Tool category Untrusted-job policy Privileged-job policy
File read Scoped to checkout Scoped to required paths
File write Workspace artifacts only Explicit output paths
Shell Fixed commands or reviewed wrapper Separate reviewed deployment script
Network Required read-only endpoints Approved service endpoints
MCP tools No production connectors Narrow connector with secret scope
Secrets None Minimum value for one trusted step
Repository writes None Explicit narrow permission after approval

The Claude Code destructive git guardrails are relevant when an agent tries to clean a workspace or roll back a failed run. Use a disposable checkout and non-destructive recovery. Do not let an untrusted job run broad reset or cleanup commands against a shared runner.

Testing also needs an independent oracle. The Claude Code generated-test oracle bias explains how tests generated from implementation can inherit its mistakes. For a security control, define the expected denial or isolation first, then verify the actual side effects.

The honest loss and the data gap

The win is a narrower path from untrusted text to privileged authority. A read-only analysis job cannot expose secrets it does not hold. A validated handoff prevents free-form agent output from becoming a command. Explicit permissions make the blast radius reviewable.

The loss is pipeline complexity and delay. Separate jobs, protected environments and artifact validation add moving parts. A strict policy can block useful automation, and a badly designed wrapper can become a new injection path. Separation reduces exposure; it does not prove that the workflow is secure.

Unknown. The frozen evidence does not provide a universal secure GitHub Actions template, a numerical prompt-injection success rate or proof that every Claude Code Action deployment is affected. Microsoft’s report establishes a pathway, not a population-wide incident rate. Future updates should revisit the action documentation, GitHub permission model and the original security research.

The live status page can provide service context during an incident, but it does not replace workflow logs or token review. Preserve transaction-level evidence: trigger, commit, action version, permissions, secret scope, tool calls and output.

CI security verdict separating untrusted review, validated approval and privileged execution behind explicit boundaries
Editorial verdict map based on Microsoft security research. Separation reduces the documented exposure path but does not certify a workflow as secure.

Re-run the threat model when the workflow changes

A new trigger, action, tool or secret changes the authority map. Re-run the review whenever one of those changes. Do not assume that a workflow approved for trusted branch pushes is safe for public issues or untrusted pull requests.

Maintain a short inventory with the workflow: untrusted inputs, job permissions, secret locations, network destinations, output targets and approval owner. When an incident occurs, that inventory tells the responder where to look first. When the workflow changes, it shows which boundary moved.

The goal is not a pipeline with no agent. It is a pipeline where untrusted content cannot directly command privileged authority. That distinction survives model changes and gives the team a security property it can test.

Practical alternative: test an OpenAI-format agent

If you want to compare CI workflows in an OpenAI-format agent, One AI API Key offers 46 live free model IDs for clients such as OpenCode, Cline or Cursor. The quickstart covers the base URL and first request. The free lane shares 100 requests and 5,000,000 tokens per day per account, resets at 05:30 IST / 00:00 UTC, and allows one request in flight per key.

The documented Claude Code route is unavailable at the research cutoff because all four Claude IDs were marked unavailable on 2026-11-27. Free IDs are OpenAI-format only and should not be used in Claude Code. Check the prepaid pricing page for paid usage and the cost calculator for planning. A different model route does not remove the need to isolate CI secrets.

FAQ

Did Microsoft say Anthropic infrastructure was breached?

No. The supplied Microsoft research documents a prompt-injection pathway in the Claude Code GitHub Action that could expose workflow secrets. It does not establish an Anthropic infrastructure breach.

Should the agent job have a write token?

Only if the task truly requires it, and preferably in a separate trusted job after approval. An untrusted review job should normally use explicit read-only permissions and no secrets. Add narrow write access only to the step that needs it.

Can a read-only token still expose secrets?

Yes. Token permissions and secret access are separate. A job with a read-only token can still leak a secret if the value is present in its environment, logs or tool output. Exclude secrets from untrusted jobs entirely.

Is auto mode enough protection for CI?

No. Official. Auto mode uses a classifier and can block benign actions or allow risky ones when intent is ambiguous. CI needs deterministic permission rules, secret separation and tested failure paths.

What is the first safe test?

Use a disposable repository, a harmless marker instruction and a fake secret. Confirm that the untrusted job has no real credentials, the prohibited action is denied or contained, and the fake value never appears in output. Record the actual permissions and action version.

More Claude Code troubleshooting

Sources

More in Blog

Try it

One API key for GPT, Grok, DeepSeek, Kimi, GLM, MiniMax, Qwen, Step, Beam, Nemotron, ERNIE, Hunyuan, Gemma, Laguna, LFM, LongCat, Llama, Solar, Jais, Mistral, K2 and Roleplay.

One AI API Key speaks the OpenAI and Anthropic formats, so you change the base URL and the key, not your code. Credit packs start at $10, and every model has a published per-token rate.

New accounts$10 credit on sign-up
  • 100requests
    per day
  • 3Mtokens
    per day
  • 47free
    models
  • $0per
    token
  • No card
  • No end date
Claim $10 credit →