Issues (2)

Security Analysis    no request data  

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/BaseFraud.php (2 issues)

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
/**
4
 * @author Alireza Josheghani <[email protected]>
5
 * @since 28 Oct 2016
6
 *
7
 * BaseFraud middleware object
8
 */
9
10
namespace Josh\Fraud;
11
12
use Illuminate\Http\Request;
13
use Jenssegers\Agent\Agent;
14
15
class BaseFraud
16
{
17
    /**
18
     * User agent
19
     *
20
     * @var string|array
21
     **/
22
    protected $agent;
23
24
    /**
25
     * check except methods in class
26
     *
27
     * @var array
28
     **/
29
    protected $except = [];
30
31
    /**
32
     * Bots list
33
     *
34
     * @var array
35
     */
36
    private $bots = [
37
        'crawler',
38
        'spider'
39
    ];
40
41
    /**
42
     * BaseFraud constructor.
43
     */
44
    public function __construct(Request $request)
45
    {
46
        // set user agent
47
        $this->agent = $request->header('user-agent');
48
49
        if(function_exists('config_path')) {
50
51
            // if exists bots file then include list
52
            if(file_exists(config_path('bots.php'))) {
53
54
                // require bots list
55
                $this->bots = include config_path('bots.php');
56
            }
57
58
        } else {
59
            $this->bots = include __DIR__ . '/../bots.php';
60
        }
61
    }
62
63
    /**
64
     * Check user agent has browser
65
     *
66
     * @return bool
67
     */
68
    public function isUserAgent()
69
    {
70
        $agent = new Agent;
71
72
        $agent->setUserAgent($this->agent);
0 ignored issues
show
It seems like $this->agent can also be of type array; however, Mobile_Detect::setUserAgent() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
73
        if(! $agent->browser() 
74
            || ! $agent->device()
75
            || ! $agent->platform($this->agent)
0 ignored issues
show
It seems like $this->agent can also be of type array; however, Jenssegers\Agent\Agent::platform() does only seem to accept string|null, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
76
            || ! $agent->version($agent->browser())
77
            || ! $agent->version($agent->platform())
78
        ) {
79
            return true;
80
        }
81
82
        return false;
83
    }
84
85
    /**
86
     * Check user is curl
87
     *
88
     * @author Alireza Josheghani <[email protected]>
89
     * @since  25 Oct , 2016
90
     * @return boolean
91
     */
92
    public function isCurl()
93
    {
94
        if(preg_match('/curl/', $this->agent)) {
95
            return true;
96
        }
97
98
        return false;
99
    }
100
101
    /**
102
     * Check user is httpie
103
     *
104
     * @author Alireza Josheghani <[email protected]>
105
     * @since  27 Oct , 2016
106
     * @return boolean
107
     */
108
    public function isHttpie()
109
    {
110
        if(preg_match('/HTTPie/', $this->agent)) {
111
            return true;
112
        }
113
114
        return false;
115
    }
116
117
    /**
118
     * Check user is robot
119
     *
120
     * @author Alireza Josheghani <[email protected]>
121
     * @since  25 Oct , 2016
122
     */
123
    public function isRobot()
124
    {
125
        foreach ($this->bots as $bot){
126
            if(preg_match('/' . $bot . '/', $this->agent)) {
127
                return true;
128
            }
129
        }
130
131
        return false;
132
    }
133
134
    /**
135
     * Check except methods array
136
     *
137
     * @author Alireza Josheghani <[email protected]>
138
     * @since  28 Oct 2016
139
     * @param  $method
140
     * @return bool
141
     */
142
    public function checkExcept($method)
143
    {
144
        if(!empty($this->except)) {
145
            foreach ($this->except as $except){
146
                if($except === $method) {
147
                    return true;
148
                }
149
            }
150
        }
151
152
        return false;
153
    }
154
155
    /**
156
     * Get all fraud methods
157
     *
158
     * @author Alireza Josheghani <[email protected]>
159
     * @since  28 Oct 2016
160
     * @param  $class
161
     * @return array
162
     */
163
    public function methods()
164
    {
165
        $methods = get_class_methods($this);
166
167
        foreach ($methods as $key => $method){
168
            if(substr($method, 0, 2) !== 'is' || $this->checkExcept($method)) {
169
                unset($methods[$key]);
170
            }
171
        }
172
173
        return $methods;
174
    }
175
176
}