Skip to content

Commit 76b8d66

Browse files
pteroca-comksroga
andauthored
[v0.4.4] Added DISABLE_CSRF env option & TRUSTED_PROXIES (#46)
Co-authored-by: Konrad Sroga <[email protected]>
1 parent 7c4c1b7 commit 76b8d66

File tree

12 files changed

+69
-24
lines changed

12 files changed

+69
-24
lines changed

CHANGELOG.md

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

33
---
44

5+
## [0.4.4] - 2025-03-26
6+
7+
### Added
8+
- Added TRUSTED_PROXIES environment variable to specify trusted proxies for Symfony.
9+
- Added DISABLE_CSRF environment variable to allow disabling CSRF protection.
10+
11+
### Fixed
12+
- Fixed an issue where the user with USER_ROLE could not access server console.
13+
14+
---
15+
516
## [0.4.3] - 2025-03-24
617

718
### Added

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "pteroca/panel",
33
"description": "PteroCA.com is a free, open-source client area and management panel designed specifically for Pterodactyl server users and hosting providers. The platform simplifies and automates server management with a user-friendly interface and robust billing features.",
4-
"version": "0.4.3",
4+
"version": "0.4.4",
55
"type": "project",
66
"license": "MIT",
77
"minimum-stability": "stable",

config/packages/framework.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# see https://symfony.com/doc/current/reference/configuration/framework.html
22
framework:
33
secret: '%env(APP_SECRET)%'
4-
#csrf_protection: true
54

65
# Note that the session will be started ONLY if you read or write from it.
76
session: true

public/index.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,28 @@
11
<?php
22

33
use App\Kernel;
4+
use Symfony\Component\Dotenv\Dotenv;
5+
use Symfony\Component\HttpFoundation\Request;
46

57
require_once dirname(__DIR__).'/vendor/autoload_runtime.php';
68

9+
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
10+
11+
$trustedProxies = $_ENV['TRUSTED_PROXIES'] ?? '';
12+
if (!empty($trustedProxies)) {
13+
$proxiesArray = array_map('trim', explode(',', $trustedProxies));
14+
15+
Request::setTrustedProxies(
16+
$proxiesArray,
17+
Request::HEADER_X_FORWARDED_FOR
18+
| Request::HEADER_X_FORWARDED_HOST
19+
| Request::HEADER_X_FORWARDED_PORT
20+
| Request::HEADER_X_FORWARDED_PROTO
21+
| Request::HEADER_X_FORWARDED_PREFIX
22+
| Request::HEADER_X_FORWARDED_AWS_ELB
23+
);
24+
}
25+
726
return function (array $context) {
827
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
928
};

src/Core/Controller/API/ServerController.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace App\Core\Controller\API;
44

55
use App\Core\Entity\Server;
6-
use App\Core\Enum\UserRoleEnum;
76
use App\Core\Repository\ServerRepository;
87
use App\Core\Service\Server\ServerService;
98
use App\Core\Service\Server\ServerWebsocketService;
@@ -50,7 +49,7 @@ private function getServer(int $id): Server
5049
throw $this->createNotFoundException();
5150
}
5251

53-
if ($server->getUser() !== $this->getUser() || !$this->isGranted(UserRoleEnum::ROLE_ADMIN->name)) {
52+
if ($server->getUser() !== $this->getUser()) {
5453
throw $this->createAccessDeniedException();
5554
}
5655

src/Core/Form/RegistrationFormType.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
9999

100100
public function configureOptions(OptionsResolver $resolver): void
101101
{
102+
$disableCsrf = isset($_ENV['DISABLE_CSRF']) && $_ENV['DISABLE_CSRF'] === 'true';
102103
$resolver->setDefaults([
103104
'data_class' => User::class,
104-
'csrf_protection' => true,
105+
'csrf_protection' => !$disableCsrf,
105106
'csrf_field_name' => '_token',
106107
'csrf_token_id' => 'user_registration',
107108
]);

src/Core/Form/ResetPasswordFormType.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace App\Core\Form;
44

5+
use App\Core\Entity\User;
56
use Symfony\Component\Form\AbstractType;
67
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
78
use Symfony\Component\Form\FormBuilderInterface;
@@ -63,6 +64,11 @@ public function validatePasswordMatch($object, ExecutionContextInterface $contex
6364

6465
public function configureOptions(OptionsResolver $resolver): void
6566
{
66-
$resolver->setDefaults([]);
67+
$disableCsrf = isset($_ENV['DISABLE_CSRF']) && $_ENV['DISABLE_CSRF'] === 'true';
68+
$resolver->setDefaults([
69+
'csrf_protection' => !$disableCsrf,
70+
'csrf_field_name' => '_token',
71+
'csrf_token_id' => 'user_registration',
72+
]);
6773
}
6874
}

src/Core/Form/ResetPasswordRequestFormType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ public function buildForm(FormBuilderInterface $builder, array $options): void
2525

2626
public function configureOptions(OptionsResolver $resolver): void
2727
{
28-
$resolver->setDefaults([]);
28+
$disableCsrf = isset($_ENV['DISABLE_CSRF']) && $_ENV['DISABLE_CSRF'] === 'true';
29+
$resolver->setDefaults([
30+
'csrf_protection' => !$disableCsrf,
31+
'csrf_field_name' => '_token',
32+
'csrf_token_id' => 'user_registration',
33+
]);
2934
}
3035
}

src/Core/Resources/config/services.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
parameters:
2-
version: '0.4.3'
2+
version: '0.4.4'
33
categories_base_path: '/uploads/categories'
44
categories_directory: 'public/uploads/categories'
55
products_base_path: '/uploads/products'

src/Core/Security/UserAuthenticator.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ public function authenticate(Request $request): Passport
5252

5353
$request->getSession()->set(SecurityRequestAttributes::LAST_USERNAME, $email);
5454

55+
$disableCsrf = isset($_ENV['DISABLE_CSRF']) && $_ENV['DISABLE_CSRF'] === 'true';
56+
$badges = [
57+
new RememberMeBadge(),
58+
];
59+
if (!$disableCsrf) {
60+
$badges[] = new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token'));
61+
}
62+
5563
return new Passport(
5664
new UserBadge($email),
5765
new PasswordCredentials($request->request->get('password', '')),
58-
[
59-
new CsrfTokenBadge('authenticate', $request->request->get('_csrf_token')),
60-
new RememberMeBadge(),
61-
]
66+
$badges,
6267
);
6368
}
6469

0 commit comments

Comments
 (0)