Issues (85)

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/Http/Controllers/UserController.php (9 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 namespace Mascame\Artificer\Http\Controllers;
2
3
use Auth;
4
use Carbon\Carbon;
5
use Illuminate\Auth\EloquentUserProvider;
6
use Input;
7
use Mascame\Artificer\Options\AdminOption;
8
use Redirect;
9
use Session;
10
use Validator;
11
use View;
12
13
class UserController extends BaseController
14
{
15
16
    public $tries_key = 'artificer.user.login.tries';
17
    public $ban_key = 'artificer.user.login.banned';
18
    public $authProvider;
19
20
    public function __construct() {
21
        parent::__construct();
22
23
        $this->authProvider = new EloquentUserProvider(app('hash'), 'ArtificerUser');
24
    }
25
26
    /**
27
     * Unban user
28
     */
29
    private function unban()
30
    {
31
        Session::forget($this->ban_key);
32
    }
33
34
    /**
35
     * @return bool
36
     */
37
    private function isBanned()
38
    {
39
        if (Session::has($this->ban_key)) {
40
            $ban = Carbon::parse(Session::get($this->ban_key));
41
42
            if (! $ban->isPast()) {
43
                return true;
44
            }
45
        }
46
47
        $this->unban();
48
49
        return false;
50
    }
51
52
    /**
53
     * Ban user
54
     */
55
    private function ban()
56
    {
57
        Session::set($this->ban_key, Carbon::now()->addMinutes(AdminOption::get('auth.ban_time')));
58
    }
59
60
    /**
61
     *
62
     */
63
    private function addAttempt()
64
    {
65
        $tries = Session::get($this->tries_key);
66
67
        if (! $tries) {
68
            $tries = 1;
69
        } else {
70
            $tries++;
71
        }
72
73
        Session::set($this->tries_key, $tries);
74
75
        if ($tries >= AdminOption::get('auth.max_login_attempts')) {
76
            $this->ban();
77
            Session::forget($this->tries_key);
78
        }
79
    }
80
81
    /**
82
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\View\View
83
     */
84
    public function showLogin()
85
    {
86
        if (Auth::check()) return Redirect::route('admin.home');
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
87
88
        return View::make($this->getView('pages.login'));
89
    }
90
91
    /**
92
     * @return $this|\Illuminate\Http\RedirectResponse
93
     */
94
    public function login()
95
    {
96
        if ($this->isBanned()) {
97
            return Redirect::route('admin.showlogin')->withErrors(array("You are banned for too many login attempts"));
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
98
        }
99
100
        $rules = array(
101
            'username' => 'required|email',
102
            'password' => 'required|min:3'
103
        );
104
105
        $validator = Validator::make(Input::all(), $rules);
106
107
        if ($validator->fails()) {
108
            return $this->onFailValidation($validator);
109
        }
110
111
        /*
112
         * Todo: add also to banning in case of fail auth attempt
113
         */
114
        if ($this->isValidUser($this->getUser())) {
0 ignored issues
show
It seems like $this->getUser() targeting Mascame\Artificer\Http\C...erController::getUser() can also be of type object<Mascame\Artificer...rollers\UserController>; however, Mascame\Artificer\Http\C...ntroller::isValidUser() does only seem to accept object<Illuminate\Database\Eloquent\Model>|null, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
115
            return $this->successLoginRedirect();
116
        }
117
118
        return $this->failedLoginRedirect();
119
    }
120
121
    protected function successLoginRedirect() {
122
        return Redirect::route('admin.home');
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
123
    }
124
125
    protected function failedLoginRedirect() {
126
        return Redirect::route('admin.login')
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
127
            ->withInput(Input::except('password'))->withErrors(array('The user credentials are not correct or does not have access'));
128
    }
129
130
    protected static function attempt($attemptClosure, $credentials) {
131
        return is_callable($attemptClosure) ? $attemptClosure($credentials) : false;
132
    }
133
134
    protected static function getClosureAttempt() {
135
        return AdminOption::get('auth.attempt');
136
    }
137
138
    protected static function getClosureCheckAuth() {
139
        return AdminOption::get('auth.check');
140
    }
141
142
    protected static function checkAuth($checkClosure) {
143
        return is_callable($checkClosure) ? $checkClosure() : false;
144
    }
145
146
    public static function check() {
147
        return self::checkAuth(self::getClosureCheckAuth());
148
    }
149
150
    protected function onFailValidation($validator)
151
    {
152
        $this->addAttempt();
153
154
        return Redirect::route('admin.login')
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
155
            ->withErrors($validator)
156
            ->withInput();
157
    }
158
159
    /**
160
     * @return \Illuminate\Database\Eloquent\Model|null|static
161
     */
162
    protected function getUser()
163
    {
164
        return \Mascame\Artificer\Auth\ArtificerUser::where('email', '=', Input::get('username'))
165
            ->OrWhere('username', '=', Input::get('username'))->first();
166
    }
167
168
    /**
169
     * @param $user
170
     * @return bool
171
     */
172
    protected function attemptLogin($user)
173
    {
174
        $role_colum = AdminOption::get('auth.role_column');
175
        if (in_array($user->$role_colum, AdminOption::get('auth.roles'))) {
176
177
            $credentials = array(
178
                'email' => Input::get('username'),
179
                'password' => Input::get('password')
180
            );
181
182
            if (self::attempt(self::getClosureAttempt(), $credentials)) {
183
                return true;
184
            }
185
186
        }
187
188
        return false;
189
    }
190
191
    /**
192
     * @param \Illuminate\Database\Eloquent\Model|null $user
193
     * @return bool
194
     */
195
    protected function isValidUser($user)
196
    {
197
        if ($user) {
198
            if ($this->attemptLogin($user)) {
199
                return true;
200
            }
201
        }
202
203
        return false;
204
    }
205
206
    /**
207
     * @return \Illuminate\Http\RedirectResponse
208
     */
209
    public function logout()
210
    {
211
        Auth::logout();
212
213
        return Redirect::route('admin.showlogin');
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
214
    }
215
216
217
    public function authFilter() {
218
        $roles = AdminOption::get('auth.roles');
219
        $role_column = AdminOption::get('auth.role_column');
220
221
        if (Auth::guest()
222
            && \Route::currentRouteName() != 'admin.showlogin'
223
            && \Route::currentRouteName() != 'admin.login'
224
        ) {
225
            if (\Request::ajax()) {
226
                return \Response::make('Unauthorized', 401);
227
            } else {
228
                return Redirect::route('admin.showlogin');
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
229
            }
230
        } else {
231
            if (Auth::check()
232
                && \Route::currentRouteName() != 'admin.logout'
233
            ) {
234
                if (!in_array(Auth::user()->$role_column, $roles)) {
235
                    return Redirect::route('admin.logout');
0 ignored issues
show
The method route() does not seem to exist on object<redirect>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
236
                }
237
            }
238
        }
239
    }
240
}