Skip to content

Commit d8eccf0

Browse files
authored
Merge pull request #14896 from snipe/fixes/tls_loading
Possible fix for proxy/reverse proxy
2 parents b8882fa + d9f70c1 commit d8eccf0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Illuminate\Support\Facades\Schema;
2222
use Illuminate\Support\ServiceProvider;
2323
use Illuminate\Support\Facades\Log;
24+
use Illuminate\Support\Facades\URL;
2425

2526
/**
2627
* This service provider handles setting the observers on models
@@ -31,27 +32,32 @@
3132
class AppServiceProvider extends ServiceProvider
3233
{
3334
/**
34-
* Custom email array validation
35+
* Bootstrap application services.
3536
*
3637
* @author [A. Gianotto] [<[email protected]>]
3738
* @since [v3.0]
3839
* @return void
3940
*/
4041
public function boot(UrlGenerator $url)
4142
{
42-
if (env('APP_FORCE_TLS')) {
43-
if (strpos(env('APP_URL'), 'https') === 0) {
44-
$url->forceScheme('https');
45-
} else {
46-
Log::debug("'APP_FORCE_TLS' is set to true, but 'APP_URL' does not start with 'https://'. Will not force TLS on connections.");
47-
}
43+
/**
44+
* This is a workaround for proxies/reverse proxies that don't always pass the proper headers.
45+
*
46+
* Here, we check if the APP_URL starts with https://, which we should always honor,
47+
* regardless of how well the proxy or network is configured.
48+
*
49+
* We'll force the https scheme if the APP_URL starts with https://, or if APP_FORCE_TLS is set to true.
50+
*
51+
*/
52+
if ((strpos(env('APP_URL'), 'https://') === 0) || (env('APP_FORCE_TLS'))) {
53+
$url->forceScheme('https');
4854
}
4955

5056
// TODO - isn't it somehow 'gauche' to check the environment directly; shouldn't we be using config() somehow?
5157
if ( ! env('APP_ALLOW_INSECURE_HOSTS')) { // unless you set APP_ALLOW_INSECURE_HOSTS, you should PROHIBIT forging domain parts of URL via Host: headers
5258
$url_parts = parse_url(config('app.url'));
5359
if ($url_parts && array_key_exists('scheme', $url_parts) && array_key_exists('host', $url_parts)) { // check for the *required* parts of a bare-minimum URL
54-
\URL::forceRootUrl(config('app.url'));
60+
URL::forceRootUrl(config('app.url'));
5561
} else {
5662
Log::error("Your APP_URL in your .env is misconfigured - it is: ".config('app.url').". Many things will work strangely unless you fix it.");
5763
}

0 commit comments

Comments
 (0)