Fix unhandled 500 when a proxy target host is blocked#105
Open
morcen wants to merge 1 commit into
Open
Conversation
AllowedHostsGuard::check() throws DisallowedProxyTargetException when a handler's base_uri host is not in the allowed_hosts list, but PassageController only caught InvalidBaseUriException. A blocked host therefore surfaced as an unhandled 500 with a framework error page instead of a clean JSON response, leaking internals and breaking API clients that expect JSON errors from Passage. Catch DisallowedProxyTargetException alongside InvalidBaseUriException and return a JSON 403 response.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was broken
AllowedHostsGuard::check()throwsDisallowedProxyTargetExceptionwhen a handler'sbase_urihost is not in the configuredallowed_hostslist.PassageController::handle()only caughtInvalidBaseUriExceptionaround that call, soDisallowedProxyTargetExceptionpropagated as an unhandled exception, producing a generic 500 framework error page instead of a clean JSON response.The
allowed_hostsguard is a security feature meant to prevent open-proxy misconfigurations, but its failure mode leaked internals (a framework error page) and broke API clients expecting JSON error responses from Passage.What changed
src/Http/Controllers/PassageController.php: catchDisallowedProxyTargetExceptionalongsideInvalidBaseUriExceptionand return a JSON403response with the exception message.tests/Unit/PassageControllerTest.php: add a regression test that enablesenforce_allowed_hosts, hits a route whose handler'sbase_uritargets a disallowed host, and asserts a JSON 403 response instead of a crash.Verification
vendor/bin/pint --dirty: passedcomposer test(vendor/bin/pest): 104 tests passed, 262 assertionsFixes #83.
Generated by Claude Code