Skip to content

refactor: consolidate refuse-redirect handlers into shared comfy_cli/http.py (BE-2152)#487

Open
mattmillerai wants to merge 1 commit into
mainfrom
matt/be-2152-consolidate-noredirect
Open

refactor: consolidate refuse-redirect handlers into shared comfy_cli/http.py (BE-2152)#487
mattmillerai wants to merge 1 commit into
mainfrom
matt/be-2152-consolidate-noredirect

Conversation

@mattmillerai

Copy link
Copy Markdown
Collaborator

ELI-5

Five different files each had their own private copy of the same little safety class that says "if a server tries to redirect this authenticated request somewhere else, refuse — don't hand over the Bearer token / X-API-Key to wherever it points." Five identical copies means a future security fix could land in one and be forgotten in the other four. This PR replaces all five with one audited definition in a new comfy_cli/http.py, so there's a single source of truth.

What changed

  • New module comfy_cli/http.py — one NoRedirectHandler (stdlib-only, so no import cycles). It refuses to follow any 30x redirect and raises a clear HTTPError instead. The refusal message is a constructor arg so call sites keep their own wording.
  • Swapped in at all 5 sites, deleting each local copy:
    • comfy_client.py (_NoRedirectHandler)
    • cql/engine.py (_NoRedirectHandler)
    • cql/loader.py (_NoRedirect)
    • cloud/oauth.py (_NoRedirect)
    • command/transfer.py (_NoRedirectHandler) — passes "redirect refused (auth leak prevention)" to preserve its original message byte-for-byte.
  • New tests tests/comfy_cli/test_http.py — assert every redirect status (301/302/303/307/308) raises HTTPError with the code preserved, the default "redirect refused" message, and a custom message passed through.

Deliberately NOT touched

  • command/transfer.py's _DownloadRedirectHandler / _DOWNLOAD_OPENER — that one intentionally follows redirects while stripping auth headers (for cloud /api/view → signed-GCS 302s). It is a distinct handler, not a duplicate. Left entirely alone.
  • Did not consolidate the separate _LOOPBACK_HOSTS duplication — out of scope for this ticket.

Behavior

Pure refactor — no behavior change. All four non-transfer sites already used the message "redirect refused" (now the default); transfer's longer message is preserved via the constructor arg. No import removals were needed (every file that kept import urllib.error still uses it elsewhere).

Verification

  • ruff check + ruff format --check clean (ruff v0.15.15, matching the repo's pre-commit pin).
  • Full pytest suite: 2324 passed, 36 skipped.

Judgment calls

  • Dropped the per-site rationale comments/docstrings in favor of the one consolidated docstring in http.py (the ticket calls for deleting the local classes; the shared docstring captures the auth-leak/SSRF reasoning).

@mattmillerai mattmillerai added agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review labels Jul 2, 2026
@mattmillerai mattmillerai marked this pull request as ready for review July 2, 2026 05:30
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

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: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 197573f8-8bd3-4cf1-b8f8-96a89419ddc7

📥 Commits

Reviewing files that changed from the base of the PR and between a628223 and 2aa8c89.

📒 Files selected for processing (7)
  • comfy_cli/cloud/oauth.py
  • comfy_cli/comfy_client.py
  • comfy_cli/command/transfer.py
  • comfy_cli/cql/engine.py
  • comfy_cli/cql/loader.py
  • comfy_cli/http.py
  • tests/comfy_cli/test_http.py
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch matt/be-2152-consolidate-noredirect
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch matt/be-2152-consolidate-noredirect

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

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 2, 2026
@mattmillerai mattmillerai force-pushed the matt/be-2152-consolidate-noredirect branch from 18c9348 to 2aa8c89 Compare July 2, 2026 05:32
@mattmillerai mattmillerai requested a review from skishore23 July 2, 2026 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agent-coded PR authored by the agent-work loop cursor-review Request Cursor bot review size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants