Skip to content

Add maxRedirects guard to UrlChecker#20

Merged
leMaur merged 1 commit into
mainfrom
feature/max-redirects-guard
May 27, 2026
Merged

Add maxRedirects guard to UrlChecker#20
leMaur merged 1 commit into
mainfrom
feature/max-redirects-guard

Conversation

@leMaur

@leMaur leMaur commented May 27, 2026

Copy link
Copy Markdown
Owner

What

Adds a maxRedirects guard to UrlChecker to bound redirect-following.

Why

getResponse() followed 301/302/307/308 redirects recursively with no depth cap and no cycle guard — a redirect loop could recurse until PHP hit its memory/stack limit. The recursive hop also silently dropped the caller's userAgent/connectTimeout/timeout.

Changes

  • New public const UrlChecker::DEFAULT_MAX_REDIRECTS = 5 (untyped, to preserve the package's php: ^8.1 support — typed class constants are 8.3+).
  • check() gains a trailing, backward-compatible ?int $maxRedirects = null parameter. maxRedirects: 0 returns the redirect response without following it.
  • getResponse() threads a redirectsLeft budget through the recursion, stops once exhausted (returning the last 3xx response), and now preserves the caller's user-agent and timeouts on every hop.
  • README documents the redirect behavior and the new parameter.

Tests

5 new Pest cases: each of 301/302/307/308 must terminate (in fake mode every hop re-serves the same response, so without the guard the suite would hang — a genuine regression test), plus a maxRedirects: 0 no-follow case.

Local gates: pest 17 pass / 29 assertions, phpstan analyse no errors, pint --test passed.

@leMaur leMaur force-pushed the feature/max-redirects-guard branch from 26dd60e to c15c39e Compare May 27, 2026 06:59
@leMaur leMaur merged commit d06f3a5 into main May 27, 2026
17 checks passed
@leMaur leMaur deleted the feature/max-redirects-guard branch May 27, 2026 07:09
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.

1 participant