Skip to content

fix: detect and prevent redirect loops with Client/Pool #4361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

mcollina
Copy link
Member

Summary

Fixes redirect interceptor failing to redirect with Client and Pool by detecting redirect loops that occur when single-host dispatchers attempt cross-origin redirects.

Problem

Issue #4360 reported that when using Client or Pool with the redirect interceptor, cross-origin redirects would fail silently and loop infinitely instead of following the redirect properly. This happened because:

  1. Client and Pool are single-host dispatchers bound to specific origins
  2. They cannot handle cross-origin redirects properly
  3. Instead of failing cleanly, they would loop trying to redirect to the same URL repeatedly

Solution

  • Added redirect loop detection in RedirectHandler
  • When a redirect loop is detected, throw a clear error message instead of infinite looping
  • The error message guides users to use Agent for cross-origin redirects
  • Agent continues to work correctly for cross-origin redirects

Test Plan

  • Added comprehensive tests covering Client, Pool, and Agent behavior
  • ✅ Client throws clear error for cross-origin redirects
  • ✅ Pool throws clear error for cross-origin redirects
  • ✅ Agent successfully follows cross-origin redirects
  • ✅ Same-origin redirects continue to work with Agent

Error Message

Before: Silent infinite loops until maxRedirections reached
After: Redirect loop detected. Cannot redirect to ${origin}. This typically happens when using a Client or Pool with cross-origin redirects. Use an Agent for cross-origin redirects.

Fixes #4360

🤖 Generated with Claude Code

Fixes redirect interceptor failing to redirect with Client and Pool
by detecting redirect loops that occur when single-host dispatchers
attempt cross-origin redirects. Instead of infinite loops, now throws
clear error messages directing users to use Agent for cross-origin
redirects.

Fixes #4360

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
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.

Redirect interceptor fails to redirect
1 participant