Skip to content

Fix weakness to host header manipulation - #1121

Merged
markstory merged 2 commits into
5.xfrom
fix-host-trust
Nov 9, 2026
Merged

markstory merged 2 commits into
5.xfrom
fix-host-trust

Conversation

@markstory

Copy link
Copy Markdown
Member

For a long time we used HTTP_HOST as a fallback for fullBaseUrl, but doing so makes applications vulnerable to host header injection. In #1071, the HostHeaderMiddleware was introduced to address this weakness. However, in #1076 the debug condition was removed to address feedback, but also re-opened the weakness to host-header injection.

These changes restore the debug check around automatically trusting HTTP_HOST. The HostHeaderMiddleware is applied after error handling so configuration mistakes are easy to identify.

Thanks to Jaro Varga for reporting this.

For a long time we used `HTTP_HOST` as a fallback for `fullBaseUrl`, but
doing so makes applications vulnerable to host header injection. In #1071,
the `HostHeaderMiddleware` was introduced to address this weakness.
However, in #1076 the debug condition was removed to address feedback,
but also re-opened the weakness to host-header injection.

These changes restore the `debug` check around automatically trusting
`HTTP_HOST`. The `HostHeaderMiddleware` is applied *after* error
handling so configuration mistakes are easy to identify.

Thanks to Jaro Varga for reporting this.
@markstory markstory added this to the 5.x milestone Nov 8, 2026
Comment thread config/bootstrap.php
$s = null;
if (env('HTTPS') || env('HTTP_X_FORWARDED_PROTO') === 'https') {
$s = 's';
if (Configure::read('debug')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no fan of that $s variable.

Wouldn't something like this be more readable ? 🤖

$fullBaseUrl = Configure::read('App.fullBaseUrl');

if (!$fullBaseUrl && Configure::read('debug')) {
    $httpHost = env('HTTP_HOST');
    if ($httpHost) {
        $scheme = (
            env('HTTPS') || env('HTTP_X_FORWARDED_PROTO') === 'https'
        ) ? 'https' : 'http';

        $fullBaseUrl = $scheme . '://' . $httpHost;
    }
    unset($httpHost, $scheme);
}

if ($fullBaseUrl) {
    Router::fullBaseUrl($fullBaseUrl);
}
unset($fullBaseUrl);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

@LordSimal

Copy link
Copy Markdown
Member

With josbeir's improvement I'd say this looks good.

@markstory
markstory merged commit 6f9b840 into 5.x Nov 9, 2026
4 checks passed
@markstory
markstory deleted the fix-host-trust branch November 9, 2026 04:37
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.

4 participants