ModSecurity::detect()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 3
1
<?php
2
/**
3
 * This file is part of SHIELDFY Web Application Firewall Detector.
4
 * (c) 2016 SHIELDFY, All rights reserved.
5
 *
6
 * The code provided was developed by Matthias "Nihylum" Kaschubowski
7
 *
8
 * The applied license is stored at the root directory of this package.
9
 */
10
namespace Shieldfy\Firewall;
11
12
use Shieldfy\FirewallInterface;
13
14
/**
15
 * Mod_Security Firewall Class.
16
 *
17
 * @deprecated The checkup does suffer from inconsistency, high fake possibility
18
 *
19
 * @package    shieldfy.waf-detector
20
 *
21
 * @author     Matthias Kaschubowski <[email protected]>
22
 */
23
class ModSecurity implements FirewallInterface
24
{
25
    /**
26
     * returns the name of the firewall.
27
     *
28
     * @return string
29
     */
30
    public function getName()
31
    {
32
        return 'mod_security';
33
    }
34
35
    /**
36
     * detects whether the provided headers and body string does match the firewall identification rules or not.
37
     *
38
     * @param string[] $headers
39
     * @param string   $bodyString
40
     * @param string   $url
41
     *
42
     * @return bool
43
     */
44
    public function detect(array $headers, $bodyString, $url)
45
    {
46
        $response = @file_get_contents("{$url}/../../etc");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $url instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
47
48
        if (strstr($response['content'], 'Mod_Security')) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return (bool) strstr($re...ent'], 'Mod_Security');.
Loading history...
49
            return true;
50
        }
51
52
        return false;
53
    }
54
}
55