|
21 | 21 | use Illuminate\Support\Facades\Schema; |
22 | 22 | use Illuminate\Support\ServiceProvider; |
23 | 23 | use Illuminate\Support\Facades\Log; |
| 24 | +use Illuminate\Support\Facades\URL; |
24 | 25 |
|
25 | 26 | /** |
26 | 27 | * This service provider handles setting the observers on models |
|
31 | 32 | class AppServiceProvider extends ServiceProvider |
32 | 33 | { |
33 | 34 | /** |
34 | | - * Custom email array validation |
| 35 | + * Bootstrap application services. |
35 | 36 | * |
36 | 37 | * @author [A. Gianotto] [<[email protected]>] |
37 | 38 | * @since [v3.0] |
38 | 39 | * @return void |
39 | 40 | */ |
40 | 41 | public function boot(UrlGenerator $url) |
41 | 42 | { |
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'); |
48 | 54 | } |
49 | 55 |
|
50 | 56 | // TODO - isn't it somehow 'gauche' to check the environment directly; shouldn't we be using config() somehow? |
51 | 57 | if ( ! env('APP_ALLOW_INSECURE_HOSTS')) { // unless you set APP_ALLOW_INSECURE_HOSTS, you should PROHIBIT forging domain parts of URL via Host: headers |
52 | 58 | $url_parts = parse_url(config('app.url')); |
53 | 59 | 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')); |
55 | 61 | } else { |
56 | 62 | Log::error("Your APP_URL in your .env is misconfigured - it is: ".config('app.url').". Many things will work strangely unless you fix it."); |
57 | 63 | } |
|
0 commit comments