Skip to content

feat: label-gated issue-to-PR workflow with injection hardening#693

Merged
Lightheartdevs merged 5 commits intoLight-Heart-Labs:mainfrom
Tony363:feat/ai-issue-to-pr
Apr 2, 2026
Merged

feat: label-gated issue-to-PR workflow with injection hardening#693
Lightheartdevs merged 5 commits intoLight-Heart-Labs:mainfrom
Tony363:feat/ai-issue-to-pr

Conversation

@Tony363
Copy link
Copy Markdown
Contributor

@Tony363 Tony363 commented Mar 31, 2026

Summary

Adds an AI-powered issue-to-PR workflow (split from #683, PR C per review feedback):

When a maintainer applies the ai-implement label to an issue, Claude reads the issue, implements code changes, runs guardrails, and creates a draft PR.

Security hardening (critical review items from #683)

Concern Mitigation
Open to any user Label-gated: only triggers on ai-implement label — only maintainers can apply
Prompt injection Body truncated to 4000 chars + anti-injection preamble
Recursive triggers GITHUB_TOKEN for PR creation
Secret exposure env-block validation pattern
Mutable action tags All actions pinned to commit SHA

Note: AI-generated draft PRs use GITHUB_TOKEN for PR creation. By design,
these PRs won't have CI checks run automatically. A maintainer must interact
(push, close/reopen, or label) to trigger CI.

Setup

Only one secret needed: ANTHROPIC_API_KEY

Create the ai-implement label in your repo before using.

Cost estimate

$5-15 per issue.

Depends on

Test plan

  • CI checks pass
  • actionlint validates workflow YAML
  • Trigger only fires on labeled event with ai-implement
  • No PAT_TOKEN references
  • Issue body is truncated and sandboxed in prompt

🤖 Generated with Claude Code

Copy link
Copy Markdown
Collaborator

@Lightheartdevs Lightheartdevs left a comment

Choose a reason for hiding this comment

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

Audit Review

Best injection hardening of the three AI workflow PRs. The 4-job pipeline (validate -> implement -> guardrails -> create-pr) is well-designed.

Required: Pin @anthropic-ai/claude-code version

npx -y @anthropic-ai/claude-code in the implement job has no version specifier. Same supply chain risk as #692 — a compromised npm package gets arbitrary code execution with ANTHROPIC_API_KEY.

Fix: Pin to a specific version, e.g., npx -y @anthropic-ai/claude-code@0.2.72

Medium: Replace Bash(cat/head/tail/find *) with Read tool

The --allowedTools list includes Bash(cat *), Bash(head *), Bash(tail *), Bash(find *). While GITHUB_TOKEN is not in Claude's env (good isolation), these can still read files on the runner filesystem. Claude Code has a dedicated Read tool that's safer — replace the Bash file-reading tools with it.

Required: Remove gpu.py change

Same fix present in #691 and #692. PR #715 already merged this. Remove to avoid conflicts.

Good — injection defense is solid

  • Anti-injection preamble before issue body
  • Issue body truncated to 4000 chars
  • GITHUB_TOKEN NOT in Claude's env — only ANTHROPIC_API_KEY and issue metadata
  • gh CLI not in --allowedTools — Claude can't use GitHub API
  • Guardrails job: protected file revert, secret scanning (API keys, AWS keys, GitHub tokens, passwords), 1000-line diff size gate, Python/Shell syntax validation
  • Output always draft PR + needs-human-review + ai-generated labels
  • Duplicate PR detection before starting
  • All actions SHA-pinned
  • GITHUB_TOKEN for PR creation (no recursion)
  • Label-gated — only maintainers can trigger via ai-implement label
  • 4000-char truncation on issue body
  • --max-turns 15 cap

@Tony363 Tony363 force-pushed the feat/ai-issue-to-pr branch from 6a75443 to 51c3fe5 Compare April 1, 2026 23:56
Tony363 and others added 2 commits April 1, 2026 20:10
Add AI-powered issue-to-PR workflow that reads GitHub issues, implements
code changes via Claude, and creates draft PRs for review.

Security hardening per review feedback:
- Label-gated: only triggers when 'ai-implement' label is applied by
  a maintainer — prevents arbitrary users from triggering Claude
- Input sanitization: issue body truncated to 4000 chars with
  anti-injection instructions in the prompt
- All actions pinned to commit SHA
- GITHUB_TOKEN used for PR creation (no PAT_TOKEN)
- Secret validation uses env-block pattern
- Guardrails: protected file reverts, secret scanning, diff size gate,
  Python and shell syntax validation

Estimated cost: $5-15 per issue.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Pin @anthropic-ai/claude-code to v2.1.89 (supply chain hardening)
- Remove gpu.py cherry-pick (merged via PR Light-Heart-Labs#715)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Tony363 Tony363 force-pushed the feat/ai-issue-to-pr branch from 51c3fe5 to 0df0778 Compare April 2, 2026 00:10
Tony363 and others added 3 commits April 1, 2026 20:31
Replace Bash(cat *), Bash(head *), Bash(tail *), Bash(find *) with the
dedicated Read/Glob tools which are already in the allowedTools list.
Reduces runner filesystem exposure surface.

Addresses review: PR Light-Heart-Labs#693 pullrequestreview-4047305668

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
… env vars

- Add git apply --check before applying patches (both guardrails and create-pr jobs)
- Expand secret scanning regex to detect GitLab PATs, GitHub OAuth tokens, and PEM private keys
- Move ${{ }} expressions in failure-reason step to env vars for shell safety

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Lightheartdevs Lightheartdevs merged commit 4646236 into Light-Heart-Labs:main Apr 2, 2026
20 checks passed
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.

2 participants