Skip to content

Instantly share code, notes, and snippets.

@artturik
Forked from iangcarroll/Security.php
Last active September 23, 2018 18:45
Show Gist options
  • Save artturik/16b95108e6693d14808985804a56a4cb to your computer and use it in GitHub Desktop.
Save artturik/16b95108e6693d14808985804a56a4cb to your computer and use it in GitHub Desktop.
Expose (a PHPIDS fork) middleware for Laravel. Assumes it's already included via composer.
<?php
namespace App\Http\Middleware;
use Closure;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Log;
class Security {
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
// Headers
// XSS Protection
header("X-XSS-Protection: 1; mode=block");
// Mask PHP
header("X-Powered-By: None-Of-Your-Business");
header("Server: A-Web-Server/-1.0");
if ($request->isMethodSafe()){
return $next($request);
}
// Simple IDS
$filters = new \Expose\FilterCollection();
$filters->load();
// create a log channel
$monolog = Log::getMonolog();
$manager = new \Expose\Manager($filters, $monolog);
$manager->run($request->input());
if ($manager->getImpact() > 7) {
abort(403, "A security issue was identified with your request, and it was terminated.");
}
return $next($request);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment