Repository navigation
fix: prevent context injection into prompt template directives - #73586
Conversation
Keep context and experiment values opaque until author-owned directives are parsed and selected. Align renderer code-region protection with sanitization and cover adversarial substitutions and runtime imports. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
✅ Design Decision Gate 🏗️ completed the design decision gate check. See the comment below for the result and any generated ADR draft. Design Decision Gate 🏗️Outcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
✅ PR Code Quality Reviewer completed the code quality review.
|
|
✅ Test Quality Sentinel completed test quality analysis. Test Quality SentinelOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
|
🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅
|
|
✅ Ponytail Reviewer completed successfully! Ponytail ReviewerOutcome: The agent completed and reported no action. A no-op output alone does not verify that all required work was completed or that publication was possible. Agent messages are omitted from this comment. The category uses structured run status, not interpretation of agent prose.
|
There was a problem hiding this comment.
Review: no blocking findings
I found no actionable correctness, security, or performance issues in the changed lines. The specialist pass was unavailable because its file access was denied; this review is based on the pre-fetched diff and targeted source inspection only.
🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.7K
Comment /review to run again
There was a problem hiding this comment.
Skills-Based Review 🧠
Applied /diagnosing-bugs and /codebase-design (triage agent unavailable — used the documented fallback heuristic: classified as a security bugfix, prioritized interpolate_prompt.cjs, sanitize_content_core.cjs, runtime_import.cjs, render_template.cjs as high-impact files).
This is a solid, well-scoped fix for CWE-1336. The opaque-token (protectValue/restoreValues) design cleanly separates "untrusted context insertion" from "author-directive parsing," and reusing the sanitizer's code-region logic in the renderer closes a real gap (inline-code spans weren't previously protected the same way as fenced blocks). The new interpolate_prompt_injection.test.cjs suite is a strong, genuinely adversarial regression suite (prose/inline/fenced contexts × 14 injection payloads, plus nested imports, split prompts, and extracted-artifact boundaries).
Left two inline suggestions, neither blocking:
📋 Key Themes & Highlights
Key Themes
/codebase-design:sanitize_content_core.cjs'sapplyToNonCodeRegionsnow decides whether to re-throw a fence-parsing error based onarguments.length >= 3rather than on whether a meaningfulcodeFnwas supplied. This is a subtle trap for future refactors (e.g. a caller explicitly passingundefinedas the third arg would silently flip behavior)./tdd: The new regression suite doesn't cover a forged/replayed opaque marker (\x00VALUE_<uuid>_<n>\x00) appearing in untrusted content. Given a fresh UUID per run this should fail closed (via thevalue === undefinedthrow inrestoreValues), but that fail-closed behavior isn't asserted anywhere, so a future change could silently make it fail open instead.
Verified, non-issues
- Confirmed
render_template.cjs's standalonemain()(which doesn't threadresolveCondition) is not a separately invoked pipeline step — it's only listed insetup.sh's file-bundling manifest and used as a library byinterpolate_prompt.cjs(protected) andfirewall_blocked_domains.cjs(internal-only template, no untrusted context). Not a gap. - Verified
evaluateExpression/processExpressionsinruntime_import.cjscorrectly leaves unresolved${{ }}expressions unprotected (so they remain literal GHA syntax for later evaluation) while wrapping all resolved values — the protect/no-protect split is deliberate and correct. - Verified ordering in
extract_inline_sub_agents.cjs:restoreValuesruns before frontmatter preservation and experiment-reference resolution, so no opaque token can leak into the experiment-reference regex.
Caveat
- Could not execute
interpolate_prompt_injection.test.cjsin this review sandbox (network/cert restrictions blockednpm/vitest). The review relies on static reading of the new test file and diff; the PR description states all 1,254 tests across 11 suites passed, which I was unable to independently verify here.
Positive Highlights
- ✅ Per-run
randomUUID()markers (both ininterpolate_prompt.cjsandrender_template.cjs) prevent an attacker from pre-seeding a literal marker string that collides with the sanitizer's placeholder — a real improvement over the prior static\x00FENCE\x00sentinel. - ✅ Single combined-regex interpolation pass in
interpolateVariablescorrectly prevents recursive placeholder expansion (tested explicitly). - ✅ Documentation (
templating.md) updated to describe the new processing order.
@copilot please address the review comments above.
🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · sonnet50 · ~191 AIC · ⌖ ~16 AIC · ⊞ 10.7K
Comment /matt to run again
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved critical defects cause runtime data to trigger unintended substitutions, discard authored skill instructions, and leave conditional branches and directive markers in rendered prompts.
5 open issues
Parse author frontmatter before restoring runtime values · New Keep restored context opaque through all substitution stages · New Fix unclosed workflow fence hiding the closing directive · New Avoid substituting experiment references inside quoted conditions · New Restore code placeholders in parsed conditions before evaluation · New
What changed in this PR
This PR hardens gh-aw’s runtime prompt pipeline against context-supplied template directives by separating substituted data from author-owned template structure.
Changes:
- Keeps context and experiment values opaque during directive parsing and uses single-pass interpolation.
- Shares inline/fenced code handling and restores literal values in import provenance and extracted artifacts.
- Adds adversarial regression coverage and documents the processing boundary.
| File | Description |
|---|---|
docs/src/content/docs/reference/templating.md |
Documents directive boundaries and runtime processing order. |
actions/setup/js/template_branch.cjs |
Resolves condition values after branch parsing. |
actions/setup/js/sanitize_content_core.cjs |
Adds optional transformations for protected code regions. |
actions/setup/js/runtime_import.cjs |
Carries value protection through nested file and URL imports. |
actions/setup/js/render_template.cjs |
Protects inline and fenced code during conditional rendering. |
actions/setup/js/is_truthy.cjs |
Supports multiline comparison operands. |
actions/setup/js/interpolate_prompt.cjs |
Coordinates opaque substitutions, condition evaluation, and literal restoration. |
actions/setup/js/interpolate_prompt_injection.test.cjs |
Covers injection payloads, imports, artifacts, and split prompts. |
actions/setup/js/extract_inline_sub_agents.cjs |
Adds literal restoration when writing sub-agent artifacts. |
actions/setup/js/extract_inline_skills.cjs |
Adds literal restoration when writing skill artifacts. |
Review effort: Max (auto)
Address PR review feedback on inline artifact metadata, quoted conditions, code-region callbacks, replayed markers, and nested Dependabot example fences. Persist the author-owned opaque view across activation and deferred substitution and regenerate workflow locks for the provenance artifact. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Regarding the Design Decision Gate notice: no code change is needed because this is completion telemetry, not an actionable finding or ADR request. The no-op status is not being used as evidence of correctness. |
|
Regarding the Code Quality Reviewer notice: no additional code change is needed because this comment only reports review completion. The associated review reported no blocking findings. |
|
Regarding the Test Quality Sentinel notice: no code change is needed because it contains no actionable finding. Correctness is supported by the regression suites, not the no-op telemetry. |
|
Regarding the Skills Reviewer notice: both associated inline suggestions were addressed in commit |
|
Regarding the Ponytail Reviewer notice: no code change is needed because the comment reports completion without an actionable finding. The no-op telemetry is not being treated as independent validation. |
|
Rechecked the repeated notices and prior responses below. No additional code changes are warranted, and completion/no-action telemetry is not being treated as correctness evidence.
|
Remove all harness-owned prompt artifacts on success and failure, with cleanup regression coverage. Refresh golden expectations for the prompt literal sidecar artifact. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@copilot merge main, fix ci failures |
…ate-injection Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Merged latest |
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Keep missing-import location, hint, and raw-path privacy assertions while enforcing main's isolated error-chain contract. Pass subtest handles to operations so required assertions report on the correct test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
🎉 This pull request is included in a new release. Release: |


Fixes code-scanning alert 1042 (CWE-1336). Raw context substitutions could introduce conditional template markers that removed or changed author instructions. Sanitized comments could also retain active markers inside inline code because the sanitizer and renderer protected different code regions.
Context and experiment values now remain opaque through runtime imports and template branch parsing. Conditions resolve their values only after author-owned directives have been parsed; selected content restores literal values once, without further template processing. Single-pass interpolation also prevents recursive replacement of placeholders supplied by untrusted content.
The renderer shares the sanitizer's inline/fenced code-region handling. Runtime-import provenance and extracted agent/skill artifacts restore literal values without leaking internal tokens. Legitimate if/elseif conditions, experiment comparisons, and split prompts remain supported. Templating documentation describes the processing boundary.
Validation
{{#if false}}title payloads removed author instructions.make fmt-cjs,make lint-cjs, JavaScript typecheck, andmake agent-report-progresspassed. Lint reported warnings but no errors; impacted Go tests were skipped because there are no Go changes.No alert dismissal or workflow dispatch was performed. Alert closure requires integration and rescanning.