SecretsGitHub Actions
Secrets in CI/CD: where they leak and how to stop it
GitHub redacts secrets from workflow logs, and its own documentation says that redaction is not guaranteed. Logs, fork pull requests, caches, artifacts and third-party actions each have a separate control in GitHub Actions.

Where secrets leak
- Logs. A secret value can be transformed in several ways, and for that reason automatic redaction comes with no guarantee.
- Pull requests from forks. The
pull_request_targettrigger, used with the checkout of an untrusted pull request, exposes the repository to security compromises. - Caches. Read access is enough to open a pull request on a repository, and from there to read what a cache contains.
- Artifacts.
actions/upload-artifactignores hidden files by default, to avoid unintentionally uploading sensitive information. - Third-party actions. If an action is compromised, every secret configured on the repository is within its reach.
- People. Any user with write access to a repository has read access to all secrets configured in it.
What log masking misses
GitHub's secure use reference lists the limits of redaction:
- Structured data. Redaction depends largely on an exact match with the secret value. Do not wrap a secret in a blob of JSON, XML or YAML. Create an individual secret for each sensitive value.
- Transformed values. If a secret is transformed, for example Base64 or URL-encoded, register the new value as a secret too.
- Generated values. When a secret produces another sensitive value, a JWT signed with a private key for instance, register the new value as a secret too.
The add-mask workflow command registers a value. This is GitHub's example for a value generated inside a job:
on: push
jobs:
generate-a-secret-output:
runs-on: ubuntu-latest
steps:
- id: sets-a-secret
name: Generate, mask, and output a secret
run: |
the_secret=$((RANDOM))
echo "::add-mask::$the_secret"
echo "secret-number=$the_secret" >> "$GITHUB_OUTPUT"Register the value before it is output in the build logs. When a secret lands unredacted in a workflow run log, delete that log and rotate the secret.
Pull requests from forks
A workflow triggered from a forked repository gets no secrets on its runner, GITHUB_TOKEN being the one exception. In a pull request from a fork, the GITHUB_TOKEN can only read.
pull_request_target is different. The job is given the GITHUB_TOKEN of the base repository and can reach repository secrets and organization secrets. The workflow file comes from the base repository's default branch, and no code from the fork is executed by default. The risk starts when a workflow points actions/checkout at the pull request head and a later step runs what was checked out.
GitHub's guidance: stay away from this event when the job has to build or run the pull request's code, and choose pull_request when no extra access to secrets is needed.
Caches, artifacts and actions
- Caches. GitHub's recommendation is to keep sensitive information, access tokens and login credentials for example, out of every file in the cache path.
- Artifacts. The
include-hidden-filesinput ofactions/upload-artifactdefaults tofalse. Artifacts are retained for 90 days by default, and theretention-daysinput sets a shorter period. - Actions. Pin each third-party action to a full-length commit SHA, and verify that the SHA is from the action's repository and not from a fork. Someone who gains access to the repository that stores an action can move a tag or delete it.
Environment secrets with approvals
A secret stored in an environment reaches only the workflow jobs that reference that environment. When the environment requires approval, the job gets no environment secrets before one of the required reviewers has approved it.
- The reviewer list holds up to six users or teams, and one approval from that list is enough for the job.
- With the setting that prevents self-reviews, users who initiate a deployment cannot approve the deployment job.
On the GitHub Free, GitHub Pro and GitHub Team plans, required reviewers are only available for public repositories.
OIDC in place of stored keys
With OpenID Connect, a workflow accesses resources in AWS without storing the AWS credentials as long-lived GitHub secrets. The job requests an OIDC token and uses it to authenticate with a short-lived access token.
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v7
- uses: aws-actions/configure-aws-credentials@e3dd6a429d7300a6a4c196c26e071d42e0343502
with:
role-to-assume: arn:aws:iam::111122223333:role/my-app-deploy
aws-region: us-east-1The environment name, the role ARN and the Region are yours to replace. The credentials action is pinned to the commit SHA that GitHub's own example uses. id-token: write lets GitHub's OIDC provider create a token for the run. It grants the workflow no right to change any resource or write to one.
On the AWS side, GitHub's guide says to edit the role's trust policy and add the sub field to the validation conditions. For repositories created after July 15, 2026, the sub claim includes immutable owner and repository IDs, so make sure the trust policy matches the format your repository uses.
Rotation of what remains
For the secrets that remain after OIDC, GitHub's guidance has two parts. Rotate secrets on a schedule. A compromised secret then stays valid for a shorter time. Periodically review the registered secrets, and remove those that are no longer needed.
What to check first
- Search your workflows for
pull_request_targetand confirm that none checks out and runs pull request code. - Replace any JSON, XML or YAML blob stored as one secret with individual secrets.
- Replace stored cloud keys with OIDC.
- Move production secrets into an environment with required reviewers.
- Pin third-party actions to a full-length commit SHA.
Sources
Want a second pair of eyes on yours? We do this work for a living.
More guides

Keyless deploys to AWS and Google Cloud with OIDC
Authentication · 2 min read
The trust policy for AWS and the provider setting for Google Cloud, with the workflow for each.

Set up OIDC between GitHub Actions and Azure
Authentication · 2 min read
Five steps from an app registration to a workflow that logs in with no stored secret.

SOPS: encrypted secrets in a Git repository
Secrets · 4 min read
Encrypt values with age or KMS, set rules in .sops.yaml, and rotate keys in the documented order.