Skip to content

Commit db0a078

Browse files
authored
Merge pull request #10573 from uberbrady/fix_force_root_url
Add some guardrails around very-badly formatted APP_URL settings
2 parents 9634dde + 1cf1278 commit db0a078

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,12 @@ public function boot(UrlGenerator $url)
4747
// TODO - isn't it somehow 'gauche' to check the environment directly; shouldn't we be using config() somehow?
4848
if ( ! env('APP_ALLOW_INSECURE_HOSTS')) { // unless you set APP_ALLOW_INSECURE_HOSTS, you should PROHIBIT forging domain parts of URL via Host: headers
4949
$url_parts = parse_url(config('app.url'));
50-
$root_url = $url_parts['scheme'].'://'.$url_parts['host'].( isset($url_parts['port']) ? ':'.$url_parts['port'] : '');
51-
\URL::forceRootUrl($root_url);
50+
if ($url_parts && array_key_exists('scheme', $url_parts) && array_key_exists('host', $url_parts)) {
51+
$root_url = $url_parts['scheme'].'://'.$url_parts['host'].(isset($url_parts['port']) ? ':'.$url_parts['port'] : '');
52+
\URL::forceRootUrl($root_url);
53+
} else {
54+
\Log::error("Your APP_URL in your .env is misconfigured - it is: ".config('app.url').". Many things will work strangely unless you fix it.");
55+
}
5256
}
5357

5458
Schema::defaultStringLength(191);

0 commit comments

Comments
 (0)