Skip to content

Commit

Permalink
Merge pull request #129 from szymach/3.2
Browse files Browse the repository at this point in the history
Prevent accessing empty firewall config instance when checking for password change enforcement
  • Loading branch information
rn0 authored Nov 29, 2019
2 parents 61967fd + c552e0e commit e917c22
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ sudo: required
addons:
firefox: "47.0.1"

services:
- xvfb
services: xvfb

matrix:
include:
Expand Down
22 changes: 14 additions & 8 deletions EventListener/EnforcePasswordChangeListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use FSi\Bundle\AdminSecurityBundle\Security\Firewall\FirewallMapper;
use FSi\Bundle\AdminSecurityBundle\Security\User\EnforceablePasswordChangeInterface;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
Expand Down Expand Up @@ -89,7 +88,7 @@ public static function getSubscribedEvents(): array

public function onKernelRequest(GetResponseEvent $event): void
{
if ($event->getRequestType() !== HttpKernelInterface::MASTER_REQUEST) {
if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
return;
}

Expand All @@ -98,20 +97,22 @@ public function onKernelRequest(GetResponseEvent $event): void
return;
}

if (!$this->isConfiguredFirewall($event->getRequest())) {
if (false === $this->isConfiguredFirewall($event->getRequest())) {
return;
}

if (!$this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
if (false === $this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) {
return;
}

if ($this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) {
if (true === $this->authorizationChecker->isGranted('ROLE_PREVIOUS_ADMIN')) {
return;
}

$user = $token->getUser();
if (!($user instanceof EnforceablePasswordChangeInterface) || !$user->isForcedToChangePassword()) {
if (false === $user instanceof EnforceablePasswordChangeInterface
|| false === $user->isForcedToChangePassword()
) {
return;
}

Expand All @@ -120,8 +121,13 @@ public function onKernelRequest(GetResponseEvent $event): void

private function isConfiguredFirewall(Request $request): bool
{
if (method_exists($this->firewallMap, 'getFirewallConfig')) {
$firewallName = $this->firewallMap->getFirewallConfig($request)->getName();
if (true === method_exists($this->firewallMap, 'getFirewallConfig')) {
$config = $this->firewallMap->getFirewallConfig($request);
if (null === $config) {
return false;
}

$firewallName = $config->getName();
} else {
$firewallName = $this->firewallMapper->getFirewallName($request);
}
Expand Down

0 comments on commit e917c22

Please sign in to comment.