Skip to content

Commit 2182a15

Browse files
committed
Don't return variables to users that they should not be able to see; closes pterodactyl#2388
1 parent 7968258 commit 2182a15

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

app/Http/Controllers/Api/Client/Servers/StartupController.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@
22

33
namespace Pterodactyl\Http\Controllers\Api\Client\Servers;
44

5-
use Carbon\CarbonImmutable;
65
use Pterodactyl\Models\Server;
7-
use Illuminate\Http\JsonResponse;
86
use Pterodactyl\Services\Servers\StartupCommandService;
97
use Pterodactyl\Services\Servers\VariableValidatorService;
108
use Pterodactyl\Repositories\Eloquent\ServerVariableRepository;
119
use Pterodactyl\Transformers\Api\Client\EggVariableTransformer;
1210
use Pterodactyl\Http\Controllers\Api\Client\ClientApiController;
13-
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1411
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1512
use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\GetStartupRequest;
1613
use Pterodactyl\Http\Requests\Api\Client\Servers\Startup\UpdateStartupVariableRequest;
@@ -59,7 +56,9 @@ public function index(GetStartupRequest $request, Server $server)
5956
{
6057
$startup = $this->startupCommandService->handle($server, false);
6158

62-
return $this->fractal->collection($server->variables)
59+
return $this->fractal->collection(
60+
$server->variables()->where('user_viewable', true)->get()
61+
)
6362
->transformWith($this->getTransformer(EggVariableTransformer::class))
6463
->addMeta([
6564
'startup_command' => $startup,
@@ -84,7 +83,7 @@ public function update(UpdateStartupVariableRequest $request, Server $server)
8483
/** @var \Pterodactyl\Models\EggVariable $variable */
8584
$variable = $server->variables()->where('env_variable', $request->input('key'))->first();
8685

87-
if (is_null($variable) || !$variable->user_viewable) {
86+
if (is_null($variable) || ! $variable->user_viewable) {
8887
throw new BadRequestHttpException(
8988
"The environment variable you are trying to edit does not exist."
9089
);

app/Transformers/Api/Client/EggVariableTransformer.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Pterodactyl\Transformers\Api\Client;
44

5+
use BadMethodCallException;
6+
use InvalidArgumentException;
57
use Pterodactyl\Models\EggVariable;
68

79
class EggVariableTransformer extends BaseClientTransformer
@@ -20,6 +22,15 @@ public function getResourceName(): string
2022
*/
2123
public function transform(EggVariable $variable)
2224
{
25+
// This guards against someone incorrectly retrieving variables (haha, me) and then passing
26+
// them into the transformer and along to the user. Just throw an exception and break the entire
27+
// pathway since you should never be exposing these types of variables to a client.
28+
if (!$variable->user_viewable) {
29+
throw new BadMethodCallException(
30+
'Cannot transform a hidden egg variable in a client transformer.'
31+
);
32+
}
33+
2334
return [
2435
'name' => $variable->name,
2536
'description' => $variable->description,

0 commit comments

Comments
 (0)