Skip to content

Quote prompt-step environment values as YAML scalars - #74560

Merged
pelikhan merged 7 commits into
mainfrom
copilot/uk-ai-resilience-fix-unsafe-quoting
Nov 4, 2026
Merged

pelikhan merged 7 commits into
mainfrom
copilot/uk-ai-resilience-fix-unsafe-quoting

Conversation

Copilot AI commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

Generated prompt-step environment values were concatenated into YAML without escaping, allowing YAML-significant expression content to alter or invalidate the generated workflow.

  • Safe emission: Use writeYAMLEnv to quote and escape each value.
  • Regression coverage: Add a round-trip test for expressions containing YAML-significant characters.
writeYAMLEnv(yaml, "          ", key, allEnvVars[key])

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix unsafe quoting in unified_prompt_step.go Quote prompt-step environment values as YAML scalars Nov 3, 2026
Copilot AI requested a review from gh-aw-bot November 3, 2026 16:47
@pelikhan
pelikhan marked this pull request as ready for review November 3, 2026 19:10
Copilot AI adaptive review requested due to automatic review settings November 3, 2026 19:10
@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Ponytail Reviewer completed successfully!

Ponytail Reviewer

Outcome: reported_no_action

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.

Generated from Ponytail Reviewer · routed: gpt56 max · ~1 AIC · ⌖ ~1 AIC · ⊞ 118 · ◷

Generated by Ponytail Reviewer for #74560

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ PR Code Quality Reviewer completed the code quality review.

🔎 Code quality review by PR Code Quality Reviewer

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ 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: reported_no_action

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.

Generated from Design Decision Gate 🏗️ · routed: gpt56 max · ~1 AIC · ⌖ ~2 AIC · ⊞ 7.7K · ◷

🏗️ ADR gate enforced by Design Decision Gate 🏗️

@github-actions

github-actions Bot commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

✅ Test Quality Sentinel completed test quality analysis.

Test Quality Sentinel

Outcome: reported_no_action

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.

Generated from Test Quality Sentinel · haiku45 · ~43 AIC · ⌖ ~12 AIC · ⊞ 9.4K · ◷

🧪 Test quality analysis by Test Quality Sentinel

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The quoting change breaks the existing PR-context test assertion and double-quotes deferred prompt values, producing incorrect environment contents and failing deferred-prompt assertions.

2 open issues
What changed in this PR

This PR hardens prompt-step environment emission in the gh-aw compiler against YAML-significant expression content, addressing issue #73221.

Changes:

  • Uses writeYAMLEnv to quote and escape environment values.
  • Adds a YAML round-trip regression test for expressions containing colons, quotes, and comment markers.
File Description
pkg/​workflow/​unified_prompt_step.go Emits prompt-step environment values through the YAML quoting helper.
pkg/​workflow/​unified_prompt_creation_test.go Checks that YAML-significant expression content survives serialization unchanged.

Review effort: Balanced (auto)

envKeys := sliceutil.SortedKeys(allEnvVars)
for _, key := range envKeys {
yaml.WriteString(" " + key + ": " + allEnvVars[key] + "\n")
writeYAMLEnv(yaml, " ", key, allEnvVars[key])
envKeys := sliceutil.SortedKeys(allEnvVars)
for _, key := range envKeys {
yaml.WriteString(" " + key + ": " + allEnvVars[key] + "\n")
writeYAMLEnv(yaml, " ", key, allEnvVars[key])

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Review complete: no actionable issues found in the changed lines. The environment emission now uses YAML-safe quoting, and the regression test verifies round-trip preservation of expression values. The specialist pass was unavailable because its pre-fetched diff reads were denied; independent review completed.

🔎 Code quality review by PR Code Quality Reviewer · copilot · gpt50 · ~2 AIC · ⌖ ~1 AIC · ⊞ 1.6K
Comment /review to run again

@github-actions

github-actions Bot commented Nov 3, 2026

Copy link
Copy Markdown
Contributor

🧪 Test Quality Sentinel Report

Summary

✅ Score: 100/100 — Excellent

Implementation Ratio: 0% (no implementation tests detected)
Design Tests: 100%
Violations: None


Test Coverage Analysis

New Test Found: 1

  • TestGenerateUnifiedPromptCreationStep_QuotesExpressionEnvVars
Test Details
Test Name File Lines Type Classification
TestGenerateUnifiedPromptCreationStep_QuotesExpressionEnvVars unified_prompt_creation_test.go 125-150 Design behavioral_contract

TestGenerateUnifiedPromptCreationStep_QuotesExpressionEnvVars

Design: Round-trip test for YAML-significant characters in environment expressions.

Expression tested: ${{ github.event.issue.title || 'value: \"quoted\" # comment' }}

Includes: Single quotes, double quotes, colon-space (YAML metacharacter), comment syntax

Assertions:

  1. ✅ YAML parses without error (error handling)
  2. ✅ Exactly 1 step generated (structural integrity)
  3. ✅ Expression matches exactly after round-trip (behavioral contract — critical for security)

Edge Cases Covered:

  • YAML-significant punctuation (quotes, colons)
  • Comment-like syntax in values
  • Complex nested expressions
  • Data integrity through YAML marshaling/unmarshaling cycle

Quality Signals:

  • ✅ Design invariant: Yes — verifies environment value integrity
  • ✅ High value if deleted: Regression test for YAML injection vulnerability
  • ✅ No duplication detected
  • ✅ Build tag present: (go/redacted):build !integration
  • ✅ Clear assertion messages

Violations Check

✅ No Go mock libraries detected
✅ Build tags compliant
✅ Assertion messages descriptive
✅ No test inflation detected


Recommendation

✅ APPROVE — This test directly addresses the security boundary fix (YAML injection prevention). The single, focused regression test has excellent coverage of the vulnerability scenario with proper edge cases. No concerns detected.

🧪 Test quality analysis by Test Quality Sentinel · copilot · haiku45 · ~43 AIC · ⌖ ~12 AIC · ⊞ 9.4K · ◷
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Test Quality Sentinel: 100/100. 0% implementation tests (threshold: 30%). Single focused regression test with comprehensive edge-case coverage of YAML injection prevention. No violations.

🧪 Test quality analysis by Test Quality Sentinel · copilot · haiku45 · ~43 AIC · ⌖ ~12 AIC · ⊞ 9.4K
Comment /review to run again

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Skills-Based Review 🧠

Applied /diagnosing-bugs and /tdd. The escaping direction is right, but the change breaks three existing tests, so requesting changes.

📋 Key Themes & Highlights

Key Themes

  • Double quoting of literal env values: ExpressionMapping.environmentValue() already %q-quotes literal mappings, and writeYAMLEnv quotes them again. This breaks TestDeferredPromptCompilation, which expects bare __GH_AW_DEFERRED_...__ placeholders. Fix in the inline comment on unified_prompt_step.go:475.
  • Stale assertion: TestGenerateUnifiedPromptCreationStep_PRContextConditional (unified_prompt_creation_test.go:745) asserts the old unquoted GH_AW_INCLUDE_PR_CONTEXT: ${{ form. It should check the quoted scalar instead.
  • Sibling still unescaped: generateInterpolationAndTemplateStep in template.go:145 still writes mapping.EnvVar + ": " + mapping.environmentValue() by concatenation. Once environmentValue() is fixed, this site needs writeYAMLEnv too, or it will emit invalid YAML.

Positive Highlights

  • ✅ The round-trip test is a good fit: the raw form of its expression is invalid YAML (checked with PyYAML), so the test would catch the original bug.
  • ✅ Using the existing writeYAMLEnv helper keeps one escaping path.

Notes

  • TestCredentialFreePromptEnvironment fails in this sandbox on an inherited GITHUB_TOKEN guard. It is unrelated to this diff.
  • I could not run the parent commit as a baseline (remote fetch blocked), so pre-existing failures are not ruled out. I checked the three failures against the diff and a temporary local experiment, which I reverted.

@copilot please address the review comments above, then rerun go test ./pkg/workflow/.

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · copilot · routed: haiku55 xhigh · ~6 AIC · ⌖ ~1 AIC · ⊞ 5.4K
Comment /matt to run again

envKeys := sliceutil.SortedKeys(allEnvVars)
for _, key := range envKeys {
yaml.WriteString(" " + key + ": " + allEnvVars[key] + "\n")
writeYAMLEnv(yaml, " ", key, allEnvVars[key])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/diagnosing-bugs] Root cause is a second quoting layer, and it breaks the deferred-prompt placeholders. For literal mappings, ExpressionMapping.environmentValue() (expression_extraction.go:29) already returns a Go %q-quoted string, and writeYAMLEnv quotes it again. As a result TestDeferredPromptCompilation sees the placeholder wrapped in extra quote characters instead of the bare __GH_AW_DEFERRED_...__ value.

💡 Suggested fix

Keep one quoting layer. Make environmentValue() return the raw Content for literal mappings, keep the ${{ ... }} wrapping for expressions, and switch the template.go:145 call site to writeYAMLEnv too. Then writeYAMLEnv is the only place these values are quoted.

I checked this locally: with literal values left unquoted, both deferred-prompt tests pass. That local change was reverted and is not part of this review.

@copilot please address this.

}
}

func TestGenerateUnifiedPromptCreationStep_QuotesExpressionEnvVars(t *testing.T) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/tdd] Good regression test. The unquoted form of this expression is not valid YAML (checked with PyYAML), so the test would catch the bug.

💡 Suggested edge case

The fix also depends on %q escaping control characters. Consider one more table entry whose value spans two lines and starts with a double quote, so that path is covered too.

@copilot please address this.

@pelikhan

pelikhan commented Nov 3, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

Copilot AI and others added 2 commits November 3, 2026 23:46
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot run pr-finisher skill

Ran PR-finisher and pushed 32282ef: fixed double-quoted literals, hardened interpolation emission, and updated regression tests. Focused tests, formatting, repository lint, and secret scanning pass.

Not yet merge-ready: the full package reproduces the unrelated smoke-agy CI failure; the final gate reports pre-existing custom-linter diagnostics on unchanged lines. Review threads remain unresolved (no thread-resolution tool available). CodeQL was invoked but skipped analysis because its database is too large. PR is open/non-draft with merge state unstable.

A maintainer must resolve the remaining blockers and re-trigger CI; CI on the new HEAD is unverified. No merge performed.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan November 4, 2026 00:02
@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

@copilot review the double encoding and ensure it makes sense. Add tests.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review the double encoding and ensure it makes sense. Add tests.

Added a parsed-YAML regression test for a literal containing a colon, quote, newline, and backslash. environmentValue() returns raw literal content, and writeYAMLEnv quotes it once; the test verifies the parsed environment value remains byte-for-byte unchanged. Commit: 052a7023.

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
@pelikhan
pelikhan merged commit 71eeda2 into main Nov 4, 2026
36 checks passed
@pelikhan
pelikhan deleted the copilot/uk-ai-resilience-fix-unsafe-quoting branch November 4, 2026 01:54
@github-actions

github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v1.2.0

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.

[uk-ai-resilience] Tier C: unsafe quoting in unified_prompt_step.go (code scanning 1045)

4 participants