Skip to content

Commit c2bc1f0

Browse files
committed
[BUGFIX] Use correct ip address behind reverse proxies
Resolves: in2ode-de/in2frontendauthentication#17
1 parent 9beb397 commit c2bc1f0

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

Classes/Domain/Repository/FeGroupsRepository.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use In2code\In2frontendauthentication\Utility\DatabaseUtility;
1010
use IPTools\IP;
1111
use IPTools\Range;
12+
use Psr\Http\Message\ServerRequestInterface;
1213
use Throwable;
1314
use TYPO3\CMS\Core\Utility\GeneralUtility;
1415

@@ -19,18 +20,21 @@ class FeGroupsRepository
1920
{
2021
const TABLE_NAME = 'fe_groups';
2122

23+
private ServerRequestInterface $request;
24+
2225
/**
2326
* FeGroupsRepository constructor.
2427
* @throws ClassDoesNotExistException
2528
*/
26-
public function __construct()
29+
public function __construct(ServerRequestInterface $request)
2730
{
2831
if (class_exists(Range::class) === false) {
2932
throw new ClassDoesNotExistException(
3033
'IPTools/Range is not available. Did you install this extension via composer?',
3134
1583143391
3235
);
3336
}
37+
$this->request = $request;
3438
}
3539

3640
/**
@@ -62,7 +66,10 @@ protected function isCurrentIpInList(string $ipList): bool
6266
{
6367
$ips = GeneralUtility::trimExplode(',', $ipList, true);
6468
foreach ($ips as $ip) {
65-
if ($this->isCurrentIpAddressInRangeDefinition(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $ip) === true) {
69+
if ($this->isCurrentIpAddressInRangeDefinition(
70+
$this->request->getAttribute('normalizedParams')->getRemoteAddress(), $ip
71+
) === true)
72+
{
6673
return true;
6774
}
6875
}

Classes/EventListener/ModifyFeGroups.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class ModifyFeGroups
1818
{
1919
public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void
2020
{
21-
$feGroupsRepository = GeneralUtility::makeInstance(FeGroupsRepository::class);
21+
$feGroupsRepository = GeneralUtility::makeInstance(FeGroupsRepository::class, $event->getRequest());
2222
$feGroups = $feGroupsRepository->findByCurrentIpAddress();
2323
if (!empty($feGroups)) {
2424
$this->setCookie(true);

0 commit comments

Comments
 (0)