Skip to content

🔒 Fix argument injection vulnerability in get_pr_status#368

Merged
sheepdestroyer merged 2 commits into
masterfrom
fix-gh-cli-shell-injection-7664865179964863263
Jul 24, 2026
Merged

🔒 Fix argument injection vulnerability in get_pr_status#368
sheepdestroyer merged 2 commits into
masterfrom
fix-gh-cli-shell-injection-7664865179964863263

Conversation

@sheepdestroyer

@sheepdestroyer sheepdestroyer commented Jul 24, 2026

Copy link
Copy Markdown
Owner

🎯 What: Fixed an argument injection vulnerability in scripts/get_pr_status.py when passing the pr_id argument to the gh CLI.\n⚠️ Risk: An attacker could execute arbitrary flags on the gh CLI if an invalid input was passed to the get_pr_status function.\n🛡️ Solution: Added a .isdigit() check to pr_id to explicitly verify that the PR ID format is numeric before appending it to the gh command arguments, otherwise it will exit with an error. Added unit tests for this case.


PR created automatically by Jules for task 7664865179964863263 started by @sheepdestroyer

Summary by Sourcery

Validate PR ID format in get_pr_status before invoking gh CLI to prevent unsafe argument injection.

Bug Fixes:

  • Exit with an error when a non-numeric PR ID is provided to get_pr_status, avoiding unsafe CLI argument usage.

Tests:

  • Add unit test covering behavior when get_pr_status is called with an invalid, non-numeric PR ID.

Summary by CodeRabbit

  • Bug Fixes
    • Added validation for optional pull request IDs.
    • Invalid, non-numeric IDs now produce a clear error and stop processing instead of being submitted.
  • Tests
    • Added coverage to verify the error message and failure behavior for invalid pull request IDs.

@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@sourcery-ai

sourcery-ai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adds validation to ensure PR IDs passed to get_pr_status are strictly numeric before invoking the gh CLI, and introduces a unit test to cover invalid PR ID behavior and error messaging.

Sequence diagram for validated get_pr_status invocation

sequenceDiagram
    actor Developer
    participant get_pr_status
    participant GhCLI

    Developer->>get_pr_status: get_pr_status(pr_id)
    get_pr_status->>get_pr_status: [pr_id]
    alt [pr_id is numeric]
        get_pr_status->>GhCLI: gh pr view pr_id --json state,reviewDecision,statusCheckRollup
    else [pr_id is not numeric]
        get_pr_status->>get_pr_status: print(Error: Invalid PR ID format. Must be numeric.)
        get_pr_status-->>Developer: sys.exit(1)
    end
Loading

File-Level Changes

Change Details Files
Harden get_pr_status against argument injection by validating PR ID format before constructing the gh CLI command.
  • Ensure pr_id is converted to string and checked with isdigit before using it in the command arguments.
  • Print a clear error message to stderr when the PR ID format is invalid.
  • Exit with status code 1 on invalid PR input instead of calling gh.
  • Append the validated PR ID string to the gh command when it passes validation.
scripts/get_pr_status.py
Add unit coverage for invalid PR IDs to assert error handling and messaging.
  • Introduce a test that calls get_pr_status with a non-numeric PR ID and expects SystemExit.
  • Verify the exit code is 1 for invalid PR IDs.
  • Assert that the error message is printed to stderr for invalid PR IDs.
tests/test_get_pr_status.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@sheepdestroyer, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 49 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6437120d-d3e2-475a-ac0e-f9beb1601793

📥 Commits

Reviewing files that changed from the base of the PR and between a1c0c2d and fa2f081.

📒 Files selected for processing (2)
  • scripts/get_pr_status.py
  • tests/test_get_pr_status.py
📝 Walkthrough

Walkthrough

The script now rejects non-numeric optional PR IDs with an error and exit code 1. A test verifies the exit status and stderr message.

Changes

PR ID validation

Layer / File(s) Summary
Validate PR IDs and test invalid input
scripts/get_pr_status.py, tests/test_get_pr_status.py
Provided PR IDs are checked for numeric content before building the gh pr view command; invalid IDs trigger exit code 1 and a validation error on stderr, with corresponding test coverage.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: validating get_pr_status input to prevent argument injection.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix-gh-cli-shell-injection-7664865179964863263

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • Using str(pr_id).isdigit() will reject some potentially valid inputs (e.g., strings with surrounding whitespace or non-decimal numeric formats); consider normalizing the input (strip whitespace, explicit type check) before validating to avoid surprising failures.
  • Since get_pr_status is a callable function rather than just a CLI entrypoint, it may be more flexible to raise a specific exception instead of calling sys.exit(1), letting callers decide how to handle invalid PR IDs.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Using `str(pr_id).isdigit()` will reject some potentially valid inputs (e.g., strings with surrounding whitespace or non-decimal numeric formats); consider normalizing the input (strip whitespace, explicit type check) before validating to avoid surprising failures.
- Since `get_pr_status` is a callable function rather than just a CLI entrypoint, it may be more flexible to raise a specific exception instead of calling `sys.exit(1)`, letting callers decide how to handle invalid PR IDs.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sheepdestroyer
sheepdestroyer force-pushed the fix-gh-cli-shell-injection-7664865179964863263 branch 2 times, most recently from f2d2d0f to a68f56b Compare July 24, 2026 10:40
google-labs-jules Bot and others added 2 commits July 24, 2026 12:45
@sheepdestroyer
sheepdestroyer force-pushed the fix-gh-cli-shell-injection-7664865179964863263 branch from a68f56b to fa2f081 Compare July 24, 2026 10:45
@sheepdestroyer
sheepdestroyer merged commit 028a6f4 into master Jul 24, 2026
8 checks passed
@sheepdestroyer
sheepdestroyer deleted the fix-gh-cli-shell-injection-7664865179964863263 branch July 24, 2026 10:47
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.

1 participant