-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Use env vars for workflow_run context values in example workflows #1125
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
🟣 Pre-existing issue:
OUTPUT='${{ steps.detect.outputs.structured_output }}'on lines 59, 76, and 89 is directly interpolated into shell using single quotes — the same class of vulnerability this PR fixes forworkflow_runvalues. If Claude's JSON output contains a single quote (e.g.,"summary": "It's a flaky test"), the single-quoting breaks shell parsing. Since the PR already addsenv:blocks to these steps, consider also passingstructured_outputviaenv:for consistency.Extended reasoning...
What the bug is
In
examples/test-failure-analysis.yml, the variablestructured_outputfrom the Claude action step is assigned in shell using single-quote interpolation:This appears on lines 59, 76, and 89. GitHub Actions evaluates the
${{ }}expression and substitutes the raw value directly into the shell script before bash executes it.How it manifests
The
structured_outputis JSON produced by Claude with a schema containing asummarystring field. If that string contains a single quote — which is entirely plausible for natural language (e.g.,"summary": "It's a flaky test") — the resulting shell line becomes:The single quote inside
It'sterminates the single-quoted string prematurely, leavings a flaky test" }'as unquoted shell text. This causes a shell syntax error at minimum, and in adversarial scenarios could lead to command injection.Why existing code doesn't prevent it
The JSON schema constrains the structure of the output but not the characters within string fields. Claude can produce any valid string content in the
summaryfield. There is no escaping or sanitization applied between the GitHub Actions expression evaluation and shell execution.Impact
In practice, the impact is a robustness issue rather than a security vulnerability, since
structured_outputcomes from the repo's own Claude invocation rather than attacker-controlled input like branch names. However, it would cause the workflow to fail unexpectedly when Claude's summary contains apostrophes or single quotes — a common occurrence in English text.How to fix
Pass
structured_outputthrough an environment variable, the same pattern this PR applies toworkflow_runvalues:This ensures the value is treated as a literal string by the shell regardless of its contents.
Pre-existing status
This pattern existed before this PR and is not introduced or modified by it. However, the PR already touches the
env:blocks of these exact steps to addWORKFLOW_NAMEandHEAD_BRANCH, so fixingstructured_outputat the same time would be a natural and low-risk addition for consistency.