Ignore ${{ ... }} in bash # comments during run-script expression harvesting#35777
Conversation
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
${{ ... }} in bash # comments during run-script expression harvesting
There was a problem hiding this comment.
Pull request overview
This PR narrows GitHub expression harvesting and validation for workflow run: scripts so ${{ ... }} inside bash # comments is treated like non-executable content, similar to existing heredoc exclusions.
Changes:
- Adds
stripShellLineCommentsto remove bash-style comments while preserving quoted and escaped#. - Applies heredoc + comment stripping before sanitizer and validation scans.
- Adds unit and compiler-path regression tests for comment-only expressions.
Show a summary per file
| File | Description |
|---|---|
pkg/workflow/template_injection_validation.go |
Excludes shell comments from parsed workflow expression validation scans. |
pkg/workflow/template_injection_validation_test.go |
Adds unit coverage for shell comment stripping behavior. |
pkg/workflow/template_injection_utils.go |
Adds the comment-stripping helper and comment-start detection. |
pkg/workflow/run_step_sanitizer.go |
Updates run-step expression scanning to ignore comments. |
pkg/workflow/run_step_sanitizer_test.go |
Adds sanitizer cases for comment-only and mixed comment/executable expressions. |
pkg/workflow/compiler_template_injection_both_paths_test.go |
Adds both-path validation coverage for expressions inside bash comments. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 6/6 changed files
- Comments generated: 1
| // Only scan executable script content: | ||
| // - strip heredoc bodies (written to files/stdin, not executed) | ||
| // - strip bash line comments (not executed) | ||
| scanContent := stripShellLineComments(removeHeredocContent(runVal)) |
|
@copilot review all comments and reviews from copilot and github-actions actor. Address and resolve. |
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Addressed the actionable Copilot review feedback in commit |
|
``
|
gh aw compileregressed in v0.76+ by harvesting${{ ... }}tokens from bash comments insiderun:blocks, hoisting them into stepenv, and generating invalid lock workflows when those expressions resolve to non-scalars (e.g.secrets.*). This PR limits harvesting/guardrail scans to executable script content.Scope of fix: executable-only expression scanning
# ...) before run-script expression extraction.Compiler paths updated
sanitizeRunStepExpressionsnow scansstripShellLineComments(removeHeredocContent(run)).Behavioral coverage added
#, escaped\#, trailing comments).