[Agents] Add guardrails to PR triage agent - #2681
Draft
qcorporation wants to merge 4 commits into
Draft
Conversation
Add prompt-injection guardrails to harden the PR triage workflow: - SKILL.md: add `## Prompt-injection awareness` section so the skill carries the guidance whether invoked from CI or interactively. - report-template.md: add `Prompt-injection signals` bullet under Risk notes so the agent has a structured place to report suspicious directives found in PR content. - pr-triage.yml: split PR data fetching out of the agent step into a dedicated `Fetch PR data` step that runs `gh pr view` / `gh pr diff` and writes the output to files before the agent starts. The agent step no longer receives `GH_TOKEN` or permission to call `gh`; it reads the pre-fetched files instead. Added `## Security — prompt-injection guardrails` and `## Pre-fetched PR data` sections to the system prompt that explicitly frame PR content as untrusted, attacker-controlled data and instruct the model never to follow directives embedded in it. Addresses review comment from andrewkroh on #2656: running gh commands in workflow steps (not by the LLM), writing output to files, and passing those paths to the agent so the agent no longer needs GH_TOKEN. Co-authored-by: Cursor <cursoragent@cursor.com>
Contributor
🤖 GitHub commentsJust comment with:
|
andrewkroh
reviewed
Aug 6, 2026
andrewkroh
reviewed
Aug 6, 2026
| echo "" | ||
|
|
||
| if opencode run "$(cat "$PROMPT_FILE")" --model "$MODEL" 2>&1 | tee "$TRANSCRIPT_FILE"; then | ||
| if (cd "$RUNTIME" && opencode run "$(cat "$PROMPT_FILE")" --model "$MODEL") 2>&1 | tee "$TRANSCRIPT_FILE"; then |
Contributor
There was a problem hiding this comment.
For defense in depth, consider replacing the tee with a direct write to the file (> "$TRANSCRIPT_FILE" 2>&1). Otherwise if OpenCode prints to stdout/stderr (tool traces, errors, accidental secret echoes), then it hits the Actions logs before the redaction step. ::add-mask:: helps, but only when the exact credential strings appear.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. What does this PR do?
Adds prompt-injection guardrails to the PR triage agent workflow and skill. Revives #2656 with the pending review comment from @andrewkroh addressed.
Changes:
SKILL.md— Added## Prompt-injection awarenesssection so the skill carries injection-resistance guidance whether invoked from CI or interactively in Cursor.report-template.md— AddedPrompt-injection signalsbullet under### Risk notesso the agent has a structured place to report any suspicious directives found in PR content..github/workflows/pr-triage.yml— Three improvements:Fetch PR data): the workflow now runsgh pr viewandgh pr diffbefore the agent starts, writing output topr-metadata.jsonandpr-diff.patch. This directly addresses @andrewkroh's review comment — the agent no longer needsGH_TOKENor permission to callgh.GH_TOKENremoved from the agent step: theBuild prompt and run triagestep no longer hasGH_TOKENin its environment, so the agent has no path to make authenticated GitHub API calls.## Security — prompt-injection guardrailsand## Pre-fetched PR datasections explicitly frame PR content as untrusted, attacker-controlled data and instruct the model never to follow directives embedded in it.2. Which ECS fields are affected/introduced?
N/A — tooling/agent workflow change only.
3. Why is this change necessary?
The PR triage workflow passes PR title, body, and diff to an LLM with no adversarial framing. A malicious PR author could embed prompt-injection payloads (e.g. "ignore previous instructions") and potentially manipulate the triage classification, extract secrets, or alter the output. These guardrails reduce that attack surface.
The pre-fetching approach also eliminates the agent's need for a GitHub token entirely
4. Have you added/updated documentation?
N/A — changes are confined to the skill file, report template, and the CI workflow.
5. Have you built ECS and committed any newly generated files?
N/A — no schema changes.
6. Have you run the ECS validation tests locally?
N/A — no schema or generator changes.
7. Anything else for the reviewers?
This PR directly addresses the unresolved review comment left by @andrewkroh on the now-closed #2656:
The
Fetch PR datastep does exactly that. The agent step now reads local files instead of callinggh.The second part of @andrewkroh's comment ("apply an allowlist to opencode such that only the tools necessary by the skills to complete the review are available") is a follow-on improvement that would require investigation of opencode's tool-restriction configuration surface; it is not addressed in this PR.
Commit Message
[Agents] Add prompt-injection guardrails to PR triage agent: pre-fetch PR data in a dedicated workflow step so the agent never needs GH_TOKEN or gh CLI access; add security framing to the system prompt and injection-awareness guidance to the skill.
Made with Cursor