Skip to content

fix(WF017): recognise the raw env-mapping secret gate - #687

Merged
hyperpolymath merged 8 commits into
mainfrom
fix/wf017-raw-env-gate
Aug 7, 2026
Merged

hyperpolymath merged 8 commits into
mainfrom
fix/wf017-raw-env-gate

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

WF017 reports correctly-gated workflows, and pushes authors toward a construction that cannot work.

The rule understood one env form — comparison inside the env assignment:

env:
  HAS_TOKEN: ${{ secrets.X != '' }}
steps:
  - if: env.HAS_TOKEN == 'true'

but not the form the estate documents and uses, where the raw secret is mapped and the comparison lives in the if::

env:
  TOKEN: ${{ secrets.X }}
steps:
  - if: env.TOKEN != ''

Both are valid. Without the second clause the rule fires on every workflow using it — 7 alerts in hyperpolymath/standards alone, on files whose own comments explain the pattern. Those 7 are part of what currently blocks every merge in that repository, via its code_scanning ruleset rule.

⚠ Why the rule must not ask for if: secrets.X != ''

The secrets context is not available in if:. A workflow using it there is rejected before any job is created — a startup_failure with no log, no jobs and no check run, invisible to gh pr checks. That fault silently killed CI in 51 estate repositories.

So the rule's own advice text, taken literally, breaks the workflow it is trying to protect. The env indirection is the only construction that works.

Verification

Three tests added:

  • the raw-env test fails without this change and passes with it (verified by reverting the rule alone)
  • the boolean-env form still passes
  • an action with no gate at all is still reported — a precision fix must not blind the rule

The two pre-existing failures in this test file are unrelated and present before this change.

🤖 Generated with Claude Code

WF017 (`secret_action_without_presence_gate`) reports correctly-gated
workflows, and it pushes authors toward a construction that cannot work.

The rule already understood one env form — the comparison placed INSIDE the env
assignment:

    env:
      HAS_TOKEN: ${{ secrets.X != '' }}
    steps:
      - if: env.HAS_TOKEN == 'true'

but not the form the estate actually documents and uses, where the raw secret
is mapped and the comparison lives in the `if:`:

    env:
      TOKEN: ${{ secrets.X }}
      steps:
      - if: env.TOKEN != ''

Both are valid. Without the second clause the rule fired on every workflow
using it — 7 alerts in `hyperpolymath/standards` alone, on files whose own
comments explain the pattern.

⚠ WHY THE INDIRECTION EXISTS, AND WHY THE RULE MUST NOT ASK FOR
`if: secrets.X != ''`. The `secrets` context is NOT available in `if:`. A
workflow that uses it there is REJECTED BEFORE ANY JOB IS CREATED — a
startup_failure with no log, no jobs and no check run, which is invisible to
`gh pr checks` and silently killed CI in 51 estate repositories. So the rule's
own advice text, taken literally, breaks the workflow it is trying to protect.
The env indirection is the only construction that works, and the rule now
recognises both of its spellings.

Three tests added. The raw-env test FAILS without this change and passes with
it (verified by reverting the rule alone), and a third asserts an action with
no gate at all is STILL reported — a precision fix must not blind the rule.

The two pre-existing failures in this file (`audit/2 returns comprehensive
report`, `check_missing_workflows/1 flags all missing when empty`) are
unrelated and present before this change; verified by running the suite against
the unmodified rule.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
Comment on lines +1044 to +1057
env_raw_gate? =
case Regex.run(
~r/(\w+):\s*\$\{\{\s*secrets\.#{Regex.escape(secret_name)}\s*\}\}/,
stripped
) do
[_, env_name] ->
Regex.match?(
~r/if:[^\n]*env\.#{Regex.escape(env_name)}\b[^\n]*(!=|==)/,
stripped
)

_ ->
false
end

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: Raw env-gate match is file-global, can mask ungated steps

env_raw_gate? runs its regexes over the whole-file stripped content rather than the current job/step, and the first (\w+): ${{ secrets.X }} capture will also match the action's own with: <param>: ${{ secrets.X }} line. So a workflow with two secret-consuming steps where only one is properly gated (or where an unrelated if: env.<name> != exists elsewhere in the file) can suppress a genuine WF017 alert on the ungated step. This mirrors the existing behaviour of env_boolean_gate?, but the raw form widens it since the pattern also matches the with: mapping line. Consider scoping the env-name lookup to the enclosing job block and excluding the with: line, and add a test with one gated + one ungated secret step to confirm the ungated one is still reported.

Was this helpful? React with 👍 / 👎

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ This PR is blocked due to unresolved code review findings.

Configure merge blocking · Maintainers can dismiss this review.

@gitar-bot

gitar-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown

Note

Automatic reviews are paused because your trial's included automatic processing has been used for this period. Upgrade now, or comment "Gitar review" to run a review anytime.
Learn more

Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Expands WF017 rule logic to recognise raw env-mapping secret gates alongside existing boolean comparisons, successfully resolving false positives across estate repositories. Consider scoping the file-global env_raw_gate? regex match to avoid potentially masking ungated steps.

Auto-approved and auto-merge armed: No blocking issues found.
Please see Auto-approve Docs for details on setting custom approval criteria. — merges when pipeline and required approvals pass.

💡 Edge Case: Raw env-gate match is file-global, can mask ungated steps

📄 lib/rules/workflow_audit.ex:1044-1057

env_raw_gate? runs its regexes over the whole-file stripped content rather than the current job/step, and the first (\w+): ${{ secrets.X }} capture will also match the action's own with: <param>: ${{ secrets.X }} line. So a workflow with two secret-consuming steps where only one is properly gated (or where an unrelated if: env.<name> != exists elsewhere in the file) can suppress a genuine WF017 alert on the ungated step. This mirrors the existing behaviour of env_boolean_gate?, but the raw form widens it since the pattern also matches the with: mapping line. Consider scoping the env-name lookup to the enclosing job block and excluding the with: line, and add a test with one gated + one ungated secret step to confirm the ungated one is still reported.

🤖 Prompt for agents
Code Review: Expands WF017 rule logic to recognise raw env-mapping secret gates alongside existing boolean comparisons, successfully resolving false positives across estate repositories. Consider scoping the file-global `env_raw_gate?` regex match to avoid potentially masking ungated steps.

1. 💡 Edge Case: Raw env-gate match is file-global, can mask ungated steps
   Files: lib/rules/workflow_audit.ex:1044-1057

   `env_raw_gate?` runs its regexes over the whole-file `stripped` content rather than the current job/step, and the first `(\w+): ${{ secrets.X }}` capture will also match the action's own `with: <param>: ${{ secrets.X }}` line. So a workflow with two secret-consuming steps where only one is properly gated (or where an unrelated `if: env.<name> !=` exists elsewhere in the file) can suppress a genuine WF017 alert on the ungated step. This mirrors the existing behaviour of `env_boolean_gate?`, but the raw form widens it since the pattern also matches the `with:` mapping line. Consider scoping the env-name lookup to the enclosing job block and excluding the `with:` line, and add a test with one gated + one ungated secret step to confirm the ungated one is still reported.

Options

Display: compact → Showing less information.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Important

Your trial ends in 3 days — upgrade now to keep code review, CI analysis, auto-apply, custom automations, and more.

Was this helpful? React with 👍 / 👎 | Gitar

@gitar-bot
gitar-bot Bot enabled auto-merge (squash) August 7, 2026 06:55
gitar-bot[bot]
gitar-bot Bot previously approved these changes Aug 7, 2026

@gitar-bot gitar-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Gitar has auto-approved this PR and enabled auto-merge (configure)

@gitar-bot gitar-bot Bot added the gitar-approved Added by Gitar label Aug 7, 2026
Installers routinely PRINT the command a user should run:

    echo "  curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh"
    echo "  curl -sSL https://get.haskellstack.org/ | sh"

The rule's pattern matches anywhere on the line, so it reported both — files
that are being helpful, not dangerous. Two of the six shell_download_then_run
alerts currently blocking every merge in `hyperpolymath/standards` are this.

⚠ THE TEST IS NOT "THE LINE STARTS WITH echo". `echo hello | sh` really does
execute, and so does `printf '%s' x | bash`. The question is whether the
pipe-to-shell sits INSIDE the quotes or outside them. So the quoted segments
are stripped and the pattern re-tested against what remains: if it no longer
matches, every match was inside a string. Escaped quotes are honoured.

Implemented as a `context_safe_line?/2` clause, which is the existing extension
point for exactly this — `secret_detected` already has one.

Four tests, covering both directions: echoed advice and printf'd advice are
suppressed; `echo hello | sh` and a genuine `curl … | bash` stay reported. A
precision fix that cannot still catch the real thing is not a precision fix.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
hyperpolymath and others added 6 commits August 7, 2026 08:33
Cargo's convention puts benchmarks in `benches/`, and a benchmark that unwraps
or panics is normal — the failure costs a benchmark run, not a user's session,
and setup code in a bench has no error path to take. `test/` and `tests/` were
already exempt for exactly this reason; `benches/` was missed.

⚠ EXEMPTED FOR code_safety ONLY, DELIBERATELY NOT FOR security_errors. The
obvious implementation is to add "benches/" to @training_corpus_paths, which is
shared by four rule modules — that would also stop the SECRET rules scanning
benchmark files. A hardcoded credential in a bench is a real leak like any
other, and it would have been hidden by a change whose stated purpose was
unwrap noise. The exemption is therefore attached to the code_safety module
alone.

Three tests, including the one that matters: a `secret_detected` finding inside
`benches/` is still reported.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
`ncl_http_url` flagged two lines in k9-svc/register.ncl, which embeds mime-info
and plist templates:

    <mime-info xmlns="http://www.freedesktop.org/standards/shared-mime-info">
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
                           "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

Neither is an endpoint. An XML namespace name and a DOCTYPE public identifier
are IDENTIFIERS — the XML specification is explicit that a namespace name is
never dereferenced. Nothing connects to them, so there is no transport to
secure.

⚠ This is a finding that CANNOT BE ACTED ON EVEN IN PRINCIPLE. Rewriting either
to https changes the identifier and breaks the schema match, so the only
available responses were to suppress it or to break the file. A rule that can
only be satisfied by breaking the thing it inspects trains people to ignore it.

Excludes xmlns attributes and the well-known DTD/schema hosts. Three tests,
including one asserting a genuine `endpoint = "http://api.example.com/v1"` is
still flagged — the exclusion is for identifiers, not for http generally.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
…ing them

This is the upstream cause of a required gate failing in
metadatastician/standards#584, traced from the merge block down.

`expect_in_hot_path` is meant not to fire inside a `LazyLock` body, because
that body runs ONCE — the rule carries `context: :runtime_path` and
`strip_lazy_initialisers` is supposed to elide those bodies first. The
intent, in the existing comment, was "brace-counting from the initialiser
opener". The implementation was a regex with two hard-coded levels of nesting.

⚠ REGEXES CANNOT COUNT, and the nesting here is unbounded because the elided
body contains a REGEX LITERAL whose own groups nest arbitrarily:

    LazyLock::new(|| Regex::new(r"\[\|\s*((?:'[A-Za-z]+\s*,?\s*)*)\|]").expect(..))

That pattern is one level deeper than the approximation allowed, so the
initialiser was not elided and its `.expect(` was reported as a hot-path
finding — on a body that by definition runs once. Measured in k9-svc/lsp:
FOUR of five statics elided and the fifth did not, differing only in having one
more capture group. A rule that fires or not depending on how many groups an
unrelated pattern contains is not measuring anything.

Replaced with an actual paren counter.

⚠ RUST STRING LITERALS ARE HONOURED, INCLUDING RAW STRINGS. `r#"..."#` exists
precisely so a literal may contain `"`, and regex patterns use it for exactly
that — `r#"(install|deploy)\s*=\s*"([^"]*)""#`. Treating those embedded quotes
as delimiters desynchronises the count. That was not hypothetical: after the
plain-string case was handled, this exact pattern still survived elision.

⚠ THE DANGEROUS FAILURE MODE IS SILENT. A desynchronised counter does not
error — it swallows the remainder of the file, blinding every code_safety rule
after that point while still reporting success. There is a test for it.

Four regression tests: nested capture groups elide; hash raw strings elide; a
genuine per-call `.expect(` two lines later is STILL reported; and an
unbalanced paren inside a string does not swallow the file. 41 tests pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
…y set

hypatia's own required gate `governance / Validate Hypatia Baseline` was
failing with exit code 2 — the SCHEMA-INVALID code, not a findings failure:

    error: baseline violates hypatia-baseline.schema.json:
    entry[0]: unknown key action
    entry[1]: unknown key action
    ...

All 44 entries carried `action`, 9 carried `reason` and 1 `trusted`. Those are
fields of the SCANNER'S RAW FINDING FORMAT, not of a baseline entry — the file
was generated straight from scan output without trimming to the nine keys the
schema permits. The schema is a closed key set, so one stray field invalidates
the WHOLE file and the gate cannot even begin evaluating findings.

⚠ THE FAILURE READS AS THE OPPOSITE OF WHAT IT IS. Exit 2 means "your baseline
is malformed"; a maintainer sees a red `Validate Hypatia Baseline` and looks
for unacknowledged findings, which is the one thing it is not. This repository
gates on its own scanner and was blocked by its own acknowledgement file.

Stripped to the closed key set; the validator now accepts it, and every entry
still satisfies file XOR file_pattern.

Fixed on this branch because this pull request cannot merge until it is: it is
a required check for hyperpolymath/hypatia.

Co-Authored-By: Claude Opus 5 <[email protected]>
Signed-off-by: Jonathan D.A. Jewell <[email protected]>
…uage file

The `Validate Hypatia Baseline` gate reported 210 findings once its baseline
became schema-valid. 203 were `unpinned_action`. Those are a real defect, not
baseline material, so they are fixed rather than acknowledged.

**Pinning (203).** Every `uses:` ref resolved to a verified commit SHA via the
commits API, with the original tag kept as a trailing comment so a version bump
stays reviewable in a diff. 40 distinct refs across 21 workflow files.

`dtolnay/rust-toolchain` needed care: it resolves WHICH TOOLCHAIN to install
from its own ref, so a bare SHA pin installs nothing. It is pinnable only with
the toolchain moved into an explicit `with: toolchain:` input — 20 of 22 call
sites already did this; the other 2 now do. This is a genuine pin, not an
exemption.

**Orphan gitlinks (4 x structural_drift/SD005).** `.claude/worktrees/{arango-hc,
e2e-diag,reflexive-fix,rescan-ff}` were committed as mode-160000 gitlinks with
no `.gitmodules`, so every clone carried four broken submodule pointers to
commits that exist in no repository. Removed, and the path is now ignored so it
cannot recur.

**Banned language (1).** `resolve.py` was a throwaway merge-conflict resolver at
the repo root, referenced by nothing. Python is banned estate-wide; a scratch
script is not a reason to hold an exception. Deleted.

**Missing timeout (1).** `inbox-steward-intake.yml`'s `summary` job was the only
job in the file without `timeout-minutes`.

Verified: all 27 workflows parse; the estate duplicate-key scanner reports them
clean; no unpinned ref remains; every dtolnay step names its toolchain.
…ne pinning

Reverses the inline SHA-pinning in the previous commit, which was wrong and
measurably harmful, and fixes the rule that motivated it.

**Why the pinning was wrong.** This account enforces GitHub Actions lockfiles.
`.github/workflows/actions.lock` resolves each symbolic ref to a verified
commit, together with owner_id, repo_id and the transitive dependencies of
composite actions — which an inline SHA cannot express at all. The two
mechanisms are mutually exclusive, not additive: `gh actions-lock` refuses a
ref that no tag or branch contains, so inline-pinning an action REMOVES it from
the lockfile.

Measured, not assumed. Inline-pinning 40 refs across 21 workflows:
  * put 14 workflows into `startup_failure` (0 on the parent commit) — the
    lockfile no longer matched, so they were rejected before any job started;
  * dropped `dtolnay/rust-toolchain` from 7 lockfile entries, with
    `gh actions-lock` reporting "no tag or branch contains this commit —
    a symbolic ref is required for the lockfile".

So `actions/[email protected]` on this repository IS pinned, and reporting it as
unpinned drives a change that reduces supply-chain coverage.

**The rule fix.** `check_unpinned_actions/2` takes the lockfile via
`opts[:actions_lock]` and reports covered refs as `lockfile_pinned_accepted`
(`:info`, with rationale) instead of `unpinned_action`. Matching normalises to
the `owner/repo@ref` form the lockfile keys on, lowercased, so subpath actions
(`github/codeql-action/init@v4`) match their root entry. With no lockfile the
behaviour is byte-identical to before.

Result on this repository: 203 `unpinned_action` -> 0, with 203 accepted. Six
tests cover both directions, including that the same ref WITHOUT a lockfile is
still reported, that a ref absent from the lockfile is still reported, and that
a different ref of a locked action is not accepted.

**One real gap closed.** The scan left 2 findings the lockfile genuinely did not
cover: `trufflesecurity/[email protected]` in security-policy.yml was used but
never locked. `gh actions-lock` now pins it to a verified commit.

Retained from the previous commit (all genuine):
  * `.claude/worktrees/*` removed — four mode-160000 gitlinks with no
    `.gitmodules`, so every clone carried broken submodule pointers; now ignored
  * `resolve.py` deleted — a scratch merge-conflict resolver in a banned
    language, referenced by nothing
  * `inbox-steward-intake.yml`'s `summary` job given `timeout-minutes`

Verified: workflow_audit tests 55 pass / 2 fail, the same 2 failing before this
change (`check_missing_workflows`, unrelated).
@hyperpolymath
hyperpolymath merged commit 83c6ba4 into main Aug 7, 2026
56 of 82 checks passed
@hyperpolymath
hyperpolymath deleted the fix/wf017-raw-env-gate branch August 7, 2026 09:15
hyperpolymath added a commit that referenced this pull request Aug 7, 2026
main fails mix format --check-formatted on the files PR #687 touched.
The reformatted lines are upstream's (elide_lazy_inits/find_open_paren
in code_safety, pin_exempt_accepted in workflow_audit, the new
scanner_suppression tests) — mechanical mix format output only.

Co-Authored-By: Claude Opus 5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gitar-approved Added by Gitar

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant