Skip to content

Guard GraphQL PR number conversion against int32 overflow#56

Open
Copilot wants to merge 2 commits intomainfrom
copilot/fix-code-scanning-alerts
Open

Guard GraphQL PR number conversion against int32 overflow#56
Copilot wants to merge 2 commits intomainfrom
copilot/fix-code-scanning-alerts

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 21, 2026

This PR addresses the CodeQL alert on unsafe integer downcast when passing PR numbers into GraphQL query variables. The change ensures int values are validated before converting to graphql.Int (int32-backed).

  • What changed

    • Added a narrow conversion helper in internal/github/github.go:
      • toGraphQLInt(n int) (graphql.Int, error)
      • Enforces math.MinInt32 <= n <= math.MaxInt32
    • Updated FindPRByNumber to use the validated conversion instead of direct cast.
  • Behavioral impact

    • Out-of-range PR numbers now fail fast with a clear error instead of risking truncation/overflow during conversion.
  • Focused coverage

    • Added unit tests in internal/github/github_test.go for:
      • successful in-range conversion
      • error on out-of-range conversion
func toGraphQLInt(n int) (graphql.Int, error) {
	if n < math.MinInt32 || n > math.MaxInt32 {
		return 0, fmt.Errorf("number %d is out of GraphQL Int range", n)
	}
	return graphql.Int(n), nil
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/graphql
    • Triggering command: /tmp/go-build2513184261/b287/cmd.test /tmp/go-build2513184261/b287/cmd.test -test.testlogfile=/tmp/go-build2513184261/b287/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� g_.a 0.1-go1.25.7.lin--64 ux-amd64/pkg/tool/linux_amd64/compile user.name (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Fix code scanning alert #3 Guard GraphQL PR number conversion against int32 overflow Apr 21, 2026
Copilot AI requested a review from skarim April 21, 2026 14:25
@skarim skarim marked this pull request as ready for review April 23, 2026 15:48
Copilot AI review requested due to automatic review settings April 23, 2026 15:48
Copy link
Copy Markdown

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 mitigates a CodeQL-reported unsafe integer downcast by validating int PR numbers before converting them into graphql.Int (int32-backed) for GraphQL query variables.

Changes:

  • Added toGraphQLInt(n int) (graphql.Int, error) to enforce GraphQL Int range bounds before conversion.
  • Updated FindPRByNumber to use the validated conversion instead of a direct cast.
  • Added unit tests covering in-range success and out-of-range failure for the new helper.
Show a summary per file
File Description
internal/github/github.go Adds the guarded intgraphql.Int conversion helper and uses it in FindPRByNumber.
internal/github/github_test.go Adds unit tests for toGraphQLInt range validation behavior.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 2/2 changed files
  • Comments generated: 0

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