fix(workflows): Prevent shell injection in fast-revert workflow#4210
Closed
fix(workflows): Prevent shell injection in fast-revert workflow#4210
Conversation
Use environment variables instead of direct GitHub context interpolation in shell commands to prevent potential script injection attacks. Refs: https://linear.app/getsentry/issue/DI-967 Co-Authored-By: Claude <noreply@anthropic.com>
Changelog Preview📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨
Bug Fixes 🐛
Internal Changes 🔧Deps
🤖 This preview updates automatically when you update the PR. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR fixes a shell injection vulnerability in the
fast-revert.ymlGitHub Actions workflow.Vulnerability
The "comment on failure" step directly interpolates GitHub context values (
${{ github.event.inputs.pr }},${{ github.repository }},${{ github.run_id }}, etc.) inside arun:block. This pattern is flagged by the Semgrep rule yaml.github-actions.security.run-shell-injection.run-shell-injection.When GitHub context values are interpolated directly into shell commands, a malicious actor could craft input (e.g., a specially crafted PR number or repository name) that breaks out of the intended shell context and executes arbitrary commands.
Fix
Replace direct context interpolation with environment variables. The GitHub context values are safely assigned to
env:variables, which are then referenced as shell variables (e.g.,$GH_TOKEN,$REPO). This prevents shell injection because environment variable expansion does not allow command substitution.References