Skip to content

Harden project GraphQL lookups by replacing interpolated owner inputs with variableized requests - #51143

Merged
pelikhan merged 6 commits into
mainfrom
copilot/uk-ai-resilience-gov-scan-fix-graphql-injection
Aug 7, 2026
Merged

Harden project GraphQL lookups by replacing interpolated owner inputs with variableized requests#51143
pelikhan merged 6 commits into
mainfrom
copilot/uk-ai-resilience-gov-scan-fix-graphql-injection

Conversation

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Code scanning flagged pkg/cli/project_command.go for GraphQL injection risk: owner-scoped queries were assembled through CLI field interpolation, relying on manual escaping. This change moves those paths to parameterized GraphQL variables carried in JSON request bodies.

  • Owner lookup/query execution path

    • Added a shared helper to execute GraphQL with JSON {query, variables} via gh api graphql --input -.
    • Switched validateOwner, getOwnerNodeId, and getStatusField to use variableized payloads for user-controlled values (login, number) instead of inline/interpolated arguments.
  • Security posture improvement

    • Removed reliance on argument-level interpolation for these lookup queries.
    • Ensures user input is data-bound in variables, not embedded into GraphQL text.
  • Focused test updates

    • Updated project command tests to assert:
      • query strings use $login / $number
      • user-controlled values are present only under variables
      • calls route through --input - with expected --jq behavior.
requestBody := map[string]any{
  "query": `query($login: String!) { organization(login: $login) { id } }`,
  "variables": map[string]any{
    "login": owner,
  },
}

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.2 AIC · ⊞ 8.4K ·
Comment /souschef to run again


Run context: https://github.com/github/gh-aw/actions/runs/31206913072> Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13 AIC · ⊞ 8.4K ·

Comment /souschef to run again

Copilot AI and others added 2 commits August 7, 2026 17:09
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GraphQL injection risk in project_command.go Harden project GraphQL lookups by replacing interpolated owner inputs with variableized requests Aug 7, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Hey @Copilot 👋 — thanks for the security fix! This PR addresses the GraphQL injection risk in pkg/cli/project_command.go by replacing fmt.Sprintf with parameterized GraphQL variables, exactly as recommended in issue #51126.

What looks great:

The fix is aligned with the contributing guidelines for agentic development and follows the project's security-first approach. The changes are minimal and targeted — exactly what a security remediation should look like.

Once you're ready to exit draft status and complete the final validation steps (make agent-report-progress, code review, CodeQL), this should be good to merge. Well done! 🎯

Generated by ✅ Contribution Check · auto · 84.8 AIC · ⊞ 8.7K ·

Copilot AI requested a review from pelikhan August 7, 2026 17:26
@pelikhan
pelikhan marked this pull request as ready for review August 7, 2026 17:28
Copilot AI balanced review requested due to automatic review settings August 7, 2026 17:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Hardens project GraphQL lookups by sending user-controlled values as JSON variables instead of CLI field arguments.

Changes:

  • Adds a shared variableized GraphQL request helper.
  • Migrates owner and status-field lookups.
  • Updates tests to verify query separation, variable types, and CLI arguments.
Show a summary per file
File Description
pkg/cli/project_command.go Uses JSON GraphQL variables for project lookups.
pkg/cli/project_command_test.go Validates request bodies and invocation arguments.

Review details

Tip

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

  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please triage this PR, refresh the branch if possible, and run the pr-finisher skill before handing back to maintainers.

Failed checks to inspect:

Run context: https://github.com/github/gh-aw/actions/runs/31204567664

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 10.2 AIC · ⊞ 8.4K ·
Comment /souschef to run again

@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Triage Result

Category: bug (security hardening) · Risk: medium · Priority: high (score 74/100 — impact 30, urgency 26, quality 18)
Recommended action: fast_track

Notes: Addresses a code-scanning GraphQL injection finding by parameterizing queries — security-relevant, prioritize review. CI: Unit tests (D-L) is currently failing; other jobs pass. AI reviewer left comments. Needs the D-L failure resolved (see #51151) before merge.

Generated by 🔧 PR Triage Agent · auto · 31.2 AIC · ⌖ 2.44 AIC · ⊞ 7.9K ·

@gh-aw-bot

Copy link
Copy Markdown
Collaborator

@copilot Please triage this PR, refresh the branch if GitHub can update it cleanly, inspect the failing checks below, and run the pr-finisher skill before handing back to maintainers.

Failed checks to inspect:

This security hardening change appears blocked by the same D-L failure tracked by #51151. Please confirm whether this branch only needs a refresh/retest after that fix lands, or whether additional branch-local changes are needed.

Run context: https://github.com/github/gh-aw/actions/runs/31206913072

Generated by 👨‍🍳 PR Sous Chef · gpt54 · 13 AIC · ⊞ 8.4K ·
Comment /souschef to run again

@pelikhan
pelikhan merged commit 2e5eaa9 into main Aug 7, 2026
@pelikhan
pelikhan deleted the copilot/uk-ai-resilience-gov-scan-fix-graphql-injection branch August 7, 2026 18:42
Copilot stopped work on behalf of gh-aw-bot due to an error August 7, 2026 18:42
Copilot AI requested a review from gh-aw-bot August 7, 2026 18:42
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

🎉 This pull request is included in a new release.

Release: v0.86.1

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.

[uk-ai-resilience] [gov-scan] GraphQL injection risk via fmt.Sprintf in project_command.go (alerts #651, #652)

4 participants