Skip to content

fix(workflow_audit): WF030 job text from the parsed node; tighter guards - #1074

Merged
hyperpolymath merged 7 commits into
mainfrom
claude/wf030-review-followup
Nov 13, 2026
Merged

hyperpolymath merged 7 commits into
mainfrom
claude/wf030-review-followup

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Follow-up to #1073. It auto-merged at the same moment CodeRabbit posted 5 findings. All 5 were real. Each now has a test that fails on main (577eeaf) and passes here.

Changes

  • repository.private == true / != false select private sources. Only == false, != true or a negation count as a guard. (CodeRabbit, security)
  • Needed-job guard: it counts only when the mirror job still needs that job to succeed. If the mirror job's if: uses always(), failure() or cancelled(), the guard is dropped. (CodeRabbit, security)
  • Job text comes from the job's parsed node, not from line slices. A later top-level env: cannot lend a guard to the last job, and flow-style jobs on one line stay separate.
  • Shell comments are now stripped with the existing quote-aware wf_strip_comment/1, so printf ' # ready'; git push --force … keeps its push.
  • needs: items are dereferenced before their value is read, so an alias cannot raise.

Tests

test/rules/mirror_visibility_guard_test.exs gains 7 tests. Five fail on main and pass here. The other 2 cover the inverse guard forms and shell comments in a script.

Before merging, I ran the test files that touch WorkflowAudit (13 files, 333 tests, 0 failures) and mix format --check-formatted.

Auto-merge is left off as you asked: please turn it on once the review threads are resolved (R6).


Generated by Claude Code

Follow-up to #1073: CodeRabbit's five findings, each reproduced by a new
test that fails on main and passes here.

- `repository.private == true` / `!= false` select private sources; only
  `== false` / `!= true` (or a negation) count as a guard.
- A needed job's guard counts only when the mirror job still needs it to
  succeed; `always()`, `failure()`, `cancelled()` in `if:` drop it.
- Job text is built from the job's parsed node, so a later top-level key
  cannot lend a guard and flow-style jobs on one line stay separate.
- Shell comments are stripped quote-aware (wf_strip_comment/1), so
  `printf ' # ready'; git push --force …` keeps its push.
- `needs:` items are dereferenced before reading their value.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
@coderabbitai

coderabbitai Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 13 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 86a8af0e-12d8-4cf8-a251-f9402788578f
Commits

Reviewing files that changed from the base of the PR and between e0628ae and c559b8b.

Files selected for processing: 2

  • lib/rules/workflow_audit.ex
  • test/rules/mirror_visibility_guard_test.exs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Codex's post-merge review of #1073: a guard reached through a chain of
needs (guard -> prepare -> mirror) counts, and the chain stops at a job
whose if: runs after a failure. Continuations also join across CRLF.
Tests pin both, plus an aliased job body (already covered by d3a7467).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
Comment thread lib/rules/workflow_audit.ex Outdated
|> Enum.reverse()
|> Enum.join("\n")
|> String.split("\n")
|> Enum.map_join("\n", &wf_strip_comment/1)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This SF001 finding was already on main; it was not introduced here. I ran StructuredFormat.scan_content/1 on workflow_audit.ex at each commit. It returns the same five regex sites:

  • main 577eeaf: 206, 541, 658, 4049, 4469
  • d3a7467: 206, 541, 658, 4049, 4505
  • c27a008 (head): 206, 541, 658, 4049, 4525

The only change is that the existing ~r/runs-on:\s*([^\n#]+)/ in the cron-drift check moved down, because this PR adds lines above it. The new WF030 code is regex-free on structure: it reads the job's Kyaml node. SF001 is advisory, and replacing that older regex belongs in its own PR.


Generated by Claude Code

@hyperpolymath
hyperpolymath marked this pull request as ready for review November 13, 2026 15:43
@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ❌ Failed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-13T16:01:19.009948Z c559b8b New commits
🔒 Security Review ❌ Failed 2026-11-13T15:54:35.269120Z
We couldn’t complete this review. Comment @codex security review to try again.
c559b8b New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c85e62b1ac

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread lib/rules/workflow_audit.ex Resolved
Comment thread lib/rules/workflow_audit.ex Resolved
Comment thread lib/rules/workflow_audit.ex Resolved
Comment thread lib/rules/workflow_audit.ex Resolved
…ouping

Codex review on c85e62b:
- P1: a needed job whose failure is masked (continue-on-error: true on the
  job or a step) lends no guard; the chain is still followed through it.
- An `if:` with always()/failure()/cancelled() keeps the guard of a need it
  still requires via `needs.<id>.result == 'success'`.
- `== (false)` and `(…private) != true` are guards.
- The API-read alternative no longer matches a job name such as
  `needs.visibility-guard`, which had been lending a false guard.

Three new tests fail on c85e62b and pass here.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

Codex P1 on c85e62b: comments were stripped line by line, so a quote
opened on one line and closed on the next made the parser preserve a
trailing `# … repository.visibility` comment, which then counted as a
guard. Each scalar (a whole run: script) is now stripped in one pass
with quote state carried across its lines. Test fails on 9cf60c8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_0136P7ZkGCWGEyedTtdEHAPT
@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@chatgpt-codex-connector

Copy link
Copy Markdown

This security review couldn’t start because the paying account has exhausted its Codex allowance and has insufficient available credits. The payer can check their balance and add credits in the Codex usage dashboard, then try again. If you do not manage the paying account, contact this repository's admins.

@sonarqubecloud

Copy link
Copy Markdown

@hyperpolymath
hyperpolymath merged commit ecf0140 into main Nov 13, 2026
85 of 86 checks passed
@hyperpolymath
hyperpolymath deleted the claude/wf030-review-followup branch November 13, 2026 15:56

Copy link
Copy Markdown
Owner Author

Red checks that are not caused by this PR (the diff touches only lib/rules/workflow_audit.ex and one test):

  • Elixir Compile (dogfood toolchain): mix test crashes the BEAM with a segmentation fault (exit 139). The run on main at e0628ae fails the same way (job 131994404702). This is the OTP 28 crash (CASE-001/003) that Stop the OTP 28 segfault in scans and the RSR oracle (PinSites miscompile) #1062 pins away.
  • Build Test Images and its Integration Status summary: the Rust toolchain in Containerfile:58 is too old (E0658 atomic_try_update). The same failure is on main.

The earlier "CI Status", "Integration Status" and "Security Status" failures on d3a7467, c27a008, 9cf60c8, 7ecf530 and fe11542 were runs cancelled when a newer commit landed. The Rust dependency audit is green again since #1071 (the quinn-udp bump).


Generated by Claude Code

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c559b8b88f

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Enum.any?([job.node | steps], fn node ->
case Hypatia.Kyaml.get(node, "continue-on-error") do
nil -> false
v -> Map.get(Hypatia.Kyaml.deref(v), :value) in [true, "true"]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Recognize expression-enabled continue-on-error

Fresh evidence beyond the earlier fix is that GitHub supports expression-valued continue-on-error at both the job and step levels, but this check recognizes only the parsed literal values true and "true" (GitHub contexts reference, job-level example). With continue-on-error: ${{ true }} on the visibility-checking job or step, its failure is masked and the mirror can run, yet this branch still lends its guard and suppresses WF030. Treat constant-true expressions—and conservatively any expression that can evaluate true—as potentially masking failure.

Useful? React with 👍 / 👎.

_ -> []
end

Enum.any?([job.node | steps], fn node ->

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Limit step masking to the step containing the guard

When a guard job also has an unrelated optional step with continue-on-error: true, this Enum.any? marks the entire job as failure-masked even though failure of the actual visibility-checking step still fails the job and blocks its dependents. GitHub defines step-level continue-on-error as allowing that specific step to fail (workflow syntax), so this produces a high-severity WF030 false positive for otherwise protected mirrors. Associate the guard with its containing step before applying step-level masking; only job-level masking applies to every guard in the job.

Useful? React with 👍 / 👎.

needs

cond_text ->
if Regex.match?(~r/\b(always|failure|cancelled)\s*\(/, cond_text) do

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Reject guards when success() is negated

The status-function test omits success(), so a mirror condition such as if: ${{ !success() && vars.GITLAB_MIRROR_ENABLED == 'true' }} takes the else branch here and retains every needed guard. GitHub applies no implicit success check once a status function is present, and !success() becomes true after that guard fails (expressions reference); the mirror can therefore run while WF030 is suppressed. Fresh evidence beyond the earlier explicit-result fix is this unhandled negative use of success(); recognize its polarity rather than assuming every condition without the three listed names requires dependency success.

Useful? React with 👍 / 👎.

if Regex.match?(~r/\b(always|failure|cancelled)\s*\(/, cond_text) do
Enum.filter(needs, fn id ->
Regex.match?(
~r/needs\.#{Regex.escape(id)}\.result\s*==\s*['"]success['"]/,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Accept index syntax for explicit dependency success

Fresh evidence beyond the earlier dot-syntax fix is that GitHub officially permits index access to contexts, so always() && needs['visibility-guard'].result == 'success' is equivalent to the recognized dot form (contexts reference). This regex cannot match the index form and drops the guard even though the mirror still requires it to succeed, producing a spurious high-severity WF030 finding. Match both supported access syntaxes when identifying explicit dependency success checks.

Useful? React with 👍 / 👎.

Comment on lines +4418 to +4419
defp strip_shell([c | rest], nil, _ws?, acc) when c in [?", ?'],
do: strip_shell(rest, c, false, [c | acc])

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Preserve escape state before opening shell quotes

For an unquoted escape such as echo \" # TODO github.event.repository.visibility, Bash treats \" as a literal quote and the following # as the start of a comment, but this scanner consumes the backslash separately and then treats the escaped " as an opening quote. It consequently preserves the fake visibility text through the rest of the script, causing an unguarded force-push job to evade WF030. The Bash manual confirms that an unquoted backslash removes the next character's special meaning (escape character); consume outside-quote escape pairs before applying the quote-opening clause.

Useful? React with 👍 / 👎.

case Map.fetch(by_id, id) do
{:ok, need} ->
own = if failure_masked?(need), do: [], else: [id]
own ++ guard_ancestors(need, by_id, MapSet.put(seen, id))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Deduplicate transitive needs across graph branches

The path-local seen set prevents cycles but does not prevent revisiting a shared ancestor through sibling branches, and this function materializes every duplicate path before Enum.any?/2 runs. A valid layered DAG where each pair of jobs needs both jobs in the preceding layer therefore makes guard_ancestors/3 perform exponentially many recursive calls despite containing only linearly many jobs; a few dozen layers can hang or exhaust memory in the workflow audit. Memoize each job's ancestor result or thread a graph-wide visited set so every dependency node is expanded at most once.

Useful? React with 👍 / 👎.

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