Skip to content

Instantly share code, notes, and snippets.

@daniellima
Last active March 28, 2016 18:55
Show Gist options
  • Select an option

  • Save daniellima/deedb44342171ca02826 to your computer and use it in GitHub Desktop.

Select an option

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
TRUSTED_HOST=http://youraddress.com
A middleware to avoid opening your site to be accessed by arbitrary domains
<?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
];
}
<?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