Skip to content

CI: reject unmasked credential writes to $GITHUB_ENV / $GITHUB_OUTPUT - #2347

Merged
anton-107 merged 3 commits into
mainfrom
deco-29706-secret-write-check
Nov 25, 2026
Merged

anton-107 merged 3 commits into
mainfrom
deco-29706-secret-write-check

Conversation

@anton-107

Copy link
Copy Markdown
Contributor

Why

SEC-35859: .github/scripts/jfrog-oidc-token.sh wrote the JFrog token to $GITHUB_ENV without ::add-mask::, so it showed up in public run logs. #2291 masked it, and #2334 added a runtime test (secret-masking.sh) for the existing credential scripts. Nothing stopped a new script or workflow step from making the same mistake. This adds a static check that covers every script and workflow under .github/ (DECO-29706).

What

  • .github/scripts/check-secret-writes.sh: a dependency-free bash check. It scans .github/**/*.sh, *.yml and *.yaml. It checks every non-comment line that writes to $GITHUB_ENV or $GITHUB_OUTPUT. The line fails when either:

    • it references a variable or ${{ expression }} whose name looks like a credential (token, secret, passw(or)d, credential, api_key, private_key, or a key / auth name segment, case-insensitive), or
    • the key it writes looks like a credential and its value is not a literal,

    and that same reference was not passed to ::add-mask:: on an earlier line of the same file.

  • Exceptions: ${{ secrets.* }} and ${{ github.token }} are skipped, because Actions masks them automatically. A justified write can end with # secret-write-ok: <reason>.

  • .github/scripts/tests/check-secret-writes.sh and fixtures/secret-writes/: tests for the check. They run as a new step of the existing secret-masking-test.yml job, so there is no new workflow.

What the heuristic catches and misses

It is a line-based heuristic, not a shell parser.

Catches:

  • the pre-fix JFrog pattern
  • a mask placed after the write
  • unmasked step outputs in ${{ }}
  • a credential-named key filled from $(...)

Misses:

  • Multi-line writes: heredocs into $GITHUB_ENV, { ...; } >> "$GITHUB_ENV".
  • Credentials behind a non-credential name. For example, PIP_INDEX_URL embeds the token. The runtime test still covers that case for the existing scripts.
  • Masks done in another file or another step's script. The mask must appear earlier in the same file.
  • Writes to rc files such as ~/.npmrc.

has_token-style outputs with literal values do not trip it, and neither do env mappings like GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}. Neither one writes a non-literal credential value to a sink. A name like KEY_ID is flagged; the allow comment is the escape hatch for it.

Tests

bash .github/scripts/tests/check-secret-writes.sh checks that:

  • jfrog-oidc-token.prefix.sh, the pre-fix script taken from before b4cec4e, is flagged at the write line.
  • mask-after-write.sh and unmasked-workflow.yml are flagged at the expected lines.
  • jfrog-oidc-token.masked.sh, a copy of the current script, and clean-workflow.yml pass. clean-workflow.yml covers masked, auto-masked, literal and allow-listed writes.
  • Removing the allow comment from clean-workflow.yml makes it fail.
  • The repository itself passes, with fixtures excluded.

Run locally on this branch: all pass, and secret-masking.sh still passes. A copy of jfrog-oidc-token.sh with its ::add-mask:: line deleted is flagged.

This pull request and its description were written by Isaac.

Add a static, line-based check (.github/scripts/check-secret-writes.sh)
that scans .github/**/*.sh and workflow YAML. It fails when a line writes
a credential-looking variable or ${{ expression }} to $GITHUB_ENV or
$GITHUB_OUTPUT without an earlier ::add-mask:: of the same reference in
the same file. A trailing "# secret-write-ok: <reason>" allows justified
exceptions.

Tests use fixtures, including the pre-fix jfrog-oidc-token.sh (must be
flagged) and the current masked one (must pass), and scan the repository.
They run as a new step of the existing secret masking workflow.

DECO-29706

Co-authored-by: Isaac <no-reply@databricks.com>
@rugpanov

rugpanov commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

🤖 Integration tests ❌ failed for 4b908ac1.
View run

@anton-107
anton-107 marked this pull request as ready for review November 24, 2026 15:51

@louis-johnston-db louis-johnston-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review. The comments in this review were written by an automated AI reviewer.

Comment thread .github/scripts/check-secret-writes.sh Outdated
while IFS= read -r line || [[ -n "$line" ]]; do
n=$((n + 1))
trimmed="${line#"${line%%[![:space:]]*}"}"
[[ "$trimmed" == \#* ]] && continue

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review: Any line containing ::add-mask:: is excluded from sink analysis, regardless of command order or which value is masked.

Trigger: A one-line command such as echo "TOKEN=$TOKEN" >> "$GITHUB_ENV"; echo "::add-mask::$TOKEN" passes even though the write precedes the mask.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2bc691. Each line is now read as a sequence of commands split on ;, && and || (outside ${{ }}), so a mask later on the same line no longer covers an earlier write, and a mask of one value no longer exempts the rest of the line. Covered by review-findings.yml lines 15 and 16.

Comment thread .github/scripts/check-secret-writes.sh Outdated

check_file() {
local file="$1" n=0 line trimmed key ref flagged sink
local masked=$'\n'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review: Mask state is accumulated across the entire workflow file rather than per job, although GitHub masks are job-scoped.

Trigger: If an earlier job masks $TOKEN and a later job writes $TOKEN unmasked, the checker accepts the later write even though it runs on a separate runner.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2bc691. In workflow files, masks are now forgotten at each job key under jobs:. Covered by review-findings.yml line 14.

Comment thread .github/scripts/check-secret-writes.sh Outdated
}

auto_masked() {
[[ "$1" == '${{secrets.'* || "$1" == '${{github.token}}' ]]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review: The automatic-mask exemption accepts every compound expression beginning with secrets., not only a direct secret reference.

Trigger: ${{ secrets.OPTIONAL_TOKEN || steps.login.outputs.token }} is skipped; when the secret is absent, the unmasked step output is written.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in c2bc691. Only a bare ${{ secrets.NAME }} or ${{ github.token }} is skipped now; any other expression is checked like a variable. Covered by review-findings.yml line 20. The same commit also counts a mask only when it masks exactly the written reference, so ::add-mask::prefix-$TOKEN no longer covers $TOKEN (line 19).

@anton-107
anton-107 requested a review from rclarey November 24, 2026 20:26
- Read each line as commands split on ;, && and ||, so a mask later on the
  same line no longer covers an earlier write, and a mask of one value no
  longer exempts the whole line.
- Count a mask only when it masks exactly the reference that is written;
  masking prefix-$TOKEN does not cover $TOKEN.
- Forget masks at each job boundary in workflow files, since masks are
  scoped to a job.
- Skip only a bare ${{ secrets.NAME }} or ${{ github.token }}; an
  expression that can fall back to a step output is checked.

Adds a fixture covering each case.

Co-authored-by: Isaac <no-reply@databricks.com>

@louis-johnston-db louis-johnston-db left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review. The comments in this review were written by an automated AI reviewer.

grep -qE "$ALLOW_RE" <<< "$line" && allowed=true

while IFS= read -r cmd; do
if [[ "$cmd" == *"::add-mask::"* ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review: Any textual occurrence is treated as an executed mask. For example, MASK_TEMPLATE="::add-mask::$TOKEN" records TOKEN even though the workflow command is never emitted, so a later unmasked write passes.

Trigger: A script assigns or otherwise uses an ::add-mask:: string without printing it, then writes the referenced credential to a GitHub environment file.

continue
elif [[ "$line" =~ ^[A-Za-z_] ]]; then
in_jobs=false
elif [[ "$in_jobs" == true && "$line" =~ ^([[:space:]]+)[A-Za-z0-9_-]+:[[:space:]]*(#.*)?$ ]]; then

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review: The job-boundary matcher excludes valid quoted YAML job IDs. Mask state therefore carries into the next quoted job even though GitHub runs it with a fresh mask scope.

Trigger: One job masks $TOKEN, and a later job declared as "second": writes a different $TOKEN without masking it.

grep -oE "$REF_RE" <<< "$1" | while IFS= read -r ref; do
case "$ref" in
'${{'*) echo "${ref//[[:space:]]/}" ;;
*) ref="${ref#\$}"; echo "${ref#\{}" ;;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AI automated review: Shell parameter transformations are reduced to the underlying variable name. A raw mask for $TOKEN therefore incorrectly covers ${TOKEN^^} even though GitHub masks values, not variable names.

Trigger: With TOKEN=abc, a script masks $TOKEN and then writes API_TOKEN=${TOKEN^^}; the checker passes, but ABC remains unmasked.

@rugpanov

Copy link
Copy Markdown
Contributor

🤖 Integration tests ✅ passed for c2bc6917.
View run

anton-107 added a commit that referenced this pull request Nov 25, 2026
…OUTPUT (#2350)

## Why

SEC-35859: `.github/scripts/jfrog-oidc-token.sh` wrote the JFrog token
to `$GITHUB_ENV` without `::add-mask::`, so it showed up in public run
logs. #2291 masked it, and #2334 added a runtime test
(`secret-masking.sh`) for the existing credential scripts. Nothing
stopped a new script or workflow step from making the same mistake. This
adds a static check that covers every script and workflow under
`.github/` (DECO-29706).

## What

- `.github/scripts/check-secret-writes.sh`: a dependency-free bash
check. It scans `.github/**/*.sh`, `*.yml` and `*.yaml`. It checks every
non-comment line that writes to `$GITHUB_ENV` or `$GITHUB_OUTPUT`. The
line fails when either:
- it references a variable or `${{ expression }}` whose name looks like
a credential (`token`, `secret`, `passw(or)d`, `credential`, `api_key`,
`private_key`, or a `key` / `auth` name segment, case-insensitive), or
- the key it writes looks like a credential and its value is not a
literal,

and that same reference was not passed to `::add-mask::` on an earlier
line of the same file.
- Exceptions: `${{ secrets.* }}` and `${{ github.token }}` are skipped,
because Actions masks them automatically. A justified write can end with
`# secret-write-ok: <reason>`.
- `.github/scripts/tests/check-secret-writes.sh` and
`fixtures/secret-writes/`: tests for the check. They run as a new step
of the existing `secret-masking-test.yml` job, so there is no new
workflow.

## What the heuristic catches and misses

It is a line-based heuristic, not a shell parser.

Catches:
- the pre-fix JFrog pattern
- a mask placed after the write
- unmasked step outputs in `${{ }}`
- a credential-named key filled from `$(...)`

Misses:
- Multi-line writes: heredocs into `$GITHUB_ENV`, `{ ...; } >>
"$GITHUB_ENV"`.
- Credentials behind a non-credential name. For example, `PIP_INDEX_URL`
embeds the token. The runtime test still covers that case for the
existing scripts.
- Masks done in another file or another step's script. The mask must
appear earlier in the same file.
- Writes to rc files such as `~/.npmrc`.

`has_token`-style outputs with literal values do not trip it, and
neither do env mappings like `GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN
}}`. Neither one writes a non-literal credential value to a sink. A name
like `KEY_ID` is flagged; the allow comment is the escape hatch for it.

## Tests

`bash .github/scripts/tests/check-secret-writes.sh` checks that:
- `jfrog-oidc-token.prefix.sh`, the pre-fix script taken from before
b4cec4e, is flagged at the write line.
- `mask-after-write.sh` and `unmasked-workflow.yml` are flagged at the
expected lines.
- `jfrog-oidc-token.masked.sh`, a copy of the current script, and
`clean-workflow.yml` pass. `clean-workflow.yml` covers masked,
auto-masked, literal and allow-listed writes.
- Removing the allow comment from `clean-workflow.yml` makes it fail.
- The repository itself passes, with fixtures excluded.

Run locally on this branch: all pass, and `secret-masking.sh` still
passes. A copy of `jfrog-oidc-token.sh` with its `::add-mask::` line
deleted is flagged.

This is the `release/3.x` counterpart of #2347. The scripts are the
same. The fixture YAML uses the 4-space style that `oxfmt` enforces on
this branch, and the repository scan here covers the `release/3.x`
workflows.

This pull request and its description were written by Isaac.

---------

Co-authored-by: Isaac <no-reply@databricks.com>
@github-actions

Copy link
Copy Markdown
Contributor

If integration tests don't run automatically, an authorized user can run them manually by following the instructions below:

Trigger:
go/deco-tests-run/vscode

Inputs:

  • PR number: 2347
  • Commit SHA: f1b043bdd8da45f652193e298ebda90b89516130

Checks will be approved automatically on success.

@rugpanov

Copy link
Copy Markdown
Contributor

🤖 Integration tests running for f1b043bd — ⏳.
View run

exprs+=("${BASH_REMATCH[1]}")
s="${s/"${BASH_REMATCH[1]}"/$'\x01'$((${#exprs[@]} - 1))$'\x01'}"
done
s="${s//&&/$'\n'}"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[blocking] commands() also splits on &&, || and ; inside $(...), so a command substitution like echo "JFROG_TOKEN=$(jq -r .access_token resp.json || true)" >> "$GITHUB_ENV" gets cut into two pieces. The piece with the sink has no KEY= and no credential ref, so the write passes, even though the first version of the script flagged it. Could you protect $(...) and backticks from splitting the same way ${{ }} is protected, and add a fixture line for it?

@anton-107
anton-107 merged commit b19af69 into main Nov 25, 2026
11 of 12 checks passed

This branch was previously deployed

1 inactive deployment
test-trigger-is — f1b043bd Deployed Nov 25, 2026 by anton-107 via Trigger Tests #2617
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants