Issues (48)

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/Support/auth/ThrottlesLogins.php (4 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
 * Created by PhpStorm.
4
 * User: Claudio Cardinale <[email protected]>
5
 * Date: 18/11/15
6
 * Time: 16.49
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
18
 */
19
20
namespace Tymon\JWTAuth\Support\auth;
21
22
use Illuminate\Cache\RateLimiter;
23
use Illuminate\Http\JsonResponse;
24
use Illuminate\Http\Request;
25
use Illuminate\Support\Facades\Lang;
26
27
/**
28
 * Class ThrottlesLogins
29
 * @package Tymon\JWTAuth\Support\auth
30
 * @author Claudio Cardinale <[email protected]>
31
 * @copyright 2015 Claudio Cardinale
32
 * @version 1.0.0
33
 */
34
trait ThrottlesLogins
35
{
36
    /**
37
     * Determine if the user has too many failed login attempts.
38
     *
39
     * @param  \Illuminate\Http\Request  $request
40
     * @return bool
41
     */
42
    protected function hasTooManyLoginAttempts(Request $request)
43
    {
44
        return app(RateLimiter::class)->tooManyAttempts(
45
            $this->getInputs($request).$request->ip(),
46
            $this->maxLoginAttempts(), $this->lockoutTime() / 60
47
        );
48
    }
49
50
    /**
51
     * Increment the login attempts for the user.
52
     *
53
     * @param  \Illuminate\Http\Request  $request
54
     * @return int
55
     */
56
    protected function incrementLoginAttempts(Request $request)
57
    {
58
        app(RateLimiter::class)->hit(
59
            $this->getInputs($request).$request->ip()
60
        );
61
    }
62
63
    /**
64
     * Determine how many retries are left for the user.
65
     *
66
     * @param  \Illuminate\Http\Request  $request
67
     * @return int
68
     */
69
    protected function retriesLeft(Request $request)
70
    {
71
        $attempts = app(RateLimiter::class)->attempts(
72
            $this->getInputs($request).$request->ip()
73
        );
74
75
        return $this->maxLoginAttempts() - $attempts + 1;
76
    }
77
78
    /**
79
     * Redirect the user after determining they are locked out.
80
     *
81
     * @param  \Illuminate\Http\Request  $request
82
     * @return \Illuminate\Http\RedirectResponse
83
     */
84
    protected function sendLockoutResponse(Request $request)
85
    {
86
        $seconds = app(RateLimiter::class)->availableIn(
87
            $this->getInputs($request).$request->ip()
88
        );
89
90
        $usernames = $this->loginUsername();
0 ignored issues
show
It seems like loginUsername() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
91
        if(!is_array($usernames)) {
92
            $usernames = [$usernames];
93
        }
94
        return new JsonResponse([
95
            implode('.', $usernames) => [$this->getLockoutErrorMessage($seconds)],
96
        ], 422);
97
    }
98
99
    /**
100
     * Get the login lockout error message.
101
     *
102
     * @param  int  $seconds
103
     * @return string
104
     */
105
    protected function getLockoutErrorMessage($seconds)
106
    {
107
        return Lang::has('auth.throttle')
108
            ? Lang::get('auth.throttle', ['seconds' => $seconds])
109
            : 'Too many login attempts. Please try again in '.$seconds.' seconds.';
110
    }
111
112
    /**
113
     * Clear the login locks for the given user credentials.
114
     *
115
     * @param  \Illuminate\Http\Request  $request
116
     * @return void
117
     */
118
    protected function clearLoginAttempts(Request $request)
119
    {
120
        app(RateLimiter::class)->clear(
121
            $this->getInputs($request).$request->ip()
122
        );
123
    }
124
125
    /**
126
     * Get the maximum number of login attempts for delaying further attempts.
127
     *
128
     * @return int
129
     */
130
    protected function maxLoginAttempts()
131
    {
132
        return property_exists($this, 'maxLoginAttempts') ? $this->maxLoginAttempts : 5;
0 ignored issues
show
The property maxLoginAttempts does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
133
    }
134
135
    /**
136
     * The number of seconds to delay further login attempts.
137
     *
138
     * @return int
139
     */
140
    protected function lockoutTime()
141
    {
142
        return property_exists($this, 'lockoutTime') ? $this->lockoutTime : 60;
0 ignored issues
show
The property lockoutTime does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
143
    }
144
145
146
    /**
147
     * get username inputs as string
148
     *
149
     * @param Request $request
150
     * @return string
151
     */
152
    private function getInputs(Request $request)
153
    {
154
        $usernames = $this->loginUsername();
0 ignored issues
show
It seems like loginUsername() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
155
        if(!is_array($usernames)) {
156
            $usernames = [$usernames];
157
        }
158
159
        $ret = '';
160
        foreach($usernames as $username)
161
            $ret .= $request->input($username).'.';
162
        $ret = substr($ret, 0, -1);
163
164
        return $ret;
165
    }
166
}