Skip to content

Commit c741a1e

Browse files
committed
Merge branch 'release/v0.7.14'
2 parents aae67a8 + c38f78d commit c741a1e

File tree

23 files changed

+144
-84
lines changed

23 files changed

+144
-84
lines changed

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.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Logo Image](https://cdn.pterodactyl.io/logos/Banner%20Logo%20Black@2x.png)](https://pterodactyl.io)
1+
[![Logo Image](https://cdn.pterodactyl.io/logos/new/pterodactyl_logo.png)](https://pterodactyl.io)
22

33
[![Build status](https://img.shields.io/travis/pterodactyl/panel/develop.svg?style=flat-square)](https://travis-ci.org/pterodactyl/panel)
44
[![StyleCI](https://styleci.io/repos/47508644/shield?branch=develop)](https://styleci.io/repos/47508644)

app/Http/Controllers/Admin/ServersController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ public function resetDatabasePassword(Request $request, $server)
599599
['id', '=', $request->input('database')],
600600
]);
601601

602-
$this->databasePasswordService->handle($database, str_random(20));
602+
$this->databasePasswordService->handle($database, str_random(24));
603603

604604
return response('', 204);
605605
}

app/Http/Controllers/Auth/LoginController.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,21 +126,20 @@ public function login(Request $request)
126126
return $this->sendFailedLoginResponse($request);
127127
}
128128

129-
$validCredentials = password_verify($request->input('password'), $user->password);
129+
if (! password_verify($request->input('password'), $user->password)) {
130+
return $this->sendFailedLoginResponse($request, $user);
131+
}
132+
130133
if ($user->use_totp) {
131134
$token = str_random(64);
132-
$this->cache->put($token, ['user_id' => $user->id, 'valid_credentials' => $validCredentials], 5);
135+
$this->cache->put($token, ['user_id' => $user->id, 'valid_credentials' => true], 5);
133136

134137
return redirect()->route('auth.totp')->with('authentication_token', $token);
135138
}
136139

137-
if ($validCredentials) {
138-
$this->auth->guard()->login($user, true);
139-
140-
return $this->sendLoginResponse($request);
141-
}
140+
$this->auth->guard()->login($user, true);
142141

143-
return $this->sendFailedLoginResponse($request, $user);
142+
return $this->sendLoginResponse($request);
144143
}
145144

146145
/**
@@ -161,12 +160,13 @@ public function totp(Request $request)
161160

162161
/**
163162
* Handle a login where the user is required to provide a TOTP authentication
164-
* token. In order to add additional layers of security, users are not
165-
* informed of an incorrect password until this stage, forcing them to
166-
* provide a token on each login attempt.
163+
* token.
167164
*
168165
* @param \Illuminate\Http\Request $request
169166
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Http\Response
167+
* @throws \PragmaRX\Google2FA\Exceptions\IncompatibleWithGoogleAuthenticatorException
168+
* @throws \PragmaRX\Google2FA\Exceptions\InvalidCharactersException
169+
* @throws \PragmaRX\Google2FA\Exceptions\SecretKeyTooShortException
170170
*/
171171
public function loginUsingTotp(Request $request)
172172
{
@@ -181,7 +181,7 @@ public function loginUsingTotp(Request $request)
181181
return $this->sendFailedLoginResponse($request);
182182
}
183183

184-
if (is_null($request->input('2fa_token')) || ! array_get($cache, 'valid_credentials')) {
184+
if (is_null($request->input('2fa_token'))) {
185185
return $this->sendFailedLoginResponse($request, $user);
186186
}
187187

app/Http/Controllers/Base/SecurityController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ public function index(Request $request)
9090
*/
9191
public function generateTotp(Request $request)
9292
{
93+
$totpData = $this->twoFactorSetupService->handle($request->user());
94+
9395
return response()->json([
94-
'qrImage' => $this->twoFactorSetupService->handle($request->user()),
96+
'qrImage' => 'https://api.qrserver.com/v1/create-qr-code/?size=200x200&data=' . $totpData,
9597
]);
9698
}
9799

app/Http/Controllers/Server/DatabaseController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function update(Request $request): JsonResponse
142142
{
143143
$this->authorize('reset-db-password', $request->attributes->get('server'));
144144

145-
$password = str_random(20);
145+
$password = str_random(24);
146146
$this->passwordService->handle($request->attributes->get('database'), $password);
147147

148148
return response()->json(['password' => $password]);

app/Models/Node.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ class Node extends Model implements CleansAttributes, ValidableContract
110110
'disk' => 'numeric|min:1',
111111
'disk_overallocate' => 'numeric|min:-1',
112112
'daemonBase' => 'regex:/^([\/][\d\w.\-\/]+)$/',
113-
'daemonSFTP' => 'numeric|between:1024,65535',
114-
'daemonListen' => 'numeric|between:1024,65535',
113+
'daemonSFTP' => 'numeric|between:1,65535',
114+
'daemonListen' => 'numeric|between:1,65535',
115115
'maintenance_mode' => 'boolean',
116116
'upload_size' => 'int|between:1,1024',
117117
];

app/Services/Databases/DatabaseManagementService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function create($server, array $data)
6969
$data['server_id'] = $server;
7070
$data['database'] = sprintf('s%d_%s', $server, $data['database']);
7171
$data['username'] = sprintf('u%d_%s', $server, str_random(10));
72-
$data['password'] = $this->encrypter->encrypt(str_random(16));
72+
$data['password'] = $this->encrypter->encrypt(str_random(24));
7373

7474
$this->database->beginTransaction();
7575
try {
Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,18 @@
11
<?php
2-
/**
3-
* Pterodactyl - Panel
4-
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5-
*
6-
* This software is licensed under the terms of the MIT license.
7-
* https://opensource.org/licenses/MIT
8-
*/
92

103
namespace Pterodactyl\Services\Users;
114

5+
use Exception;
6+
use RuntimeException;
127
use Pterodactyl\Models\User;
13-
use PragmaRX\Google2FA\Google2FA;
148
use Illuminate\Contracts\Encryption\Encrypter;
159
use Pterodactyl\Contracts\Repository\UserRepositoryInterface;
1610
use Illuminate\Contracts\Config\Repository as ConfigRepository;
1711

1812
class TwoFactorSetupService
1913
{
14+
const VALID_BASE32_CHARACTERS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
15+
2016
/**
2117
* @var \Illuminate\Contracts\Config\Repository
2218
*/
@@ -27,11 +23,6 @@ class TwoFactorSetupService
2723
*/
2824
private $encrypter;
2925

30-
/**
31-
* @var \PragmaRX\Google2FA\Google2FA
32-
*/
33-
private $google2FA;
34-
3526
/**
3627
* @var \Pterodactyl\Contracts\Repository\UserRepositoryInterface
3728
*/
@@ -42,24 +33,22 @@ class TwoFactorSetupService
4233
*
4334
* @param \Illuminate\Contracts\Config\Repository $config
4435
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
45-
* @param \PragmaRX\Google2FA\Google2FA $google2FA
4636
* @param \Pterodactyl\Contracts\Repository\UserRepositoryInterface $repository
4737
*/
4838
public function __construct(
4939
ConfigRepository $config,
5040
Encrypter $encrypter,
51-
Google2FA $google2FA,
5241
UserRepositoryInterface $repository
5342
) {
5443
$this->config = $config;
5544
$this->encrypter = $encrypter;
56-
$this->google2FA = $google2FA;
5745
$this->repository = $repository;
5846
}
5947

6048
/**
6149
* Generate a 2FA token and store it in the database before returning the
62-
* QR code image.
50+
* QR code URL. This URL will need to be attached to a QR generating service in
51+
* order to function.
6352
*
6453
* @param \Pterodactyl\Models\User $user
6554
* @return string
@@ -69,13 +58,26 @@ public function __construct(
6958
*/
7059
public function handle(User $user): string
7160
{
72-
$secret = $this->google2FA->generateSecretKey($this->config->get('pterodactyl.auth.2fa.bytes'));
73-
$image = $this->google2FA->getQRCodeGoogleUrl($this->config->get('app.name'), $user->email, $secret);
61+
$secret = '';
62+
try {
63+
for ($i = 0; $i < $this->config->get('pterodactyl.auth.2fa.bytes', 16); $i++) {
64+
$secret .= substr(self::VALID_BASE32_CHARACTERS, random_int(0, 31), 1);
65+
}
66+
} catch (Exception $exception) {
67+
throw new RuntimeException($exception->getMessage(), 0, $exception);
68+
}
7469

7570
$this->repository->withoutFreshModel()->update($user->id, [
7671
'totp_secret' => $this->encrypter->encrypt($secret),
7772
]);
7873

79-
return $image;
74+
$company = $this->config->get('app.name');
75+
76+
return sprintf(
77+
'otpauth://totp/%1$s:%2$s?secret=%3$s&issuer=%1$s',
78+
rawurlencode($company),
79+
rawurlencode($user->email),
80+
rawurlencode($secret)
81+
);
8082
}
8183
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"lord/laroute": "^2.4",
3030
"matriphe/iso-639": "^1.2",
3131
"nesbot/carbon": "^1.22",
32-
"pragmarx/google2fa": "^2.0",
32+
"pragmarx/google2fa": "^5.0",
3333
"predis/predis": "^1.1",
3434
"prologue/alerts": "^0.4",
3535
"ramsey/uuid": "^3.7",

0 commit comments

Comments
 (0)