Skip to content

Commit af9af78

Browse files
committed
Merge branch 'develop' into feature/vuejs
2 parents 48cb01f + d9948f2 commit af9af78

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ This file is a running track of new features and fixes to each version of the pa
33

44
This project follows [Semantic Versioning](http://semver.org) guidelines.
55

6+
## v0.7.9 (Derelict Dermodactylus)
7+
### Fixed
8+
* Fixes a two-factor authentication bypass present in the password reset process for an account.
9+
610
## v0.7.8 (Derelict Dermodactylus)
711
### Added
812
* Nodes can now be put into maintenance mode to deny access to servers temporarily.

app/Http/Controllers/Auth/ResetPasswordController.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22

33
namespace Pterodactyl\Http\Controllers\Auth;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Http\JsonResponse;
7+
use Illuminate\Contracts\Hashing\Hasher;
68
use Illuminate\Support\Facades\Password;
9+
use Illuminate\Auth\Events\PasswordReset;
10+
use Illuminate\Contracts\Events\Dispatcher;
711
use Pterodactyl\Exceptions\DisplayException;
812
use Pterodactyl\Http\Controllers\Controller;
913
use Illuminate\Foundation\Auth\ResetsPasswords;
1014
use Pterodactyl\Http\Requests\Auth\ResetPasswordRequest;
15+
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1116

1217
class ResetPasswordController extends Controller
1318
{
@@ -20,6 +25,40 @@ class ResetPasswordController extends Controller
2025
*/
2126
public $redirectTo = '/';
2227

28+
/**
29+
* @var bool
30+
*/
31+
protected $hasTwoFactor = false;
32+
33+
/**
34+
* @var \Illuminate\Contracts\Events\Dispatcher
35+
*/
36+
private $dispatcher;
37+
38+
/**
39+
* @var \Illuminate\Contracts\Hashing\Hasher
40+
*/
41+
private $hasher;
42+
43+
/**
44+
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
45+
*/
46+
private $userRepository;
47+
48+
/**
49+
* ResetPasswordController constructor.
50+
*
51+
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
52+
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
53+
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $userRepository
54+
*/
55+
public function __construct(Dispatcher $dispatcher, Hasher $hasher, UserRepositoryInterface $userRepository)
56+
{
57+
$this->dispatcher = $dispatcher;
58+
$this->hasher = $hasher;
59+
$this->userRepository = $userRepository;
60+
}
61+
2362
/**
2463
* Reset the given user's password.
2564
*
@@ -49,6 +88,35 @@ public function __invoke(ResetPasswordRequest $request): JsonResponse
4988
throw new DisplayException(trans($response));
5089
}
5190

91+
/**
92+
* Reset the given user's password. If the user has two-factor authentication enabled on their
93+
* account do not automatically log them in. In those cases, send the user back to the login
94+
* form with a note telling them their password was changed and to log back in.
95+
*
96+
* @param \Illuminate\Contracts\Auth\CanResetPassword|\Pterodactyl\Models\User $user
97+
* @param string $password
98+
*
99+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
100+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
101+
*/
102+
protected function resetPassword($user, $password)
103+
{
104+
$user = $this->userRepository->update($user->id, [
105+
'password' => $this->hasher->make($password),
106+
$user->getRememberTokenName() => Str::random(60),
107+
]);
108+
109+
$this->dispatcher->dispatch(new PasswordReset($user));
110+
111+
// If the user is not using 2FA log them in, otherwise skip this step and force a
112+
// fresh login where they'll be prompted to enter a token.
113+
if (! $user->use_totp) {
114+
$this->guard()->login($user);
115+
}
116+
117+
$this->hasTwoFactor = $user->use_totp;
118+
}
119+
52120
/**
53121
* Send a successful password reset response back to the callee.
54122
*
@@ -59,6 +127,7 @@ protected function sendResetResponse(): JsonResponse
59127
return response()->json([
60128
'success' => true,
61129
'redirect_to' => $this->redirectTo,
130+
'send_to_login' => $this->hasTwoFactor,
62131
]);
63132
}
64133
}

0 commit comments

Comments
 (0)