Last active
March 28, 2016 18:55
-
-
Save daniellima/deedb44342171ca02826 to your computer and use it in GitHub Desktop.
A middleware to avoid opening your site to be accessed by arbitrary domains
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| TRUSTED_HOST=http://youraddress.com |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| A middleware to avoid opening your site to be accessed by arbitrary domains |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http; | |
| use App\Http\Middleware\TrustedHostMiddleware; | |
| use Illuminate\Foundation\Http\Kernel as HttpKernel; | |
| class Kernel extends HttpKernel | |
| { | |
| /** | |
| * The application's global HTTP middleware stack. | |
| * | |
| * @var array | |
| */ | |
| protected $middleware = [ | |
| \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, | |
| \App\Http\Middleware\EncryptCookies::class, | |
| \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class, | |
| \Illuminate\Session\Middleware\StartSession::class, | |
| \Illuminate\View\Middleware\ShareErrorsFromSession::class, | |
| \App\Http\Middleware\VerifyCsrfToken::class, | |
| TrustedHostMiddleware::class | |
| ]; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| namespace App\Http\Middleware; | |
| use Closure; | |
| use Illuminate\Http\Request; | |
| class TrustedHostMiddleware | |
| { | |
| public function handle($request, Closure $next) | |
| { | |
| if (env('TRUSTED_HOST')) { | |
| Request::setTrustedHosts([env('TRUSTED_HOST')]); | |
| } | |
| return $next($request); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment