Skip to content

Commit 6618a12

Browse files
committed
Merge branch 'feature/react' into develop
2 parents 905ae55 + e69d55e commit 6618a12

File tree

148 files changed

+3111
-6268
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3111
-6268
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ node_modules
1212
_ide_helper.php
1313
.phpstorm.meta.php
1414
.php_cs.cache
15-
public/assets/*
15+
public/assets/manifest.json
1616

1717
# For local development with docker
1818
# Remove if we ever put the Dockerfile in the repo

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,21 @@ 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.14 (Derelict Dermodactylus)
7+
### Fixed
8+
* **[SECURITY]** Fixes an XSS vulnerability when performing certain actions in the file manager.
9+
* **[SECURITY]** Attempting to login as a user who has 2FA enabled will no longer request the 2FA token before validating
10+
that their password is correct. This closes a user existence leak that would expose that an account exists if
11+
it had 2FA enabled.
12+
13+
### Changed
14+
* Support for setting a node to listen on ports lower than 1024.
15+
* QR code URLs are now generated without the use of an external library to reduce the dependency tree.
16+
* Regenerated database passwords now respect the same settings that were used when initially created.
17+
* Cleaned up 2FA QR code generation to use a more up-to-date library and API.
18+
* Console charts now properly start at 0 and scale based on server configuration. No more crazy spikes that
19+
are due to a change of one unit.
20+
621
## v0.7.13 (Derelict Dermodactylus)
722
### Fixed
823
* Fixes a bug with the location update API endpoint throwing an error due to an unexected response value.

app/Http/Controllers/Auth/AbstractLoginController.php

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,45 +6,17 @@
66
use Pterodactyl\Models\User;
77
use Illuminate\Auth\AuthManager;
88
use Illuminate\Http\JsonResponse;
9-
use PragmaRX\Google2FA\Google2FA;
109
use Illuminate\Auth\Events\Failed;
10+
use Illuminate\Contracts\Config\Repository;
1111
use Pterodactyl\Exceptions\DisplayException;
1212
use Pterodactyl\Http\Controllers\Controller;
1313
use Illuminate\Contracts\Auth\Authenticatable;
14-
use Illuminate\Contracts\Encryption\Encrypter;
1514
use Illuminate\Foundation\Auth\AuthenticatesUsers;
16-
use Illuminate\Contracts\Cache\Repository as CacheRepository;
17-
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1815

1916
abstract class AbstractLoginController extends Controller
2017
{
2118
use AuthenticatesUsers;
2219

23-
/**
24-
* @var \Illuminate\Auth\AuthManager
25-
*/
26-
protected $auth;
27-
28-
/**
29-
* @var \Illuminate\Contracts\Cache\Repository
30-
*/
31-
protected $cache;
32-
33-
/**
34-
* @var \Illuminate\Contracts\Encryption\Encrypter
35-
*/
36-
protected $encrypter;
37-
38-
/**
39-
* @var \PragmaRX\Google2FA\Google2FA
40-
*/
41-
protected $google2FA;
42-
43-
/**
44-
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
45-
*/
46-
protected $repository;
47-
4820
/**
4921
* Lockout time for failed login requests.
5022
*
@@ -66,30 +38,29 @@ abstract class AbstractLoginController extends Controller
6638
*/
6739
protected $redirectTo = '/';
6840

41+
/**
42+
* @var \Illuminate\Auth\AuthManager
43+
*/
44+
protected $auth;
45+
46+
/**
47+
* @var \Illuminate\Contracts\Config\Repository
48+
*/
49+
protected $config;
50+
6951
/**
7052
* LoginController constructor.
7153
*
72-
* @param \Illuminate\Auth\AuthManager $auth
73-
* @param \Illuminate\Contracts\Cache\Repository $cache
74-
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
75-
* @param \PragmaRX\Google2FA\Google2FA $google2FA
76-
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
54+
* @param \Illuminate\Auth\AuthManager $auth
55+
* @param \Illuminate\Contracts\Config\Repository $config
7756
*/
78-
public function __construct(
79-
AuthManager $auth,
80-
CacheRepository $cache,
81-
Encrypter $encrypter,
82-
Google2FA $google2FA,
83-
UserRepositoryInterface $repository
84-
) {
85-
$this->auth = $auth;
86-
$this->cache = $cache;
87-
$this->encrypter = $encrypter;
88-
$this->google2FA = $google2FA;
89-
$this->repository = $repository;
57+
public function __construct(AuthManager $auth, Repository $config)
58+
{
59+
$this->lockoutTime = $config->get('auth.lockout.time');
60+
$this->maxLoginAttempts = $config->get('auth.lockout.attempts');
9061

91-
$this->lockoutTime = config('auth.lockout.time');
92-
$this->maxLoginAttempts = config('auth.lockout.attempts');
62+
$this->auth = $auth;
63+
$this->config = $config;
9364
}
9465

9566
/**
@@ -128,10 +99,12 @@ protected function sendLoginResponse(User $user, Request $request): JsonResponse
12899

129100
$this->auth->guard()->login($user, true);
130101

131-
return response()->json([
132-
'complete' => true,
133-
'intended' => $this->redirectPath(),
134-
'user' => $user->toVueObject(),
102+
return JsonResponse::create([
103+
'data' => [
104+
'complete' => true,
105+
'intended' => $this->redirectPath(),
106+
'user' => $user->toVueObject(),
107+
],
135108
]);
136109
}
137110

app/Http/Controllers/Auth/ForgotPasswordController.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,11 @@ protected function sendResetLinkFailedResponse(Request $request, $response): Jso
3333
/**
3434
* Get the response for a successful password reset link.
3535
*
36-
* @param string $response
36+
* @param \Illuminate\Http\Request $request
37+
* @param string $response
3738
* @return \Illuminate\Http\JsonResponse
3839
*/
39-
protected function sendResetLinkResponse($response): JsonResponse
40+
protected function sendResetLinkResponse(Request $request, $response): JsonResponse
4041
{
4142
return response()->json([
4243
'status' => trans($response),

app/Http/Controllers/Auth/LoginCheckpointController.php

Lines changed: 63 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,64 @@
22

33
namespace Pterodactyl\Http\Controllers\Auth;
44

5+
use Illuminate\Auth\AuthManager;
56
use Illuminate\Http\JsonResponse;
7+
use PragmaRX\Google2FA\Google2FA;
8+
use Illuminate\Contracts\Config\Repository;
9+
use Illuminate\Contracts\Encryption\Encrypter;
610
use Pterodactyl\Http\Requests\Auth\LoginCheckpointRequest;
11+
use Illuminate\Contracts\Cache\Repository as CacheRepository;
12+
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
713
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
814

915
class LoginCheckpointController extends AbstractLoginController
1016
{
17+
/**
18+
* @var \Illuminate\Contracts\Cache\Repository
19+
*/
20+
private $cache;
21+
22+
/**
23+
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
24+
*/
25+
private $repository;
26+
27+
/**
28+
* @var \PragmaRX\Google2FA\Google2FA
29+
*/
30+
private $google2FA;
31+
32+
/**
33+
* @var \Illuminate\Contracts\Encryption\Encrypter
34+
*/
35+
private $encrypter;
36+
37+
/**
38+
* LoginCheckpointController constructor.
39+
*
40+
* @param \Illuminate\Auth\AuthManager $auth
41+
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
42+
* @param \PragmaRX\Google2FA\Google2FA $google2FA
43+
* @param \Illuminate\Contracts\Config\Repository $config
44+
* @param \Illuminate\Contracts\Cache\Repository $cache
45+
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
46+
*/
47+
public function __construct(
48+
AuthManager $auth,
49+
Encrypter $encrypter,
50+
Google2FA $google2FA,
51+
Repository $config,
52+
CacheRepository $cache,
53+
UserRepositoryInterface $repository
54+
) {
55+
parent::__construct($auth, $config);
56+
57+
$this->google2FA = $google2FA;
58+
$this->cache = $cache;
59+
$this->repository = $repository;
60+
$this->encrypter = $encrypter;
61+
}
62+
1163
/**
1264
* Handle a login where the user is required to provide a TOTP authentication
1365
* token. Once a user has reached this stage it is assumed that they have already
@@ -16,29 +68,28 @@ class LoginCheckpointController extends AbstractLoginController
1668
* @param \Pterodactyl\Http\Requests\Auth\LoginCheckpointRequest $request
1769
* @return \Illuminate\Http\JsonResponse
1870
*
71+
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
72+
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
73+
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
1974
* @throws \Pterodactyl\Exceptions\DisplayException
2075
*/
2176
public function __invoke(LoginCheckpointRequest $request): JsonResponse
2277
{
2378
try {
24-
$cache = $this->cache->pull($request->input('confirmation_token'), []);
25-
$user = $this->repository->find(array_get($cache, 'user_id', 0));
79+
$user = $this->repository->find(
80+
$this->cache->pull($request->input('confirmation_token'), 0)
81+
);
2682
} catch (RecordNotFoundException $exception) {
2783
return $this->sendFailedLoginResponse($request);
2884
}
2985

30-
if (array_get($cache, 'request_ip') !== $request->ip()) {
31-
return $this->sendFailedLoginResponse($request, $user);
32-
}
86+
$decrypted = $this->encrypter->decrypt($user->totp_secret);
87+
$window = $this->config->get('pterodactyl.auth.2fa.window');
3388

34-
if (! $this->google2FA->verifyKey(
35-
$this->encrypter->decrypt($user->totp_secret),
36-
$request->input('authentication_code'),
37-
config('pterodactyl.auth.2fa.window')
38-
)) {
39-
return $this->sendFailedLoginResponse($request, $user);
89+
if ($this->google2FA->verifyKey($decrypted, $request->input('authentication_code'), $window)) {
90+
return $this->sendLoginResponse($user, $request);
4091
}
4192

42-
return $this->sendLoginResponse($user, $request);
93+
return $this->sendFailedLoginResponse($request, $user);
4394
}
4495
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,57 @@
22

33
namespace Pterodactyl\Http\Controllers\Auth;
44

5+
use Illuminate\Support\Str;
56
use Illuminate\Http\Request;
7+
use Illuminate\Auth\AuthManager;
68
use Illuminate\Http\JsonResponse;
79
use Illuminate\Contracts\View\View;
10+
use Illuminate\Contracts\Config\Repository;
11+
use Illuminate\Contracts\View\Factory as ViewFactory;
12+
use Illuminate\Contracts\Cache\Repository as CacheRepository;
13+
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
814
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
915

1016
class LoginController extends AbstractLoginController
1117
{
18+
/**
19+
* @var \Illuminate\Contracts\View\Factory
20+
*/
21+
private $view;
22+
23+
/**
24+
* @var \Illuminate\Contracts\Cache\Repository
25+
*/
26+
private $cache;
27+
28+
/**
29+
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
30+
*/
31+
private $repository;
32+
33+
/**
34+
* LoginController constructor.
35+
*
36+
* @param \Illuminate\Auth\AuthManager $auth
37+
* @param \Illuminate\Contracts\Config\Repository $config
38+
* @param \Illuminate\Contracts\Cache\Repository $cache
39+
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
40+
* @param \Illuminate\Contracts\View\Factory $view
41+
*/
42+
public function __construct(
43+
AuthManager $auth,
44+
Repository $config,
45+
CacheRepository $cache,
46+
UserRepositoryInterface $repository,
47+
ViewFactory $view
48+
) {
49+
parent::__construct($auth, $config);
50+
51+
$this->view = $view;
52+
$this->cache = $cache;
53+
$this->repository = $repository;
54+
}
55+
1256
/**
1357
* Handle all incoming requests for the authentication routes and render the
1458
* base authentication view component. Vuejs will take over at this point and
@@ -18,7 +62,7 @@ class LoginController extends AbstractLoginController
1862
*/
1963
public function index(): View
2064
{
21-
return view('templates/auth.core');
65+
return $this->view->make('templates/auth.core');
2266
}
2367

2468
/**
@@ -54,21 +98,20 @@ public function login(Request $request): JsonResponse
5498
return $this->sendFailedLoginResponse($request, $user);
5599
}
56100

57-
// If the user is using 2FA we do not actually log them in at this step, we return
58-
// a one-time token to link the 2FA credentials to this account via the UI.
59101
if ($user->use_totp) {
60-
$token = str_random(128);
61-
$this->cache->put($token, [
62-
'user_id' => $user->id,
63-
'request_ip' => $request->ip(),
64-
], 5);
65-
66-
return response()->json([
67-
'complete' => false,
68-
'login_token' => $token,
102+
$token = Str::random(64);
103+
$this->cache->put($token, $user->id, 5);
104+
105+
return JsonResponse::create([
106+
'data' => [
107+
'complete' => false,
108+
'confirmation_token' => $token,
109+
],
69110
]);
70111
}
71112

113+
$this->auth->guard()->login($user, true);
114+
72115
return $this->sendLoginResponse($user, $request);
73116
}
74117
}

app/Http/Controllers/Base/SecurityController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ public function index(Request $request): JsonResponse
8383

8484
return JsonResponse::create([
8585
'enabled' => false,
86-
'qr_image' => $response->get('image'),
87-
'secret' => $response->get('secret'),
86+
'qr_image' => $response,
87+
'secret' => '',
8888
]);
8989
}
9090

app/Http/Requests/Auth/LoginCheckpointRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function rules(): array
2525
{
2626
return [
2727
'confirmation_token' => 'required|string',
28-
'authentication_code' => 'required|int',
28+
'authentication_code' => 'required|numeric',
2929
];
3030
}
3131
}

0 commit comments

Comments
 (0)