CCyberwiki

Secret exposure in CI/CD workflows

Secret exposure in CI/CD workflows
ClassSecrets, Software supply chain
Also known asPwn request (for the pull_request_target variant)
OWASPCICD-SEC-6 Insufficient Credential Hygiene (OWASP Top 10 CI/CD Security Risks)
Typical severityHigh
AffectsGitHub Actions workflows and the third-party actions they call; the same risks apply to other CI/CD systems

A CI/CD system holds API keys, tokens and other secrets so it can test, publish and deploy code. Secret exposure in CI/CD workflows is the leak of those values: a workflow prints one to a log, pastes text from an outsider into a shell script, builds a stranger's code while secrets are loaded, or calls a third-party step that someone has altered. All examples on this page use GitHub Actions.

Description

A repository on GitHub stores secrets in its settings, and a workflow file reads them as ${{ secrets.NAME }}. Every person with write access to the repository can read every secret configured in it.1 GitHub also creates a GITHUB_TOKEN at the start of each job. It is limited to the one repository and expires when the job ends, after at most 6 hours on GitHub-hosted runners, but while the job runs it can write to the repository if its permissions allow.2

The steps of a job share one runner, so a step can read the environment variables a later step uses, write files that a later step processes, or reach other containers on the machine, so one compromised step has access to all secrets the job loads and can use the GITHUB_TOKEN to write to the repository.1

Mechanism

Secrets in logs

The runner hides known secret values in the log. The replacement looks for an exact match, so it misses a secret that has been transformed: encoded in Base64 or for a URL, stored inside a block of JSON or YAML, or used to sign a new token such as a JSON Web Token. GitHub's own reference warns that "automatic redaction is not guaranteed".1 A leaked value also tends to spread, because build logs are often shipped to log management systems that more people can read.3

Untrusted code with secrets loaded

A pull request supplies code to the build. Its author can change a build script, add a test, or add a package whose install script runs during npm install.4 That is why a run started from a fork on the pull_request trigger gets no secrets and no write access, only a GITHUB_TOKEN with reduced rights.54

The pull_request_target trigger runs in the context of the target repository, with write permission and with its secrets. It is meant for labelling a pull request or posting a comment. When a workflow on this trigger checks out the pull request's code and builds it, the secrets go to whoever wrote the pull request; the GitHub Security Lab named this pattern the "pwn request".4 workflow_run carries the same risk, and a workflow on either trigger "can be exploited to take over a repository".1

Script injection

Before a run: step starts, GitHub replaces each ${{ }} expression with its value and writes the result into a shell script.6 Values that outsiders control, such as an issue title, a pull request body or a branch name, become part of the script. A pull request titled a"; ls $GITHUB_WORKSPACE" closes the quoted string in the step below and runs a command of the author's choosing:

- name: Check PR title
  run: |
    title="${{ github.event.pull_request.title }}"

The injected command is Command injection with the job's token and secrets within reach.

Altered third-party actions

A step written uses: owner/action@v4 follows a Git tag, and a tag "can be moved or deleted" by anyone who gains access to the action's repository.1 The next run then executes the new code with the job's secrets, a form of Software supply chain compromise.

Impact

Outside the pipeline, a leaked deploy key or cloud key opens production servers, package registries and cloud accounts. A GITHUB_TOKEN with write access lets an attacker change the repository while the job runs. Deploy keys are often left unrotated for years, so a key copied once keeps working.13

Notable incidents

Between 14 and 15 March 2025, an attacker changed the version tags of tj-actions/changed-files, an action used by more than 23,000 repositories, to point at a malicious commit. The new code read the memory of the runner process, encoded the secrets it found in Base64 and printed them to the build log, where anyone could read them in repositories with public logs.7 The exposed secrets included access keys, GitHub personal access tokens, npm tokens and private RSA keys. In CISA's assessment, an earlier compromise of reviewdog/action-setup@v1 possibly enabled the attack; the agency added both flaws (CVE-2025-30066 and CVE-2025-30154) to its Known Exploited Vulnerabilities catalog. It advised treating every identified secret as compromised and rotating it.8

Detection

Search the files in .github/workflows for pull_request_target and workflow_run together with a checkout of the pull request's code, for ${{ github.event. inside a run: block, and for uses: lines that end in a tag instead of a 40-character commit hash. Read the logs of a run after testing valid and invalid inputs.1 GitHub's CodeQL code scanning and OpenSSF Scorecard both flag vulnerable workflows.1

Prevention

  1. Set the token to read-only at the top of each workflow and raise it only in the job that needs more, following Principle of least privilege:1
    permissions:
      contents: read
  2. Pass untrusted values through an environment variable, which the shell treats as data:
    - name: Check PR title
      env:
        TITLE: ${{ github.event.pull_request.title }}
      run: |
        if [[ "$TITLE" =~ ^octocat ]]; then echo ok; fi
  3. Pin each third-party action to a full commit hash, with the tag as a comment:
    uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
  4. Build pull requests on pull_request, save results as artifacts, and do privileged work in a separate workflow_run workflow that treats those artifacts as untrusted.4
  5. Replace stored cloud keys with OpenID Connect, where the cloud provider issues a token valid for one job.9
  6. Put production secrets in an environment with required reviewers, so a job cannot read them until someone approves it, and add .github/workflows to CODEOWNERS.
  7. Register derived values as secrets, or mask them with ::add-mask::. If a secret reaches a log unmasked, delete the log and rotate the secret.

Prompt for a coding agent

Review every file in .github/workflows. Add a top-level permissions block set to contents: read and raise permissions only in the jobs that need them. Move every ${{ github.event.* }}, head_ref or other user-controlled expression out of run: scripts into env: variables and quote them in the script. Pin every third-party uses: line to its full commit SHA with the tag as a comment. Flag any workflow on pull_request_target or workflow_run that checks out or runs pull request code. List each file and line you changed, and each secret that is printed, passed on a command line or used outside the job that needs it.

In SecFlash

In a project's workflow files, SecFlash reports untrusted text run as code as SF-SEC-801, a risky trigger such as pull_request_target as SF-SEC-802, a token with more access than the job needs as SF-SEC-804, a credential that can reach a log, a later step or an artifact as SF-SEC-805, and an action not pinned to a commit as SF-SEC-806. All five show on the Security page.

See also

References

  1. a b c d e f g h i GitHub (2026). "Secure use reference". GitHub Docs.
  2. back GitHub (2026). "GITHUB_TOKEN". GitHub Docs.
  3. a b OWASP Foundation. "CICD-SEC-6: Insufficient Credential Hygiene". OWASP Top 10 CI/CD Security Risks.
  4. a b c d GitHub Security Lab (updated 17 June 2026). "Keeping your GitHub Actions and workflows secure Part 1: Preventing pwn requests". GitHub Security Lab.
  5. back GitHub (2026). "Using secrets in GitHub Actions". GitHub Docs.
  6. back GitHub (2026). "Script injections". GitHub Docs.
  7. back GitHub (15 March 2025, updated 22 October 2025). "tj-actions changed-files through 45.0.7 allows remote attackers to discover secrets by reading actions logs" (GHSA-mrrh-fwg8-r2c3). GitHub Advisory Database.
  8. back CISA (18 March 2025, revised 26 March 2025). "Supply Chain Compromise of Third-Party tj-actions/changed-files (CVE-2025-30066) and reviewdog/action-setup@v1 (CVE-2025-30154)". cisa.gov.
  9. back GitHub (2026). "OpenID Connect". GitHub Docs.