Skip to content

fix(policies): allow '}' inside single-quoted strings in ISSUE-207/209 - #636

Open
RiccardoBifulco wants to merge 3 commits into
getplumber:mainfrom
RiccardoBifulco:fix/631-expr-brace-in-string
Open

RiccardoBifulco wants to merge 3 commits into
getplumber:mainfrom
RiccardoBifulco:fix/631-expr-brace-in-string

Conversation

@RiccardoBifulco

Copy link
Copy Markdown

Replaces [^}]* in policies/template_injection.rego (ISSUE-207) and policies/github_env_injection.rego (ISSUE-209) with (?:'(?:''|[^'])*'|[^'}])*, so a } inside a GitHub Actions single-quoted string literal (such as format('{0}', github.event.comment.body), including ''-escaped quotes) no longer truncates the ${{ ... }} expression.

Adds policies/template_injection_brace_in_string_test.go covering direct format('{0}', ...), escaped quotes format('it''s {0}', ...), GITHUB_ENV redirection (ISSUE-209), and a negative case with shell single quotes around a safe expression.

Closes #631.

go test ./policies/... passes.

Copilot AI balanced review requested due to automatic review settings November 24, 2026 10:15

Copilot AI 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.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Exypte

Exypte commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Hi @RiccardoBifulco, thanks for your first contribution, and for closing the }-in-string bypass in ISSUE-207/209!

A couple of things before we merge:

  • policies/template_injection_brace_in_string_test.go:25 the safe-quoted-shell case uses github.ref, which no pattern ever matched, so it passes on the old code too. Add a negative case only the new regex gets right, e.g. ${{ format('github.event.issue.title') }} with no finding.
  • policies/template_injection_brace_in_string_test.go:36 only checks that a finding exists. Assert its Subject too, so a regression to the truncated format('{0 subject fails.

@Exypte Exypte assigned Exypte and thomasboni and unassigned Exypte Nov 25, 2026
@Exypte

Exypte commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Hi @RiccardoBifulco, one last thing before we can merge: main requires signed commits, and your two commits on this branch (3717c01 and 98ec495) are unsigned.

Could you set up commit signing (GPG or SSH, see GitHub's guide) and re-sign the branch? Pull first, since I pushed a commit on top of yours:

git pull
git rebase --force-rebase -S HEAD~3
git push --force-with-lease

The commits should then show as "Verified" in the Commits tab. Thanks!

RiccardoBifulco and others added 3 commits November 27, 2026 10:08
The quote-aware _tojson_wrapped read past '{0}', so a toJSON( anywhere
on the line exempted the whole line. format('{0} {1}',
github.event.comment.body, toJSON(github.sha)) and
${{ toJSON(github.sha) }} ${{ github.event.issue.title }} went
unreported. toJSON now has to wrap the untrusted field itself: each
extracted expression is checked with its toJSON(...) calls removed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@RiccardoBifulco
RiccardoBifulco force-pushed the fix/631-expr-brace-in-string branch from c38b5bf to 76abbc9 Compare November 27, 2026 09:08
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/209: a } inside a string literal cuts the expression short

4 participants