XSS   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 15
c 2
b 0
f 0
dl 0
loc 30
ccs 16
cts 16
cp 1
rs 10
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 28 5
1
<?php
2
3
namespace Distilleries\Security\Http\Middleware;
4
5
use Closure;
6
use Distilleries\Security\Helpers\Security;
7
use Illuminate\Http\Request;
8
9
class XSS
10
{
11 10
    public function handle(Request $request, Closure $next)
12
    {
13
14 10
        if (config('security.xss_enable') || config('security.html_purifier')) {
15 8
            $input = $request->all();
16
17
18 8
            $config = \HTMLPurifier_Config::createDefault();
19 8
            $config->set('AutoFormat.RemoveSpansWithoutAttributes', true);
20 8
            $config->set('AutoFormat.RemoveEmpty', true);
21 8
            $config->set('HTML.TidyLevel', 'heavy');
22 8
            $config->set('Cache.DefinitionImpl', null);
23
            //$config->set('HTML.SafeIframe', true);
24
25 4
            array_walk_recursive($input, function(&$input) use ($config) {
26 6
                if (config('security.html_purifier')) {
27 4
                    $input = (new \HTMLPurifier($config))->purify($input);
28
                }
29 6
                if (config('security.xss_enable')) {
30 4
                    $input = (new Security)->xss_clean($input);
31
                }
32
33 8
            });
34
35 8
            $request->merge($input);
36
        }
37
38 10
        return $next($request);
39
40
41
    }
42
}