-
Notifications
You must be signed in to change notification settings - Fork 28
Fix template injection risk in copilot-session-insights workflow #4001
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -93,6 +93,8 @@ steps: | |||||
| continue-on-error: true | ||||||
| env: | ||||||
| GH_TOKEN: ${{ secrets.GH_AW_COPILOT_TOKEN || secrets.GH_AW_GITHUB_TOKEN }} | ||||||
| # Security: Pass step output through environment variable to prevent template injection | ||||||
| EXTENSION_INSTALLED: ${{ steps.install-extension.outputs.EXTENSION_INSTALLED }} | ||||||
| run: | | ||||||
| # Create output directory | ||||||
| mkdir -p /tmp/gh-aw/agent-sessions | ||||||
|
|
@@ -112,7 +114,8 @@ steps: | |||||
| # Check if gh agent-task extension is installed | ||||||
| if ! gh agent-task --help &> /dev/null; then | ||||||
| echo "::warning::gh agent-task extension is not installed" | ||||||
| echo "::warning::Extension installation status from previous step: ${{ steps.install-extension.outputs.EXTENSION_INSTALLED }}" | ||||||
| # Security: Use environment variable instead of template expression in bash script | ||||||
|
||||||
| # Security: Use environment variable instead of template expression in bash script | |
| # Security: Use environment variable as best practice to avoid template expressions in bash |
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,119 @@ | ||||||||||||
| # Template Injection Prevention in Workflows | ||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot move to top level specs folder
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Documentation moved to |
||||||||||||
|
|
||||||||||||
| ## Overview | ||||||||||||
|
|
||||||||||||
| This document explains the template injection security fix applied to workflows in this repository to prevent potential code injection attacks via GitHub Actions template expansion. | ||||||||||||
|
|
||||||||||||
| ## What is Template Injection? | ||||||||||||
|
|
||||||||||||
| Template injection occurs when untrusted data flows into GitHub Actions template expressions (`${{ }}`) that are evaluated during workflow execution. This can lead to: | ||||||||||||
|
|
||||||||||||
| - Code execution in workflow steps | ||||||||||||
| - Information disclosure | ||||||||||||
| - Privilege escalation | ||||||||||||
|
|
||||||||||||
| ## The Vulnerability Pattern | ||||||||||||
|
|
||||||||||||
| **Unsafe Pattern:** | ||||||||||||
| ```yaml | ||||||||||||
| steps: | ||||||||||||
| - name: My Step | ||||||||||||
| run: | | ||||||||||||
| echo "Value: ${{ steps.previous.outputs.value }}" | ||||||||||||
|
Comment on lines
+20
to
+22
|
||||||||||||
| ``` | ||||||||||||
| If the output value contains malicious content, it could be executed when the template is expanded. | ||||||||||||
| ## The Fix | ||||||||||||
| **Safe Pattern:** | ||||||||||||
| ```yaml | ||||||||||||
| steps: | ||||||||||||
| - name: My Step | ||||||||||||
| env: | ||||||||||||
| MY_VALUE: ${{ steps.previous.outputs.value }} | ||||||||||||
| run: | | ||||||||||||
| echo "Value: $MY_VALUE" | ||||||||||||
| ``` | ||||||||||||
| By passing the value through an environment variable, the content is treated as data, not executable code. | ||||||||||||
| ## Changes Made | ||||||||||||
| ### copilot-session-insights.md | ||||||||||||
| **Issue:** Template expression used directly in bash echo statement | ||||||||||||
| - **Line:** 115 | ||||||||||||
|
||||||||||||
| - **Line:** 115 | |
| - **Line (source):** 115 in copilot-session-insights.md | |
| - **Line (compiled):** ~207 in copilot-session-insights.lock.yml |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The documentation states "While currently using a step output (controlled), this pattern is risky and could lead to injection if changed to use untrusted data."
This description could be misleading. The actual security concern should be stated more clearly:
The issue is not a current vulnerability, but rather a code pattern that violates security best practices. Using template expressions inside bash script strings (even with trusted data) creates a maintenance hazard - if someone later changes the code to use untrusted data, they might not realize they're creating a vulnerability.
Consider revising lines 45-47 to:
- **Line:** 115
- **Risk:** Code pattern that could become vulnerable if modified to use untrusted data in the future
- **Severity:** Preventive best practice (not an active vulnerability)This accurately reflects that it's a preventive security measure rather than fixing an exploitable bug.
| - **Line:** 115 | |
| - **Risk:** While using step output (controlled), the pattern could lead to injection if changed to use untrusted data | |
| - **Line:** 115 | |
| - **Risk:** Code pattern that could become vulnerable if modified to use untrusted data in the future | |
| - **Severity:** Preventive best practice (not an active vulnerability) |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reference to "Issue #3945" should be updated to reflect the correct issue number mentioned in the PR description. According to the PR metadata, this fixes issue #3984, not #3945.
Update line 108 to:
- Issue githubnext/gh-aw#3984 - [task] Fix template injection risks in workflows
- Discussion githubnext/gh-aw#3945 - Static Analysis Report (November 14, 2025)This correctly distinguishes between the issue being fixed (#3984) and the discussion that identified it (#3945).
| - Issue #3945 - Static Analysis Report (November 14, 2025) | |
| - Issue githubnext/gh-aw#3984 - [task] Fix template injection risks in workflows | |
| - Discussion githubnext/gh-aw#3945 - Static Analysis Report (November 14, 2025) |
Copilot
AI
Nov 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Critical Issue: This PR contradicts an existing security review.
The repository contains specs/SECURITY_REVIEW_TEMPLATE_INJECTION.md (dated 2025-11-11) which explicitly analyzed this exact same code pattern and concluded it is a FALSE POSITIVE with NO SECURITY RISK.
From that security review:
Verdict: ✅ FALSE POSITIVE - NO SECURITY RISK
Rationale:
- The template expansion references a step output that is set by the workflow itself
- The value is always one of two hardcoded strings: "true" or "false"
- No user-controlled data flows into this template expansion
Recommended Action:
- Either remove this PR entirely (if the previous security review is correct)
- Or update the documentation to explain why the previous security review's conclusion was incorrect
- Or clarify that this is a preventive best practice change (not a security fix) and update both this PR's documentation and the existing security review accordingly
The new documentation in this PR should reference the existing security review and explain the relationship between the two analyses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The security comment mentions "prevent template injection" but the actual risk here is lower than described. The
steps.install-extension.outputs.EXTENSION_INSTALLEDis a controlled step output (boolean value set by the workflow itself), not untrusted user input.While the fix is technically correct and follows best practices by using environment variables, the comment should clarify that this is a preventive measure rather than fixing an active vulnerability. The original code was not vulnerable to template injection because step outputs from the same workflow are trusted.
Consider updating the comment to:
# Security: Use environment variable as best practice to prevent potential future template injection riskThis makes it clear that it's a preventive pattern, not a fix for an existing exploitable vulnerability.