Skip to content

Fix command injection vulnerabilities in GitHub Actions workflows#301

Merged
baynezy merged 3 commits intodevelopfrom
copilot/update-workflow-security
Dec 2, 2025
Merged

Fix command injection vulnerabilities in GitHub Actions workflows#301
baynezy merged 3 commits intodevelopfrom
copilot/update-workflow-security

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 1, 2025

Three workflows were vulnerable to command injection by interpolating untrusted data directly into shell commands using GitHub expression syntax (${{ ... }}).

Changes

  • draft-new-release.yml: Move github.event.inputs.*, github.actor, github.repository, github.run_id, and step outputs to environment variables
  • in-progress-feature-workflow.yml: Move steps.extract_issue.outputs.issue to environment variable
  • completed-feature-workflow.yml: Move steps.extract_issue.outputs.issue to environment variable

Approach

Instead of:

run: echo "PR title: ${{ github.event.pull_request.title }}"

Use:

env:
  PR_TITLE: ${{ github.event.pull_request.title }}
run: echo "PR title: $PR_TITLE"

This prevents shell interpretation of user-controlled data while maintaining functionality.

Original prompt

This section details on the original issue you should resolve

<issue_title>Change this workflow to not use user-controlled data directly in a run block.</issue_title>
<issue_description>To prevent command injection in GitHub Actions workflows, avoid directly interpolating untrusted data into shell commands. Instead, use environment variables to safely pass untrusted data without risk of code execution.

The recommended approach is to assign untrusted data to environment variables using the env key, then reference these variables using standard shell variable syntax ($VARIABLE_NAME or ${VARIABLE_NAME}) rather than GitHub’s expression syntax (${{ …​}}).

Noncompliant code example

The following GitHub Action is vulnerable to command injections as it uses untrusted input directly in a run command:

name: Example

on:
  pull_request:
    branches: [ main ]

jobs:
  main:
    runs-on: ubuntu-latest

    steps:
      - name: Example Step
        run: |
          echo "PR title: ${{ github.event.pull_request.title }}" # Noncompliant

Compliant solution

name: Example

on:
  pull_request:
    branches: [ main ]

jobs:
  main:
    runs-on: ubuntu-latest

    steps:
      - name: Example Step
        env:
          PR_TITLE: ${{ github.event.pull_request.title }}
        run: |
          echo "PR title: $PR_TITLE"
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: baynezy <1049999+baynezy@users.noreply.github.com>
Copilot AI changed the title [WIP] Change workflow to avoid user-controlled data in run block Fix command injection vulnerabilities in GitHub Actions workflows Dec 1, 2025
Copilot AI requested a review from baynezy December 1, 2025 17:37
@baynezy baynezy marked this pull request as ready for review December 2, 2025 16:13
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 2, 2025

@baynezy baynezy merged commit b0dcb2d into develop Dec 2, 2025
7 checks passed
@baynezy baynezy deleted the copilot/update-workflow-security branch December 2, 2025 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change this workflow to not use user-controlled data directly in a run block.

2 participants