# 4 ways secrets still leak into CI logs

> GitHub Actions masks secrets by exact match. Encoding, multiline, and generated values can slip through.

Source: https://fullbytedeveloper.com/blog/ci-log-secret-leak-patterns
Keyword: LOGMASK
Published here: 2026-11-10, updated 2026-12-03

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:

```bash
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())
PY
```

Captured on this host:

```text
c3VwZXJzZWNyZXRfdG9rZW5fdmFsdWU=
raw length 23
b64 c3VwZXJzZWNyZXRfdG9rZW5fdmFsdWU=
same string? False
```

The 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].

<figure>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 280" role="img" aria-label="Secret value must match the mask table exactly or it prints">
  <defs>
    <marker id="ciLogArrow" markerWidth="10" markerHeight="10" refX="8" refY="3" orient="auto">
      <path d="M0,0 L8,3 L0,6 Z" fill="#14b8a6"/>
    </marker>
  </defs>
  <rect x="0" y="0" width="720" height="280" rx="12" fill="#0b1f3a"/>
  <text x="24" y="36" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="16" font-weight="700">CI log mask path</text>
  <rect x="24" y="56" width="160" height="72" rx="8" fill="#123052" stroke="#14b8a6" stroke-width="2"/>
  <text x="40" y="88" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">1. Secret store</text>
  <text x="40" y="110" fill="#cbd5e1" font-family="ui-monospace, monospace" font-size="14">MY_TOKEN=abc</text>
  <path d="M184 92 H232" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#ciLogArrow)"/>
  <rect x="240" y="56" width="180" height="72" rx="8" fill="#123052" stroke="#64748b" stroke-width="2"/>
  <text x="256" y="88" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">2. Job stdout</text>
  <text x="256" y="110" fill="#cbd5e1" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">echo / curl / crash</text>
  <path d="M420 92 H468" stroke="#14b8a6" stroke-width="3" fill="none" marker-end="url(#ciLogArrow)"/>
  <rect x="476" y="56" width="220" height="72" rx="8" fill="#123052" stroke="#f59e0b" stroke-width="2"/>
  <text x="492" y="88" fill="#f59e0b" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">3. Exact match?</text>
  <text x="492" y="110" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">mask or print clear</text>
  <rect x="24" y="160" width="672" height="96" rx="8" fill="#123052" stroke="#64748b" stroke-width="2"/>
  <text x="40" y="196" fill="#f8fafc" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">Match: abc -&gt; ***</text>
  <text x="40" y="224" fill="#f59e0b" font-family="ui-sans-serif, system-ui, sans-serif" font-size="14">Miss: YWJj (Base64), {"t":"abc"}, derived JWT, split lines without add-mask</text>
</svg>
</figure>

*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].

```yaml
- name: bad example
  run: echo "${{ secrets.MY_SECRET }}" | base64
```

Safer pattern when you must transform:

```yaml
- 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].

```yaml
- 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].

```yaml
- 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.

```bash
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:

```text
Authorization: Bearer supersecret_token_value
LEAK surface found
```

If 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

1. Rotate the secret in the upstream system first.
2. Delete the workflow run logs in the GitHub UI.
3. Audit whether the value was used (unusual API traffic, new deploy keys, unexpected package publishes).
4. 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](/blog/github-actions-five-workflow-checks) and [October security recap for Actions](/blog/october-security-recap-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.

```bash
# 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 || true
```

If 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](https://fullbytedeveloper.com/blog/topic/dev-tools).

Send this to the friend who trusts GitHub Actions to hide every secret in the logs.

Image: Dark grid floor with a navy pedestal holding two concentric glass rings glowing teal. A chain of teal cubes curves through the rings and ends in a large teal arrow; a lower gold cube chain exits as a gold arrow. Thin gold wire with a disc floats upper left.
https://fullbytedeveloper.com/media/ci-log-secret-leak-patterns/ci-log-secret-leak-patterns-venice.webp
Two differently shaped value streams pass the same rings; only an exact match gets masked in CI logs.

## Sources

1. [GitHub docs: secure use reference](https://docs.github.com/en/actions/reference/security/secure-use)
2. [GitHub runner issue: base64 masking improvements](https://github.com/actions/runner/issues/291)
3. [GitHub runner PR: add masks for multiline secrets](https://github.com/actions/runner/pull/1521)
4. [GitHub docs: Encrypted secrets](https://docs.github.com/en/actions/security-guides/using-secrets-in-github-actions)
