Every time you merge (combine your changes) into main, your repo's main branch, a server you never see installs the dependencies, runs the tests, then deploys your app to production. All that time, the server holds the deploy token. Handy. But if someone can secretly add one extra step there, that step holds the same token, and what it does reaches every user.
That automatic path is called a CI/CD pipeline, from the code you push to the app running in production: install, test, build, then deploy. On GitHub, a pipeline is written as a GitHub Actions workflow (GitHub's automation feature). A workflow runs on a GitHub server called a runner. Picture a conveyor belt in an automated factory. Materials go in at one end, the product ships to every customer at the other, and the machines hold the warehouse key. If someone secretly puts something on the belt, or swaps one of its machines, that extra thing ships to every customer too. Here, the conveyor belt is the pipeline, the materials are the code you push, the machines are the workflow's steps, the warehouse key is the deploy token, and the customers are your app's users.
The workflow under review
Workflows live in the .github/workflows/ folder. on says when a workflow runs (its triggers), and jobs holds the jobs, each one a group of steps (steps). uses runs an action, ready-made code someone else wrote, and run runs a shell command (a terminal command). This is the coffee shop's deploy workflow, the same one the Lab uses:
name: Deploy
on:
push:
branches: [main]
pull_request_target:
permissions: write-all
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- run: npm ci && npm test
- run: echo "Token: ${{ secrets.DEPLOY_TOKEN }}"
- run: curl "https://api.example.com/deploy?token=${{ secrets.DEPLOY_TOKEN }}"
It has five findings:
- a secret printed to the log (
echo), the output record of each run (each time the workflow runs) - a secret in a URL (
curl) - an action called through a tag (
@v7) - a built-in token that can write anything (
write-all) - a job holding secrets that also runs for pull requests (PRs) from forks, copies of your repo owned by other people (
pull_request_target)
Secrets live in GitHub Secrets
The deploy token must never be written straight into the workflow file, because that file goes into git. Store it in GitHub Secrets: Settings, then Secrets and variables, then Actions. The value is stored encrypted, and the workflow reads it through secrets:
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
When the workflow runs, GitHub replaces ${{ secrets.DEPLOY_TOKEN }} with the value of the secret named DEPLOY_TOKEN. If that exact value appears in the log, GitHub replaces it with ***. This is called masking.
Keep secrets out of logs and URLs
The *** masking only filters text in GitHub's log. This is what gets recorded in two places when the coffee shop workflow above runs:
# GitHub Actions log
Run echo "Token: ***"
Token: ***
# access log of api.example.com (the target server)
203.0.113.7 - - [08/Oct/2026:09:12:44 +0000] "GET /deploy?token=dpl_9f8e7d6c5b4a HTTP/1.1" 200 2 "-" "curl/8.5.0"
The full URL, query parameters included, is recorded in the target server's access log, out of GitHub's reach. Anyone who can read that access log holds your token. So a token in the URL is not safe, even though GitHub's log shows it as ***. An echo of a secret is a bad habit too: masking only recognises text that matches exactly, so a secret in another form, such as base64, isn't masked.
The fix: never print a secret, bring it in through env, and send it in a header:
- run: curl -X POST -H "Authorization: Bearer $DEPLOY_TOKEN" https://api.example.com/deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
env:turns the secret into an environment variable for this step only, and the shell reads it as$DEPLOY_TOKEN.- The
Authorizationheader isn't recorded in the standard access log format, so the server's log only holds"POST /deploy HTTP/1.1".
Pin actions to a commit SHA
actions/checkout@v7 points at a tag, a name attached to one commit (one saved version of the code in git). Whoever owns the action's repo can move that tag to another commit at any time. The next run then executes different code, and that code holds your secrets too. It has happened. In March 2025, the tags of the tj-actions/changed-files action were moved to a malicious commit that printed CI secrets into the logs. More than 23,000 repos used that action. The fix is to write the commit's SHA:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
A commit SHA is a 40-character hash of the commit's contents. It points at exactly one commit and can't be moved. The # v7.0.1 comment records the version for humans, and Dependabot can update the pin through a pull request.
Only the permissions it needs
Every run gets a GITHUB_TOKEN, a built-in token for your own repo. permissions: write-all lets every step push code, create releases (published versions) and edit issues. Limit the permissions at the top level of the workflow, then add more per job when needed:
permissions:
contents: read
Secrets only on trusted triggers
pull_request: for a PR from a fork, the workflow runs with no secrets (apart from aGITHUB_TOKENthat can only read). Safe for running tests.pull_request_target: runs with your repo's secrets and a write token, even for a PR from a fork. Never put a deploy job on this trigger, and never run the PR's code there.- Deploy runs only on a
pushtomain, which happens after the PR has been reviewed and merged. Deploy sits in a separate job withenvironment: production, which can be set to wait for an approval first.
The coffee shop workflow after the fixes:
name: Deploy
on:
push:
branches: [main]
pull_request:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: npm ci && npm test
deploy:
needs: test
if: github.event_name == 'push'
environment: production
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- run: curl -X POST -H "Authorization: Bearer $DEPLOY_TOKEN" https://api.example.com/deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
needs: test makes the deploy job wait until the test job succeeds, and if: github.event_name == 'push' makes it run only on a push.
There are two ways to give deploy access:
| Approach | When to pick it |
|---|---|
A long-lived token in GitHub Secrets (DEPLOY_TOKEN) |
used in this lesson: a deploy service that accepts only a token. Replace (rotate) the token regularly, and right away after a leak |
| OIDC: the job asks the cloud for a short-lived token | deploying to AWS, Google Cloud or Azure. No long-lived secret is stored in GitHub, and the token is valid for one job only |
For OIDC (OpenID Connect), the deploy job needs permissions: id-token: write so it can ask GitHub for a token. Then the cloud provider's official action exchanges that token for access to the cloud. For example aws-actions/configure-aws-credentials (v6.3.0), with role-to-assume set to an IAM role that trusts only tokens from your repo.
⚠️ Pipeline holes the log won't show you
- Trusting the
***in the log too much. Masking doesn't reach the server's access log, files uploaded as artifacts (files a run saves on GitHub), or a secret in another form. Don't print secrets at all. - A third-party action through a tag or
@main. Both can change. Pin to the full SHA. permissionsleft atwrite-all, or not written. Write it explicitly, starting fromcontents: read.- A job with secrets on
pull_request_target. A PR from anyone triggers that job with your secrets.
TL;DR: In GitHub Actions (the automatic path from a push to a deploy), keep secrets in GitHub Secrets and read them with ${{ secrets.NAME }}, never written into the workflow file. GitHub masks secrets as *** only in GitHub's own log. So don't echo a secret and don't put it in a URL: bring it in through env and send it in an Authorization header. Pin every action to a full commit SHA, because a tag such as @v7 can be moved. Limit the built-in token's permissions starting from contents: read. Run PR tests on the pull_request trigger (no secrets), and deploy only on a push to main, in a job with environment: production.
⚡ Secrets live in GitHub Secrets
Meaning: A CI/CD pipeline (the automatic path that tests and then deploys your code) holds the deploy token the whole way. On GitHub, a pipeline is written as a workflow file that goes into git, so the token must never be written in that file. Store it in GitHub Secrets, and GitHub replaces its value with *** in the log.
⚡ Keep them out of logs and URLs
Guess first: this step puts the secret DEPLOY_TOKEN in a URL: curl "https://api.example.com/deploy?token=${{ secrets.DEPLOY_TOKEN }}". GitHub's log shows it as ***. Is the token safe?
No. The full URL, query parameters included, is recorded in the target server's access log, out of GitHub's reach. The secret can be seen in that URL.
Write:
- run: curl -X POST -H "Authorization: Bearer $DEPLOY_TOKEN" https://api.example.com/deploy
env:
DEPLOY_TOKEN: ${{ secrets.DEPLOY_TOKEN }}
Meaning: Never print a secret. Bring it in through env, which makes it the environment variable $DEPLOY_TOKEN for this step only, then send it in the Authorization header. That header isn't recorded in the standard access log.
⚡ Pin actions to a commit SHA
Write:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
Meaning: An action is ready-made code someone else wrote, called with uses. If an action is called through a tag such as @v7, the action's repo owner can move that tag to another commit at any time. A commit SHA (a 40-character hash) points at exactly one commit and can't be moved.
⚡ Only the permissions it needs, only trusted triggers
Meaning: Every run (each time the workflow runs) gets a GITHUB_TOKEN, a built-in token for your repo. Limit it with permissions: contents: read so that token can only read. The pull_request_target trigger carries secrets even for a PR from a fork, a copy of your repo owned by someone else. So PR tests use pull_request (no secrets), and deploy runs only on a push to main.