Skip to content

fix: Prevent shell injection in GitHub Actions workflow#2110

Open
fix-it-felix-sentry[bot] wants to merge 2 commits into
mainfrom
fix/di-1912-shell-injection-workflow
Open

fix: Prevent shell injection in GitHub Actions workflow#2110
fix-it-felix-sentry[bot] wants to merge 2 commits into
mainfrom
fix/di-1912-shell-injection-workflow

Conversation

@fix-it-felix-sentry

Copy link
Copy Markdown

Summary

This PR fixes a security finding by preventing potential shell injection in the GitHub Actions workflow.

Changes

  • Replaced direct interpolation of GitHub context variables (github.sha, github.ref, github.actor, github.event_name) with environment variables
  • Updated shell commands to use quoted environment variables instead of direct ${{ }} interpolation
  • Applied the same fix to both the login and build steps

This follows GitHub Actions security best practices for preventing script injection attacks by treating all GitHub context data as potentially untrusted and using intermediate environment variables.

References

Use environment variables instead of direct interpolation of GitHub context
variables in run steps to prevent potential shell injection attacks.

This addresses the security finding by:
- Storing github.sha, github.ref, github.actor, matrix.arch, and github.event_name
  in environment variables
- Using quoted environment variables in shell commands instead of direct interpolation
- Following GitHub Actions security best practices for script injection prevention

Fixes: https://linear.app/getsentry/issue/VULN-1618
Fixes: https://linear.app/getsentry/issue/DI-1912

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@linear-code

linear-code Bot commented May 1, 2026

Copy link
Copy Markdown

@joshuarli joshuarli enabled auto-merge (squash) June 9, 2026 20:39
Comment on lines +24 to +27
env:
GITHUB_ACTOR: ${{ github.actor }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: docker login --username "$GITHUB_ACTOR" --password-stdin ghcr.io <<< "$GITHUB_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: Assignments to reserved environment variables GITHUB_ACTOR and GITHUB_TOKEN are silently ignored, making the intended security hardening ineffective.
Severity: MEDIUM

Suggested Fix

Use non-reserved names for the environment variables to ensure they are set correctly. For example, rename GITHUB_ACTOR to DOCKER_USERNAME and GITHUB_TOKEN to DOCKER_PASSWORD within the env block and update the run command to use these new variables.

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/image.yml#L24-L27

Potential issue: In the GitHub Actions workflow, the code attempts to set `GITHUB_ACTOR`
and `GITHUB_TOKEN` as environment variables for the `login` step. However, these are
reserved variable names in GitHub Actions, and any assignments to them are silently
ignored. Consequently, the intended security hardening—using intermediate variables to
prevent shell injection—is not applied. The `docker login` command still succeeds by
coincidence, as it falls back to using the globally available `GITHUB_ACTOR` and
`GITHUB_TOKEN` variables. This means the code does not achieve its security goal and
provides a false sense of security.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant