Skip to content

Commit

Permalink
[BUGFIX] Use correct ip address behind reverse proxies
Browse files Browse the repository at this point in the history
Resolves: in2ode-de/in2frontendauthentication#17
  • Loading branch information
mschwemer committed Dec 19, 2024
1 parent 9beb397 commit c2bc1f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
11 changes: 9 additions & 2 deletions Classes/Domain/Repository/FeGroupsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use In2code\In2frontendauthentication\Utility\DatabaseUtility;
use IPTools\IP;
use IPTools\Range;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;
use TYPO3\CMS\Core\Utility\GeneralUtility;

Expand All @@ -19,18 +20,21 @@ class FeGroupsRepository
{
const TABLE_NAME = 'fe_groups';

private ServerRequestInterface $request;

/**
* FeGroupsRepository constructor.
* @throws ClassDoesNotExistException
*/
public function __construct()
public function __construct(ServerRequestInterface $request)
{
if (class_exists(Range::class) === false) {
throw new ClassDoesNotExistException(
'IPTools/Range is not available. Did you install this extension via composer?',
1583143391
);
}
$this->request = $request;
}

/**
Expand Down Expand Up @@ -62,7 +66,10 @@ protected function isCurrentIpInList(string $ipList): bool
{
$ips = GeneralUtility::trimExplode(',', $ipList, true);
foreach ($ips as $ip) {
if ($this->isCurrentIpAddressInRangeDefinition(GeneralUtility::getIndpEnv('REMOTE_ADDR'), $ip) === true) {
if ($this->isCurrentIpAddressInRangeDefinition(
$this->request->getAttribute('normalizedParams')->getRemoteAddress(), $ip
) === true)
{
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Classes/EventListener/ModifyFeGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ModifyFeGroups
{
public function __invoke(ModifyResolvedFrontendGroupsEvent $event): void
{
$feGroupsRepository = GeneralUtility::makeInstance(FeGroupsRepository::class);
$feGroupsRepository = GeneralUtility::makeInstance(FeGroupsRepository::class, $event->getRequest());
$feGroups = $feGroupsRepository->findByCurrentIpAddress();
if (!empty($feGroups)) {
$this->setCookie(true);
Expand Down

0 comments on commit c2bc1f0

Please sign in to comment.