Issues (25)

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/Http/Controllers/ResetPasswordController.php (8 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
namespace Yab\FlightDeck\Http\Controllers;
4
5
use Illuminate\Support\Str;
6
use Illuminate\Http\Request;
7
use Illuminate\Http\Response;
8
use Illuminate\Http\JsonResponse;
9
use Illuminate\Routing\Controller;
10
use Illuminate\Support\Facades\Auth;
11
use Illuminate\Support\Facades\Hash;
12
use Illuminate\Support\Facades\Password;
13
use Illuminate\Auth\Events\PasswordReset;
14
use Yab\FlightDeck\Http\Requests\ResetPasswordRequest;
15
16
class ResetPasswordController extends Controller
17
{
18
    /*
19
    |--------------------------------------------------------------------------
20
    | Password Reset Controller
21
    |--------------------------------------------------------------------------
22
    |
23
    | This controller is responsible for handling password reset requests
24
    | and uses a simple trait to include this behavior. You're free to
25
    | explore this trait and override any methods you wish to tweak.
26
    |
27
    */
28
29
    /**
30
     * Create a new controller instance.
31
     *
32
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
33
     */
34
    public function __construct()
35
    {
36
        $this->middleware('guest');
37
    }
38
39
    /**
40
     * Reset the given user's password.
41
     *
42
     * @param  Yab\FlightDeck\Http\Requests\ResetPasswordRequest  $request
43
     * @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
44
     */
45
    public function reset(ResetPasswordRequest $request)
46
    {
47
        $response = $this->broker()->reset(
48
            $this->credentials($request),
49
            function ($user, $password) {
50
                $this->resetPassword($user, $password);
51
            }
52
        );
53
54
        return $response == Password::PASSWORD_RESET
55
            ? $this->sendResetResponse($request, $response)
56
            : $this->sendResetFailedResponse($request, $response);
57
    }
58
59
    /**
60
     * Get the response for a successful password reset.
61
     *
62
     * @param  Yab\FlightDeck\Http\Requests\ResetPasswordRequest   $request
63
     * @param  string  $response
64
     * @return \Illuminate\Http\JsonResponse
65
     */
66
    protected function sendResetResponse(ResetPasswordRequest $request, $response)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        return new JsonResponse([
69
            'success' => true,
70
            'message' => '',
71
        ], Response::HTTP_OK);
72
    }
73
74
    /**
75
     * Get the response for a failed password reset.
76
     *
77
     * @param  Yab\FlightDeck\Http\Requests\ResetPasswordRequest   $request
78
     * @param  string  $response
79
     * @return \Illuminate\Http\JsonResponse
80
     */
81
    protected function sendResetFailedResponse(ResetPasswordRequest $request, $response)
0 ignored issues
show
The parameter $request is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
The parameter $response is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        return new JsonResponse([
84
            'success' => false,
85
            'message' => 'An error occurred while trying to reset the password',
86
        ], Response::HTTP_INTERNAL_SERVER_ERROR);
87
    }
88
89
    /**
90
     * Get the password reset credentials from the request.
91
     *
92
     * @param  \Illuminate\Http\Request  $request
93
     * @return array
94
     */
95
    protected function credentials(Request $request)
96
    {
97
        return $request->only(
98
            'email',
99
            'password',
100
            'password_confirmation',
101
            'token'
102
        );
103
    }
104
105
    /**
106
     * Set the user's password.
107
     *
108
     * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user
109
     * @param  string  $password
110
     * @return void
111
     */
112
    protected function setUserPassword($user, $password)
113
    {
114
        $user->password = Hash::make($password);
0 ignored issues
show
Accessing password on the interface Illuminate\Contracts\Auth\CanResetPassword suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
115
    }
116
117
    /**
118
     * Reset the given user's password.
119
     *
120
     * @param  \Illuminate\Contracts\Auth\CanResetPassword  $user
121
     * @param  string  $password
122
     * @return void
123
     */
124
    protected function resetPassword($user, $password)
125
    {
126
        $this->setUserPassword($user, $password);
127
128
        $user->setRememberToken(Str::random(60));
129
130
        $user->save();
131
132
        event(new PasswordReset($user));
0 ignored issues
show
$user is of type object<Illuminate\Contra...\Auth\CanResetPassword>, but the function expects a object<Illuminate\Contracts\Auth\Authenticatable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
133
134
        $this->guard()->login($user);
0 ignored issues
show
$user is of type object<Illuminate\Contra...\Auth\CanResetPassword>, but the function expects a object<Illuminate\Contracts\Auth\Authenticatable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
135
    }
136
137
    /**
138
     * Get the broker to be used during password reset.
139
     *
140
     * @return \Illuminate\Contracts\Auth\PasswordBroker
141
     */
142
    public function broker()
143
    {
144
        return Password::broker();
145
    }
146
147
    /**
148
     * Get the guard to be used during password reset.
149
     *
150
     * @return \Illuminate\Contracts\Auth\StatefulGuard
151
     */
152
    protected function guard()
153
    {
154
        return Auth::guard();
155
    }
156
}
157