Skip to content

Commit

Permalink
Add option to force TLS connection (#9327)
Browse files Browse the repository at this point in the history
Co-authored-by: Lars Kajes <[email protected]>
  • Loading branch information
kajes and Lars Kajes authored Apr 6, 2021
1 parent 09887bd commit 49532e1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ APP_LOG=single
APP_LOG_MAX_FILES=10
APP_LOCKED=false
APP_CIPHER=AES-256-CBC
APP_FORCE_TLS=false
GOOGLE_MAPS_API=
LDAP_MEM_LIM=500M
LDAP_TIME_LIM=600
Expand Down
10 changes: 9 additions & 1 deletion app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use App\Observers\SettingObserver;
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\ServiceProvider;
use Illuminate\Routing\UrlGenerator;

/**
* This service provider handles setting the observers on models
Expand All @@ -33,8 +34,15 @@ class AppServiceProvider extends ServiceProvider
* @since [v3.0]
* @return void
*/
public function boot()
public function boot(UrlGenerator $url)
{
if (env('APP_FORCE_TLS')) {
if (strpos(env('APP_URL'), 'https') === 0) {
$url->forceScheme('https');
} else {
\Log::warning("'APP_FORCE_TLS' is set to true, but 'APP_URL' does not start with 'https://'. Will not force TLS on connections.");
}
}
Schema::defaultStringLength(191);
Asset::observe(AssetObserver::class);
Accessory::observe(AccessoryObserver::class);
Expand Down

0 comments on commit 49532e1

Please sign in to comment.