Repository navigation
fix(workflow_audit): WF030 job text from the parsed node; tighter guards - #1074
Conversation
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
|
Warning Review limit reachedYou'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. View limit details
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. |
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
| |> Enum.reverse() | ||
| |> Enum.join("\n") | ||
| |> String.split("\n") | ||
| |> Enum.map_join("\n", &wf_strip_comment/1) |
There was a problem hiding this comment.
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
|
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 Review Summary: ❌ FailedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 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".
…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
|
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
|
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. |
|
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. |
|
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. |
|
|
Red checks that are not caused by this PR (the diff touches only
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 |
There was a problem hiding this comment.
💡 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"] |
There was a problem hiding this comment.
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 -> |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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['"]/, |
There was a problem hiding this comment.
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 👍 / 👎.
| defp strip_shell([c | rest], nil, _ws?, acc) when c in [?", ?'], | ||
| do: strip_shell(rest, c, false, [c | acc]) |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 👍 / 👎.



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/!= falseselect private sources. Only== false,!= trueor a negation count as a guard. (CodeRabbit, security)if:usesalways(),failure()orcancelled(), the guard is dropped. (CodeRabbit, security)env:cannot lend a guard to the last job, and flow-style jobs on one line stay separate.wf_strip_comment/1, soprintf ' # 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.exsgains 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