Skip to content

Conversation

@ismith
Copy link
Contributor

@ismith ismith commented Dec 8, 2025

Potential fix for https://github.com/github/gh-gei/security/code-scanning/1035

To address this vulnerability, we should strictly control the value of PR_NUMBER before it is written to $GITHUB_ENV. This means ensuring that:

  • Only valid, single-line numeric data is used (since PR numbers are always positive integers).
  • All potential for newlines, extra characters, or injection attacks is removed.

This was already being done - tr -cd '0-9' removes (-d) the complement (-c) of the specified characters. But CodeQL doesn't recognize that, so we'll use its suggested approach (grep -E '^[0-9]+$') instead.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

… user-controlled sources

The concern is that the file in the artifact might be created by an attacker to inject values into the env var being set.

To address this vulnerability, we should strictly control the value of PR_NUMBER before it is written to $GITHUB_ENV. This means ensuring that:

- Only valid, single-line numeric data is used (since PR numbers are always positive integers).
- All potential for newlines, extra characters, or injection attacks is removed.
- explicitly validate that the value is non-empty and matches expectations
= Also, wrap the assignment in double quotes to further protect against expansion.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
@ismith ismith marked this pull request as ready for review December 8, 2025 19:12
Copilot AI review requested due to automatic review settings December 8, 2025 19:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a security vulnerability (code scanning alert #1035) related to environment variable injection in the GitHub Actions workflow. The fix strengthens the validation of PR numbers before they're written to $GITHUB_ENV to prevent potential injection attacks.

Key Changes:

  • Replaced tr -cd '0-9' sanitization with explicit grep -E '^[0-9]+$' validation that CodeQL recognizes
  • Added explicit error handling with conditional logic when PR number validation fails
  • Simplified the code by removing intermediate variables and using direct file redirection

Co-authored-by: synthead <synthead@github.com>
@ismith ismith requested a review from synthead December 8, 2025 19:31
Copy link
Collaborator

@synthead synthead left a comment

Choose a reason for hiding this comment

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

LGTM!

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

Unit Test Results

  1 files    1 suites   10m 25s ⏱️
960 tests 960 ✅ 0 💤 0 ❌
961 runs  961 ✅ 0 💤 0 ❌

Results for commit 093b7a1.

♻️ This comment has been updated with latest results.

@github-actions
Copy link

github-actions bot commented Dec 8, 2025

Code Coverage

Package Line Rate Branch Rate Complexity Health
ado2gh 72% 70% 712
Octoshift 83% 72% 1739
bbs2gh 83% 78% 663
gei 81% 72% 574
Summary 81% (7738 / 9604) 73% (1840 / 2521) 3688

@ismith ismith merged commit d141fb1 into main Dec 8, 2025
79 of 86 checks passed
@ismith ismith deleted the alert-autofix-1035 branch December 8, 2025 22:09
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.

3 participants