Completed
Push — master ( 34b930...ab3e16 )
by Avtandil
05:13
created

XssSecurity   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 1
dl 0
loc 28
ccs 0
cts 17
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B handle() 0 25 4
1
<?php
2
/*
3
 * This file is part of the Laravel Lodash package.
4
 *
5
 * (c) Avtandil Kikabidze aka LONGMAN <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
declare(strict_types=1);
11
12
namespace Longman\LaravelLodash\Middlewares;
13
14
use Closure;
15
use Illuminate\Http\Request;
16
17
class XssSecurity
18
{
19
    public function handle(Request $request, Closure $next)
20
    {
21
        $response = $next($request);
22
23
        $request_uri = $request->getUri();
0 ignored issues
show
Unused Code introduced by
$request_uri is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
24
        $excluded = config('lodash.xss.exclude_uris');
25
        if (! empty($excluded)) {
26
            foreach ($excluded as $uri) {
27
                if (strpos($uri, '/itdc/debug') !== false) {
28
                    return $response;
29
                }
30
            }
31
        }
32
33
        // http://blogs.msdn.com/b/ieinternals/archive/2010/03/30/combating-clickjacking-with-x-frame-options.aspx
34
        $response->headers->set('X-Frame-Options', config('lodash.xss.x_frame_options'), true);
35
36
        // http://msdn.microsoft.com/en-us/library/ie/gg622941(v=vs.85).aspx
37
        $response->headers->set('X-Content-Type-Options', config('lodash.xss.x_content_type_options'), true);
38
39
        // http://msdn.microsoft.com/en-us/library/dd565647(v=vs.85).aspx
40
        $response->headers->set('X-XSS-Protection', config('lodash.xss.x_xss_protection'), true);
41
42
        return $response;
43
    }
44
}
45