Skip to content

Commit 81f1796

Browse files
committed
Merge branch 'release/v0.7.9'
2 parents 28442ce + 8341cdb commit 81f1796

File tree

4 files changed

+98
-2
lines changed

4 files changed

+98
-2
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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@
22

33
namespace Pterodactyl\Http\Controllers\Auth;
44

5+
use Illuminate\Support\Str;
6+
use Prologue\Alerts\AlertsMessageBag;
7+
use Illuminate\Contracts\Hashing\Hasher;
8+
use Illuminate\Auth\Events\PasswordReset;
9+
use Illuminate\Contracts\Events\Dispatcher;
510
use Pterodactyl\Http\Controllers\Controller;
611
use Illuminate\Foundation\Auth\ResetsPasswords;
12+
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
713

814
class ResetPasswordController extends Controller
915
{
@@ -16,6 +22,47 @@ class ResetPasswordController extends Controller
1622
*/
1723
public $redirectTo = '/';
1824

25+
/**
26+
* @var bool
27+
*/
28+
protected $hasTwoFactor = false;
29+
30+
/**
31+
* @var \Prologue\Alerts\AlertsMessageBag
32+
*/
33+
private $alerts;
34+
35+
/**
36+
* @var \Illuminate\Contracts\Events\Dispatcher
37+
*/
38+
private $dispatcher;
39+
40+
/**
41+
* @var \Illuminate\Contracts\Hashing\Hasher
42+
*/
43+
private $hasher;
44+
45+
/**
46+
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
47+
*/
48+
private $userRepository;
49+
50+
/**
51+
* ResetPasswordController constructor.
52+
*
53+
* @param \Prologue\Alerts\AlertsMessageBag $alerts
54+
* @param \Illuminate\Contracts\Events\Dispatcher $dispatcher
55+
* @param \Illuminate\Contracts\Hashing\Hasher $hasher
56+
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $userRepository
57+
*/
58+
public function __construct(AlertsMessageBag $alerts, Dispatcher $dispatcher, Hasher $hasher, UserRepositoryInterface $userRepository)
59+
{
60+
$this->alerts = $alerts;
61+
$this->dispatcher = $dispatcher;
62+
$this->hasher = $hasher;
63+
$this->userRepository = $userRepository;
64+
}
65+
1966
/**
2067
* Return the rules used when validating password reset.
2168
*
@@ -29,4 +76,49 @@ protected function rules(): array
2976
'password' => 'required|confirmed|min:8',
3077
];
3178
}
79+
80+
/**
81+
* Reset the given user's password. If the user has two-factor authentication enabled on their
82+
* account do not automatically log them in. In those cases, send the user back to the login
83+
* form with a note telling them their password was changed and to log back in.
84+
*
85+
* @param \Illuminate\Contracts\Auth\CanResetPassword|\Pterodactyl\Models\User $user
86+
* @param string $password
87+
*
88+
* @throws \Pterodactyl\Exceptions\Model\DataValidationException
89+
* @throws \Pterodactyl\Exceptions\Repository\RecordNotFoundException
90+
*/
91+
protected function resetPassword($user, $password)
92+
{
93+
$user = $this->userRepository->update($user->id, [
94+
'password' => $this->hasher->make($password),
95+
$user->getRememberTokenName() => Str::random(60),
96+
]);
97+
98+
$this->dispatcher->dispatch(new PasswordReset($user));
99+
100+
// If the user is not using 2FA log them in, otherwise skip this step and force a
101+
// fresh login where they'll be prompted to enter a token.
102+
if (! $user->use_totp) {
103+
$this->guard()->login($user);
104+
}
105+
106+
$this->hasTwoFactor = $user->use_totp;
107+
}
108+
109+
/**
110+
* Get the response for a successful password reset.
111+
*
112+
* @param string $response
113+
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\JsonResponse
114+
*/
115+
protected function sendResetResponse($response)
116+
{
117+
if ($this->hasTwoFactor) {
118+
$this->alerts->success('Your password was successfully updated. Please log in to continue.')->flash();
119+
}
120+
121+
return redirect($this->hasTwoFactor ? route('auth.login') : $this->redirectPath())
122+
->with('status', trans($response));
123+
}
32124
}

config/app.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| change this value if you are not maintaining your own internal versions.
1010
*/
1111

12-
'version' => '0.7.8',
12+
'version' => '0.7.9',
1313

1414
/*
1515
|--------------------------------------------------------------------------

resources/lang/de/strings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
'select_none' => 'Alles abwählen',
4949
'alias' => 'Alias',
5050
'primary' => 'Primär',
51-
'make_primary' => 'Primät machen',
51+
'make_primary' => 'Primär machen',
5252
'none' => 'Nichts',
5353
'cancel' => 'Abbrechen',
5454
'created_at' => 'Erstellt am',

0 commit comments

Comments
 (0)