Skip to content

Commit 4b0197f

Browse files
committed
Implement basic security policy on daemon remote routes
1 parent 9087fee commit 4b0197f

File tree

5 files changed

+74
-6
lines changed

5 files changed

+74
-6
lines changed

app/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class Kernel extends HttpKernel
5151
'guest' => \Pterodactyl\Http\Middleware\RedirectIfAuthenticated::class,
5252
'server' => \Pterodactyl\Http\Middleware\CheckServer::class,
5353
'admin' => \Pterodactyl\Http\Middleware\AdminAuthenticate::class,
54+
'daemon' => \Pterodactyl\Http\Middleware\DaemonAuthenticate::class,
5455
'csrf' => \Pterodactyl\Http\Middleware\VerifyCsrfToken::class,
5556
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
5657
'can' => \Illuminate\Auth\Middleware\Authorize::class,
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
/**
3+
* Pterodactyl - Panel
4+
* Copyright (c) 2015 - 2017 Dane Everitt <dane@daneeveritt.com>.
5+
*
6+
* Permission is hereby granted, free of charge, to any person obtaining a copy
7+
* of this software and associated documentation files (the "Software"), to deal
8+
* in the Software without restriction, including without limitation the rights
9+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
* copies of the Software, and to permit persons to whom the Software is
11+
* furnished to do so, subject to the following conditions:
12+
*
13+
* The above copyright notice and this permission notice shall be included in all
14+
* copies or substantial portions of the Software.
15+
*
16+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
* SOFTWARE.
23+
*/
24+
25+
namespace Pterodactyl\Http\Middleware;
26+
27+
use Closure;
28+
use Pterodactyl\Models\Node;
29+
use Illuminate\Contracts\Auth\Guard;
30+
31+
class DaemonAuthenticate
32+
{
33+
/**
34+
* The Guard implementation.
35+
*
36+
* @var Guard
37+
*/
38+
protected $auth;
39+
40+
/**
41+
* Create a new filter instance.
42+
*
43+
* @param Guard $auth
44+
* @return void
45+
*/
46+
public function __construct(Guard $auth)
47+
{
48+
$this->auth = $auth;
49+
}
50+
51+
/**
52+
* Handle an incoming request.
53+
*
54+
* @param \Illuminate\Http\Request $request
55+
* @param \Closure $next
56+
* @return mixed
57+
*/
58+
public function handle($request, Closure $next)
59+
{
60+
if (! $request->header('X-Access-Node')) {
61+
return abort(403);
62+
}
63+
64+
$node = Node::where('daemonSecret', $request->header('X-Access-Node'))->first();
65+
if (! $node) {
66+
return abort(404);
67+
}
68+
69+
return $next($request);
70+
}
71+
}

app/Http/Middleware/VerifyCsrfToken.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class VerifyCsrfToken extends BaseVerifier
1313
*/
1414
protected $except = [
1515
'remote/*',
16+
'daemon/*',
1617
'api/*',
1718
];
1819
}

app/Http/Routes/DaemonRoutes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class DaemonRoutes
3030
{
3131
public function map(Router $router)
3232
{
33-
$router->group(['prefix' => 'daemon'], function () use ($router) {
33+
$router->group(['prefix' => 'daemon', 'middleware' => 'daemon'], function () use ($router) {
3434
$router->get('services', [
3535
'as' => 'daemon.services',
3636
'uses' => 'Daemon\ServiceController@list',

app/Http/Routes/RemoteRoutes.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@ public function map(Router $router)
4242
'uses' => 'Remote\RemoteController@postInstall',
4343
]);
4444

45-
$router->post('event', [
46-
'as' => 'remote.event',
47-
'uses' => 'Remote\RemoteController@event',
48-
]);
49-
5045
$router->get('configuration/{token}', [
5146
'as' => 'remote.configuration',
5247
'uses' => 'Remote\RemoteController@getConfiguration',

0 commit comments

Comments
 (0)