Skip to content

[code-scanning-fix] Fix ai-scan/cwe-78: extract Actions expressions from shell comments in run steps - #74855

Closed
github-actions[bot] wants to merge 1 commit into
mainfrom
code-scanning-fix-1060-comment-expressions-7ef1984e2f395ffc
Closed

github-actions[bot] wants to merge 1 commit into
mainfrom
code-scanning-fix-1060-comment-expressions-7ef1984e2f395ffc

Conversation

@github-actions

@github-actions github-actions Bot commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Security Fix: Shell injection through expressions in shell comments

Alert Number: #1060
Severity: High
Rule: ai-scan/cwe-78
CWE: CWE-78

Vulnerability Description

The run-step sanitizer only extracted ${{ }} expressions from content it considered executable, so expressions inside # comments stayed inline. GitHub Actions expands expressions before the shell runs. A value with a newline (such as an issue title) can end the comment and inject commands.

Location

  • File: pkg/workflow/run_step_sanitizer.go
  • Line: 97

Fix Applied

  • Scan for expressions everywhere except quoted heredoc bodies. Comments are no longer excluded, because they offer no protection against expressions that Actions expands before the shell runs.
  • Rewrite matches with the same quoted-heredoc-only region set, so expressions in comments are moved to env: and replaced with $GH_AW_* references.
  • Quoted heredoc bodies are still left untouched. Rewriting them would emit the literal variable name. These bodies are still handled by the existing validation and are not fully addressed by this PR (see below).

Security Best Practices

Bind untrusted data through env: instead of inlining template expressions in shell scripts.

Testing Considerations

The sandbox did not allow running go test here, so CI must validate this change. Please run go test ./pkg/workflow/ -run 'Sanitiz|Heredoc|TemplateInjection|RunStep'. Some existing assertions may expect comments to be left untouched and may need updating. Follow-up: the template-injection validator still permits expressions in quoted heredoc bodies. Consider rejecting those too.


Automated by: Code Scanning Fixer Workflow
Run ID: 41833342676

Generated by 🔒 Code Scanning Fixer · copilot · routed: opus55 low · ~49 AIC · ⌖ ~2 AIC · ⊞ 4.3K · ◷

  • expires on Nov 6, 2026, 5:01 AM UTC-08:00

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

Critical sanitizer bypasses still allow comment-based newline injection into lock files, and existing test expectations contradict the new behavior.

2 open issues
What changed in this PR

This PR hardens gh-aw’s run-step sanitizer against shell injection through GitHub Actions expressions embedded in shell comments.

Changes:

  • Extracts comment expressions into environment bindings and replaces them with generated variable references.
  • Uses consistent quoted-heredoc boundaries for scanning and replacement, leaving quoted bodies unchanged.
File Description
pkg/​workflow/​run_step_sanitizer.go Includes shell comments in expression extraction and replacement while preserving quoted heredoc bodies.

Review effort: Max (auto)

// protection: a value containing a newline escapes the comment. Only
// quoted heredoc bodies are left in place (rewriting them would emit the
// literal variable name); validation is responsible for those.
scanContent := transformShellContent(runVal, func(s string) string { return s }, true, false)
// protection: a value containing a newline escapes the comment. Only
// quoted heredoc bodies are left in place (rewriting them would emit the
// literal variable name); validation is responsible for those.
scanContent := transformShellContent(runVal, func(s string) string { return s }, true, false)
@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

@copilot run pr-finisher skill

@pelikhan

pelikhan commented Nov 4, 2026

Copy link
Copy Markdown
Collaborator

Duplicate of #74793

@pelikhan pelikhan marked this as a duplicate of #74793 Nov 4, 2026
@pelikhan pelikhan closed this Nov 4, 2026
Copilot stopped work on behalf of pelikhan due to an error November 4, 2026 15:19
Copilot AI requested a review from pelikhan November 4, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants