Skip to content

fix(workflows): Prevent shell injection in fast-revert workflow - #4309

Merged
aldy505 merged 2 commits into
masterfrom
fix/di-1872-shell-injection-fast-revert
May 12, 2026
Merged

fix(workflows): Prevent shell injection in fast-revert workflow#4309
aldy505 merged 2 commits into
masterfrom
fix/di-1872-shell-injection-fast-revert

Conversation

@fix-it-felix-sentry

Copy link
Copy Markdown
Contributor

Summary

This PR fixes a security finding related to potential shell injection in the fast-revert.yml GitHub Actions workflow.

Changes

  • Moved GitHub context variables (github.repository, github.run_id, github.event.repository.id, github.event.number, github.event.inputs.pr) to an env: block
  • Updated the run: script to reference these values as environment variables with proper quoting
  • This follows GitHub's security best practices to prevent script injection attacks

References

Testing

  • ✅ YAML syntax validated
  • The workflow will be tested when this PR is merged

Security Impact

While the Semgrep Assistant indicated this might be a false positive (since the variables used are mostly GitHub-controlled identifiers), following security best practices by using environment variables provides defense-in-depth and prevents any potential injection vectors.

Use environment variables to store GitHub context data instead of
directly interpolating them in the run script. This prevents potential
script injection attacks.

Changes:
- Move GitHub context variables to env block
- Reference variables using proper shell variable syntax with quotes
- Apply to: github.repository, github.run_id, github.event.repository.id,
  and github.event.number/github.event.inputs.pr

Fixes: https://linear.app/getsentry/issue/VULN-1575
Fixes: https://linear.app/getsentry/issue/DI-1872

Co-Authored-By: fix-it-felix-sentry[bot] <260785270+fix-it-felix-sentry[bot]@users.noreply.github.com>
@linear-code

linear-code Bot commented Apr 28, 2026

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 7c6ae0e. Configure here.

env:
GITHUB_TOKEN: ${{ secrets.BUMP_SENTRY_TOKEN }}
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_RUN_ID: ${{ github.run_id }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reserved env var names override silently ignored

Low Severity

GITHUB_REPOSITORY and GITHUB_RUN_ID are reserved GitHub Actions default environment variables that the documentation states cannot be overwritten. Setting them in the step-level env: block is silently ignored at runtime. This works today only because the default values happen to match what's being assigned, but using reserved names is unnecessary and could break if GitHub starts enforcing this restriction with a hard error. Using non-reserved names (e.g., GH_REPO, RUN_ID) would be more robust.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 7c6ae0e. Configure here.

token: ${{ secrets.BUMP_SENTRY_TOKEN }}
- name: comment on failure
env:
GITHUB_TOKEN: ${{ secrets.BUMP_SENTRY_TOKEN }}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The workflow attempts to overwrite the reserved GITHUB_TOKEN environment variable. This is ignored, and the subsequent API call will use a token with no permissions, causing it to fail.
Severity: MEDIUM

Suggested Fix

Instead of trying to overwrite GITHUB_TOKEN, use a different environment variable name for your PAT, for example, GH_TOKEN. Then, update the curl command to use this new variable: Authorization: Bearer ${{ env.GH_TOKEN }}.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: .github/workflows/fast-revert.yml#L34

Potential issue: The workflow at `.github/workflows/fast-revert.yml` attempts to
overwrite the reserved `GITHUB_TOKEN` environment variable with a secret PAT at line 34.
GitHub Actions silently ignores this assignment. Because the workflow also specifies
`permissions: {}` at line 11, the default `GITHUB_TOKEN` that is ultimately used has no
permissions. As a result, the `curl` command that relies on this token to post a comment
to the pull request will fail with a 403 error, preventing the failure notification from
being sent.

Did we get this right? 👍 / 👎 to inform future reviews.

@aldy505
aldy505 merged commit 45efce3 into master May 12, 2026
19 checks passed
@aldy505
aldy505 deleted the fix/di-1872-shell-injection-fast-revert branch May 12, 2026 07:23
@github-actions github-actions Bot locked and limited conversation to collaborators May 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

1 participant