-
-
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.
This file contains 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 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