Last active
April 19, 2021 23:32
-
-
Save iangcarroll/a54e9d46125a01584207 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 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 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"); | |
// Simple IDS | |
$filters = new \Expose\FilterCollection(); | |
$filters->load(); | |
// create a log channel | |
$monolog = Log::getMonolog(); | |
$manager = new \Expose\Manager($filters, $monolog); | |
if (! empty($_POST)) { | |
$manager->run($_POST); | |
$post = True; | |
} | |
if ($manager->getImpact() > 7 && $post == True) { | |
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