Skip to content

fix(policies): don't flag boolean expressions in ISSUE-207 and ISSUE-209 - #630

Open
Exypte wants to merge 3 commits into
mainfrom
fix/624-issue-207-boolean-expressions
Open

Exypte wants to merge 3 commits into
mainfrom
fix/624-issue-207-boolean-expressions

Conversation

@Exypte

@Exypte Exypte commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

What type of PR is this?

fix

What this PR does / why we need it:

ISSUE-207 (template injection) and ISSUE-209 ($GITHUB_ENV / $GITHUB_PATH injection) fired on any ${{ }} that mentions a free-text field, even when the expression can only expand to true or false:

- run: echo "is_approve=${{ github.event.comment.body == '/approve' }}" >> "$GITHUB_OUTPUT"

A comparison (==, !=, <, >, <=, >=), a ! negation, a contains() / startsWith() / endsWith() call, or an && / || combination of only those carries no payload. && and || expand to one of their operands, so ${{ cond || github.event.comment.body }} must still fire, and does.

  • New policies/lib/expression.rego (lib.expression.reduced) removes the boolean-valued parts of an expression: string literals, boolean calls, negated groups, comparisons, and groups made only of those. The existing injection patterns then run on what's left, so a free-text field that survives can reach the script.
    • Calls to any other function keep their arguments in view, so fromJSON(F) still fires.
    • An expression it can't read (nesting deeper than three groups, an unterminated literal) is left whole and fires as before.
  • template_injection.rego uses it in _expression_controlled, so the finding, its line and its subject stay consistent.
  • github_env_injection.rego checks every untrusted value through lib.expression.untrusted: direct writes, env: values, lines and subjects. The unsafe_patterns lists are unchanged, so the test that keeps them in sync still holds.
  • docs/GITHUB_ISSUES.md documents the exclusion under ISSUE-207 and points to it from ISSUE-209.

Which issue(s) this PR is related to:

Closes #624

Special notes for your reviewer:

  • The behavior was checked on GitHub first: getplumber-examples/github-actions-miscellaneous-knowledge @ test/2026-11-20-boolean-expressions, run 44718136654.
    • Each safe form was evaluated against 9 field values, including $(touch /tmp/injected), and only ever rendered true or false.
    • The five && / || operand cases rendered the field and ran the payload.
    • The new fixtures follow that table.
  • Rego has no recursion, so the reduction makes three fixed passes. Anything deeper falls back to the old behavior, which fires.
  • Separate gap, not changed here: ${{ format('{0}', github.event.issue.title) }} doesn't fire on main either, because the extraction pattern \$\{\{[^}]* stops at the } inside '{0}'. Tracked in ISSUE-207/209: a } inside a string literal cuts the expression short #631.
  • The site docs are updated in docs(issues): boolean expressions in ISSUE-207 and ISSUE-209 getplumber.io#560, to merge after the release that ships this.
  • A /code-review pass found three boolean forms that still fired: contains() around another call, a group on one side of a comparison, and a comparison with an index. The second commit fixes them, with fixtures. The third, after the claude-review findings, reads an index holding a name as that property (github.event.comment['body'] is github.event.comment.body). Bracket references like that now match the injection patterns, which missed them before.

Does this PR introduce a user-facing change?

ISSUE-207 (template-injection) and ISSUE-209 (github-env-injection) no longer report an expression that can only expand to true or false: a comparison, a ! negation, a contains() / startsWith() / endsWith() call, or an && / || combination of only those. A free-text field used directly as an && / || operand is still reported.

How was this tested?

  • New fixtures and cases in TestIssue206_TemplateInjection and TestIssue209_GitHubEnvInjection:
    • ISSUE-207: clean_boolean_expression.yml (the issue's workflow), clean_boolean_forms.yml (21 safe forms, a ternary, a literal containing &&, ( and ==, nested calls, compared groups, an index), violation_boolean_operand.yml (11 jobs, all must fire, including a parenthesized field, nesting past the three passes and a named index) and violation_index_field.yml (github['head_ref']).
    • ISSUE-209: clean_boolean_to_env.yml (a direct write, plus an env: value written to $GITHUB_ENV and $GITHUB_PATH), violation_boolean_operand_to_env.yml, violation_boolean_operand_env_bound.yml (redirect and heredoc) and violation_index_to_env.yml.
    • The new cases failed before the change and pass after.
  • make build and make test pass.
  • make lint reports 7 govet findings about reflect.Ptr in configuration/schema.go, configuration/schema_test.go and control/catalog.go. This PR doesn't touch those files.
  • plumber analyze on a clone of getplumber-examples/cli-working-lab with the issue's workflow plus an ||-leak job: only the leak job (comment/leak) got ISSUE-207, and the issue's job (comment/check) got nothing.

AI usage disclosure:

YES. Claude Code (Claude Opus 5.5) reproduced the bug, wrote the Rego helper, the fixtures and the docs, and ran the tests and the CLI check. The approach and the GitHub experiment it relies on were reviewed by the author, who is responsible for the change (CONTRIBUTING.md, AI_POLICY.md).

🤖 Generated with Claude Code

A ${{ }} expression that is a comparison, a ! negation, a contains() /
startsWith() / endsWith() call, or an && / || combination of only those
expands to true or false, so a free-text field inside it never reaches
the script. lib.expression reduces such parts away before the injection
patterns run; && and || still expand to an operand, so a field that is
itself an operand keeps firing.

Checked on GitHub in getplumber-examples/github-actions-miscellaneous-knowledge,
branch test/2026-11-20-boolean-expressions.

Closes #624

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread policies/lib/expression.rego Resolved
Comment thread policies/lib/expression.rego Resolved
…ean expressions

Review of #630 found boolean expressions the reduction still flagged:
contains() around another call, such as
contains(fromJSON('["/a","/b"]'), github.event.comment.body); a group on
one side of a comparison, such as (body || 'a') == 'b'; and a comparison
holding an index, such as body == github.event.commits[0].message.

A bare group no longer takes the parentheses of a call whose inner call
was just reduced, a group next to a comparison operator counts as
boolean, and an index reads as a property. That last change also makes
github.event['head_commit'].message match the injection patterns, which
missed it before.

ISSUE-209 now calls lib.expression.untrusted instead of its own copy, and
the docs example for boolean expressions moves after the fix example.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread policies/lib/expression.rego Resolved
Comment thread policies/github_env_injection.rego Resolved
expression.reduced turned every index into .__i__, so
github.event.comment['body'] and github['head_ref'] lost their field name
and no injection pattern matched them. An index holding one name now
reads as that property before literals are blanked. Any other index
still becomes .__i__.

New fixtures cover what the PR review asked about: a parenthesized
field, an expression nested past the three passes, a named index in
ISSUE-207 and ISSUE-209, and an env-bound || operand written to
$GITHUB_ENV with a redirect and through a heredoc.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.

ISSUE-207: false positive on expressions that evaluate to a boolean

1 participant