Repository navigation
fix(imp): guard missing HTTP_HOST in getAutoLoginServer() - #62
Merged
Merged
Conversation
Avoid PHP 8 undefined array key warnings when matching preferred mail servers if $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'] are unset.
ralflang
approved these changes
Jun 12, 2026
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.
Guard missing
HTTP_HOSTinIMP_Auth::getAutoLoginServer()Summary
$_SERVER['SERVER_NAME']and$_SERVER['HTTP_HOST']safely before matching against a backend'spreferredhostname list.Problem
IMP_Auth::getAutoLoginServer()selects the default IMAP server when a backend definespreferredhostnames. The check used$_SERVER['SERVER_NAME']and$_SERVER['HTTP_HOST']directly:If
SERVER_NAMEdoes not match the preferred list, PHP still evaluatesHTTP_HOST. When that key is missing, PHP 8+ logs a warning such as:This can occur outside a typical browser request, for example:
HostheaderSERVER_NAMEbut notHTTP_HOSTInstallations with
preferredconfigured inbackends.local.phphit this code path on every autologin server lookup, so the warning can appear frequently inhorde.logeven though functionality otherwise continues.Solution
Extract both server variables with null coalescing and only pass defined values to
in_array():This matches the defensive pattern already used elsewhere in Horde (for example
Horde\Core\Config\Vhostandhorde/config/conf.php.dist).When neither variable is set, the method falls through to the first non-disabled server key, same as when neither hostname matches
preferred.Related work
Similar unchecked
$_SERVER['HTTP_HOST']access exists in other Horde apps (ingo,passwd). Those are out of scope for this PR but may warrant the same treatment if warnings appear there.Test plan
preferredset andHTTP_HOSTunset; confirm no PHP warning is logged.preferredmatchingSERVER_NAME, confirm the correct backend is selected as the autologin server.preferredmatching onlyHTTP_HOST, confirm the correct backend is still selected on a normal HTTP request.preferred, confirm the first enabled server is returned as before.hordeauth.