4 ways secrets still leak into CI logs
GitHub Actions masks secrets by exact match. Encoding, multiline, and generated values can slip through.
Published here , updated · 4 sources · Resume reading
GitHub Actions redacts secrets in logs by exact string match on registered values [1][4]. Change the shape (Base64, JSON wrap, a derived JWT) and the same secret can print in cleartext. Start by treating every echo, failed curl, and stack trace as a leak surface, then register every derived form you still have to print.
Quick start: prove exact-match masking locally
You do not need a runner to see why encoding breaks redaction. Encode a stand-in secret and compare the two strings:
SECRET='supersecret_token_value'
echo -n "$SECRET" | base64
python3 - <<'PY'
import base64
s=b'supersecret_token_value'
print('raw length', len(s))
print('b64', base64.b64encode(s).decode())
print('same string?', s.decode() == base64.b64encode(s).decode())
PYCaptured on this host:
c3VwZXJzZWNyZXRfdG9rZW5fdmFsdWU=
raw length 23
b64 c3VwZXJzZWNyZXRfdG9rZW5fdmFsdWU=
same string? FalseThe runner masks supersecret_token_value if that exact value is a secret. It does not magically mask c3VwZXJzZWNyZXRfdG9rZW5fdmFsdWU= unless you also register that form [1][2].
How the mask pipeline works
GitHub injects repository, environment, and organization secrets into the job, then the runner replaces exact occurrences in log lines with *** [1][4]. The secure-use docs warn that secrets are not masked when you alter them (encoding, splitting, wrapping) before they hit the log stream [1].
The runner only redacts strings it already knows. Transforms create new strings unless you register them.
Pattern 1: Base64 or URL encoding
Piping a secret through base64, jq -r, or URL encoding changes the bytes that hit the log. The runner issue tracker discusses Base64 masking gaps and improvements over time; do not assume every transform is covered [2].
- name: bad example
run: echo "${{ secrets.MY_SECRET }}" | base64Safer pattern when you must transform:
- name: mask the encoded form too
run: |
ENC=$(printf '%s' "${{ secrets.MY_SECRET }}" | base64 -w0)
echo "::add-mask::$ENC"
echo "encoded length ${#ENC}"Prefer never printing the encoded form. If a tool dumps it, register it with ::add-mask:: before any later step can echo it [1].
Pattern 2: structured wrappers
Embedding a secret inside JSON, XML, or YAML changes the surrounding characters. Exact match can still catch the substring in many cases, but quoting, escapes, and pretty-printing create variants that fail redaction [1].
- run: echo '{"token":"${{ secrets.MY_TOKEN }}"}'Store tokens as individual secrets. Build structured payloads in memory without echoing the whole object. When a debug step must print JSON, strip or replace secret fields first.
Pattern 3: generated values never registered
Workflows that mint JWTs, temporary passwords, or signed URLs from a private key produce new sensitive strings. Those strings are not in the secrets store until you call ::add-mask:: [1].
- name: mint then mask
run: |
JWT=$(generate-jwt "${{ secrets.PRIVATE_KEY }}")
echo "::add-mask::$JWT"
echo "Token generated"Without the mask line, a later set -x, verbose client, or failed request can print the JWT in full.
Pattern 4: error paths and stack traces
Failed API clients often dump request headers. Language runtimes print exception messages that include connection strings. Review logs after intentional failures (bad password, 401, timeout), not only happy-path runs [1].
A useful local rehearsal: run the same CLI your job runs with a fake secret in the environment and grep the transcript for that value before you ever put the real secret in Actions.
export DEMO_TOKEN='supersecret_token_value'
# pretend a client logged the header
printf 'Authorization: Bearer %s\n' "$DEMO_TOKEN" | tee /tmp/ci-leak-demo.log
grep -F "$DEMO_TOKEN" /tmp/ci-leak-demo.log && echo 'LEAK surface found'Captured:
Authorization: Bearer supersecret_token_value
LEAK surface foundIf that greps clean only because you never printed the header, you are safer than a job that logs every curl -v line.
Multiline secrets and add-mask
Runner PR 1521 taught the runner to split multiline secrets and mask each line [3]. Still register derived single-line forms yourself. A PEM that you re-wrap, strip headers from, or join into one line is a new string.
What to do when a secret already leaked
- Rotate the secret in the upstream system first.
- Delete the workflow run logs in the GitHub UI.
- Audit whether the value was used (unusual API traffic, new deploy keys, unexpected package publishes).
- Search forks, caches, and notification channels that may have copied the log [1][4].
Deleting the log is hygiene. Rotation is the fix.
Pair this with workflow review habits
Secret hygiene sits next to pinning actions and reviewing untrusted PR workflows. See five GitHub Actions workflow checks and October security recap for Actions when you harden the same pipeline.
Audit a past run without replaying production secrets
Download a failed run's logs from the Actions UI (or gh run download when your token allows). Search for known secret prefixes, Bearer , AKIA, private key headers, and the names of environment variables your jobs export. Prefer searching for structural markers over pasting the live secret into a laptop grep habit.
# structural markers only; do not paste live secrets into shell history
rg -n 'Bearer |Authorization:|BEGIN (RSA |OPENSSH )?PRIVATE KEY|AKIA[0-9A-Z]{16}' /tmp/downloaded-logs 2>/dev/null || trueIf the search hits, treat it as a leak even when the UI showed *** on other lines. Partial masks and truncated lines can still leave enough material for an attacker who already knows the format [1].
Masking versus not writing the value
::add-mask:: is a safety net, not a license to print secrets for fun. The safest job never puts the value on stdout, stderr, or a step summary. Prefer logging lengths, hashes of non-secret metadata, or "minted=true". When a vendor CLI forces verbose auth dumps, wrap it so the wrapper strips headers before tee or cat reaches the runner log stream [1][4].
Step summaries and annotations are also log surfaces. A markdown table that includes a token cell is still a log line to the masker.
Organization and environment secrets
Organization secrets and environment-scoped secrets follow the same exact-match rule once they reach a job [4]. Environment protection rules (required reviewers) reduce who can run the job; they do not change how masking works after the job starts. Register derived values in the job that creates them, not only in the repository secret store.
Fork pull requests and secret availability
Workflows triggered by pull_request from forks generally do not receive repository secrets the way same-repo jobs do. That is good for leak prevention and bad for "it worked on my branch" confusion. Do not "fix" missing secrets by switching to pull_request_target without reading the trust model. Untrusted code plus secrets is a worse problem than an unmasked log [1].
Depth: why exact match is the only scalable rule
The runner cannot know every encoding of every secret without becoming a general cryptanalysis engine. Exact match keeps the mask table small and predictable. Your job is to keep the set of sensitive strings small and registered: the raw secret, plus any transform you knowingly create before a print could happen [1][2].
When a framework logs request objects, assume nested fields will stringify in surprising orders. Prefer redacting at the framework layer (known field names) in addition to runner masks.
Mistakes that put tokens in the transcript
Printing base64 of a secret in a "debug" step and assuming the runner still masks it [1][2].
Building a JSON blob that contains a token and echoing the whole blob for troubleshooting.
Minting a JWT or signed URL without ::add-mask:: before any later step runs.
Leaving curl -v or set -x on in jobs that export secrets into the environment.
Treating log deletion as rotation. Attackers who already scraped the run still hold the old value.
When the mask table is enough
Keep secrets short, single-line when you can, and unused in stdout. Prefer step summaries that say "token minted" over printing any form of the value. When a tool forces a transform into the log, register that transform with ::add-mask:: in the same step that creates it [1].
Browse the Dev tools topic.
Send this to the friend who trusts GitHub Actions to hide every secret in the logs.

Keep this guide
Questions about this guide
What if a secret appears in my logs?
Delete the workflow run logs and rotate the secret immediately. The log may already be cached or copied.
Does add-mask work for multiline secrets?
Yes, since late 2021. The runner splits multiline values and masks each line separately.
Does GitHub mask Base64 of a secret automatically?
No. Masking is exact string match. Register encoded forms with add-mask or avoid printing transforms.
Is deleting the workflow run enough?
No. Rotation is the reliable fix. Logs can already be copied, forked, or held in third-party caches.
Sources
- GitHub docs: secure use referencedocs.github.com
- GitHub docs: Encrypted secretsdocs.github.com