Skip to content

[4.x] Reject non-redirect status codes in redirect() - #160

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-redirect-status-check
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-redirect-status-check

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

The guard in AbstractWebApplication::redirect() reads if (!\is_int($status) && !$this->isRedirectState($status)), so only non-integer values were checked and every integer passed: redirect('http://x.test/', 200) sends HTTP/1.1 200 OK plus a Location header. The check also sat inside the header branch, so the JavaScript fallbacks (headers already sent, Trident with non-ASCII URL) skipped it completely.

The status is now checked with isRedirectState() at the start of redirect(), before anything is output, and an InvalidArgumentException is thrown for anything that is not a known 3xx code.

Behaviour change in 4.x: calls that passed a non-3xx integer (which produced a broken response) now throw.

Testing Instructions

vendor/bin/phpunit --filter testRedirectWithInvalidStatus covers 200, 404, an unknown 3xx code (399) and a non-numeric string, with headers already sent so that the JavaScript branch is exercised too. All four cases fail without the change in src/; the existing redirect tests still pass.

Documentation Changes Required

docs/web-application.md described the permissive check as a pitfall; it now describes the validation. docs/api-reference.md mentions the exception.

🤖 Generated with Claude Code

The guard in redirect() only validated non-integer status codes, so any
integer passed: redirect($url, 200) sent "200 OK" with a Location header.
The check was also skipped entirely when the redirect fell back to
JavaScript.

The status is now validated with isRedirectState() before anything is
sent, in every branch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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