Issues (11)

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

src/Abstracts/Middleware.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Spinzar\Firewall\Abstracts;
4
5
use Spinzar\Firewall\Events\AttackDetected;
6
use Spinzar\Firewall\Traits\Helper;
7
use Closure;
8
use Illuminate\Support\Facades\Redirect;
9
use Illuminate\Support\Facades\Response;
10
11
abstract class Middleware
12
{
13
    use Helper;
14
15
    public $request = null;
16
    public $middleware = null;
17
    public $user_id = null;
18
19
    /**
20
     * Handle an incoming request.
21
     *
22
     * @param \Illuminate\Http\Request $request
23
     * @param \Closure $next
24
     * @return mixed
25
     */
26
    public function handle($request, Closure $next)
27
    {
28
        if ($this->skip($request)) {
29
            return $next($request);
30
        }
31
32
        if ($this->check($this->getPatterns())) {
33
            return $this->respond(config('firewall.responses.block'));
34
        }
35
36
        return $next($request);
37
    }
38
39
    public function skip($request)
40
    {
41
        $this->prepare($request);
42
43
        if ($this->isDisabled()) {
44
            return true;
45
        }
46
47
        if ($this->isWhitelist()) {
48
            return true;
49
        }
50
51
        if (!$this->isMethod()) {
52
            return true;
53
        }
54
55
        if ($this->isRoute()) {
56
            return true;
57
        }
58
59
        return false;
60
    }
61
62
    public function prepare($request)
63
    {
64
        $this->request = $request;
65
        $this->middleware = strtolower((new \ReflectionClass($this))->getShortName());
66
        $this->user_id = auth()->id() ?: 0;
0 ignored issues
show
The method id does only exist in Illuminate\Contracts\Auth\Guard, but not in Illuminate\Contracts\Auth\Factory.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
67
    }
68
69
    public function getPatterns()
70
    {
71
        return config('firewall.middleware.' . $this->middleware . '.patterns', []);
72
    }
73
74
    public function check($patterns)
75
    {
76
        $log = null;
77
78
        foreach ($patterns as $pattern) {
79
            if (!$match = $this->match($pattern, $this->request->input())) {
80
                continue;
81
            }
82
83
            $log = $this->log();
84
85
            event(new AttackDetected($log));
86
87
            break;
88
        }
89
90
        if ($log) {
91
            return true;
92
        }
93
94
        return false;
95
    }
96
97
    public function match($pattern, $input)
98
    {
99
        $result = false;
100
101
        if (!is_array($input) && !is_string($input)) {
102
            return false;
103
        }
104
105
        if (!is_array($input)) {
106
            $input = $this->prepareInput($input);
107
108
            return preg_match($pattern, $input);
109
        }
110
111
        foreach ($input as $key => $value) {
112
            if (is_array($value)) {
113
                if (!$result = $this->match($pattern, $value)) {
114
                    continue;
115
                }
116
117
                break;
118
            }
119
120
            if (!$this->isInput($key)) {
121
                continue;
122
            }
123
124
            $value = $this->prepareInput($value);
125
126
            if (!$result = preg_match($pattern, $value)) {
127
                continue;
128
            }
129
130
            break;
131
        }
132
133
        return $result;
134
    }
135
136
    public function prepareInput($value)
137
    {
138
        return $value;
139
    }
140
141
    public function respond($response, $data = [])
142
    {
143
        if ($response['code'] == 200) {
144
            return '';
145
        }
146
147
        if ($view = $response['view']) {
148
            return Response::view($view, $data);
149
        }
150
151
        if ($redirect = $response['redirect']) {
152
            if (($this->middleware == 'ip') && $this->request->is($redirect)) {
153
                abort($response['code'], trans('firewall::responses.block.message'));
154
            }
155
156
            return Redirect::to($redirect);
157
        }
158
159
        if ($response['abort']) {
160
            abort($response['code'], trans('firewall::responses.block.message'));
161
        }
162
163
        return Response::make(trans('firewall::responses.block.message'), $response['code']);
164
    }
165
}
166