Skip to content

Commit c9ad4ea

Browse files
authored
Merge branch 'develop' into issues/1902
2 parents c46ece0 + 7557ddd commit c9ad4ea

File tree

57 files changed

+600
-1099
lines changed

Some content is hidden

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

57 files changed

+600
-1099
lines changed

app/Http/Controllers/Admin/Nodes/NodeViewController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ public function allocations(Request $request, Node $node)
148148
public function servers(Request $request, Node $node)
149149
{
150150
$this->plainInject([
151-
'node' => Collection::wrap($node->makeVisible('daemonSecret'))
152-
->only(['scheme', 'fqdn', 'daemonListen', 'daemonSecret']),
151+
'node' => Collection::wrap($node->makeVisible(['daemon_token_id', 'daemon_token']))
152+
->only(['scheme', 'fqdn', 'daemonListen', 'daemon_token_id', 'daemon_token']),
153153
]);
154154

155155
return $this->view->make('admin.nodes.view.servers', [

app/Http/Controllers/Admin/StatisticsController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function index()
6767

6868
$tokens = [];
6969
foreach ($nodes as $node) {
70-
$tokens[$node->id] = $node->daemonSecret;
70+
$tokens[$node->id] = decrypt($node->daemon_token);
7171
}
7272

7373
$this->injectJavascript([

app/Http/Controllers/Api/Remote/Servers/ServerTransferController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function archive(Request $request, string $uuid)
145145
->canOnlyBeUsedAfter($now->getTimestamp())
146146
->expiresAt($now->addMinutes(15)->getTimestamp())
147147
->relatedTo($server->uuid, true)
148-
->getToken($signer, new Key($server->node->daemonSecret));
148+
->getToken($signer, new Key($server->node->getDecryptedKey()));
149149

150150
// On the daemon transfer repository, make sure to set the node after the server
151151
// because setServer() tells the repository to use the server's node and not the one

app/Http/Controllers/Daemon/ActionController.php

Lines changed: 0 additions & 107 deletions
This file was deleted.

app/Http/Controllers/Daemon/PackController.php

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/Http/Kernel.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
use Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull;
3939
use Pterodactyl\Http\Middleware\Api\Client\SubstituteClientApiBindings;
4040
use Pterodactyl\Http\Middleware\Api\Application\AuthenticateApplicationUser;
41-
use Pterodactyl\Http\Middleware\DaemonAuthenticate as OldDaemonAuthenticate;
4241

4342
class Kernel extends HttpKernel
4443
{
@@ -107,7 +106,6 @@ class Kernel extends HttpKernel
107106
'server' => AccessingValidServer::class,
108107
'subuser.auth' => AuthenticateAsSubuser::class,
109108
'admin' => AdminAuthenticate::class,
110-
'daemon-old' => OldDaemonAuthenticate::class,
111109
'csrf' => VerifyCsrfToken::class,
112110
'throttle' => ThrottleRequests::class,
113111
'can' => Authorize::class,

app/Http/Middleware/Api/Daemon/DaemonAuthenticate.php

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Illuminate\Http\Request;
7+
use Illuminate\Contracts\Encryption\Encrypter;
78
use Symfony\Component\HttpKernel\Exception\HttpException;
89
use Pterodactyl\Contracts\Repository\NodeRepositoryInterface;
910
use Pterodactyl\Exceptions\Repository\RecordNotFoundException;
@@ -25,14 +26,21 @@ class DaemonAuthenticate
2526
'daemon.configuration',
2627
];
2728

29+
/**
30+
* @var \Illuminate\Contracts\Encryption\Encrypter
31+
*/
32+
private $encrypter;
33+
2834
/**
2935
* DaemonAuthenticate constructor.
3036
*
37+
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
3138
* @param \Pterodactyl\Contracts\Repository\NodeRepositoryInterface $repository
3239
*/
33-
public function __construct(NodeRepositoryInterface $repository)
40+
public function __construct(Encrypter $encrypter, NodeRepositoryInterface $repository)
3441
{
3542
$this->repository = $repository;
43+
$this->encrypter = $encrypter;
3644
}
3745

3846
/**
@@ -50,20 +58,31 @@ public function handle(Request $request, Closure $next)
5058
return $next($request);
5159
}
5260

53-
$token = $request->bearerToken();
54-
55-
if (is_null($token)) {
56-
throw new HttpException(401, null, null, ['WWW-Authenticate' => 'Bearer']);
61+
if (is_null($bearer = $request->bearerToken())) {
62+
throw new HttpException(
63+
401, 'Access this this endpoint must include an Authorization header.', null, ['WWW-Authenticate' => 'Bearer']
64+
);
5765
}
5866

67+
[$identifier, $token] = explode('.', $bearer);
68+
5969
try {
60-
$node = $this->repository->findFirstWhere([['daemonSecret', '=', $token]]);
70+
/** @var \Pterodactyl\Models\Node $node */
71+
$node = $this->repository->findFirstWhere([
72+
'daemon_token_id' => $identifier,
73+
]);
74+
75+
if (hash_equals((string) $this->encrypter->decrypt($node->daemon_token), $token)) {
76+
$request->attributes->set('node', $node);
77+
78+
return $next($request);
79+
}
6180
} catch (RecordNotFoundException $exception) {
62-
throw new AccessDeniedHttpException;
81+
// Do nothing, we don't want to expose a node not existing at all.
6382
}
6483

65-
$request->attributes->set('node', $node);
66-
67-
return $next($request);
84+
throw new AccessDeniedHttpException(
85+
'You are not authorized to access this resource.'
86+
);
6887
}
6988
}

app/Http/Middleware/DaemonAuthenticate.php

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)