XSS::handle()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 14
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 28
ccs 16
cts 16
cp 1
crap 5
rs 9.4888
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
}