Skip to content

Commit

Permalink
Remove flood-based redirect loop detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
jhedstrom committed May 4, 2015
1 parent 76f0698 commit f4d9bc7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 39 deletions.
2 changes: 1 addition & 1 deletion redirect.services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
- { name: backend_overridable }
redirect.checker:
class: Drupal\redirect\RedirectChecker
arguments: ['@config.factory', '@state', '@flood']
arguments: ['@config.factory', '@state']
redirect.request_subscriber:
class: Drupal\redirect\EventSubscriber\RedirectRequestSubscriber
arguments: ['@redirect.repository', '@language_manager', '@config.factory', '@redirect.checker', '@router.request_context']
Expand Down
13 changes: 1 addition & 12 deletions src/EventSubscriber/RedirectRequestSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,7 @@ public function onKernelRequestCheckRedirect(GetResponseEvent $event) {
$this->context->fromRequest($request);

try {
$redirect = $this->redirectRepository->findMatchingRedirect($path, $request_query, $this->languageManager->getCurrentLanguage()
->getId());
$redirect = $this->redirectRepository->findMatchingRedirect($path, $request_query, $this->languageManager->getCurrentLanguage()->getId());
}
catch (RedirectLoopException $e) {
\Drupal::logger('redirect')->warning($e->getMessage());
Expand All @@ -105,16 +104,6 @@ public function onKernelRequestCheckRedirect(GetResponseEvent $event) {

if (!empty($redirect)) {

// If we are in a loop log it and send 503 response.
if ($this->checker->isLoop($request)) {
\Drupal::logger('redirect')->warning('Redirect loop identified at %path for redirect %id', array('%path' => $request->getRequestUri(), '%id' => $redirect->id()));
$response = new Response();
$response->setStatusCode(503);
$response->setContent('Service unavailable');
$event->setResponse($response);
return;
}

// Handle internal path.
$url = $redirect->getRedirectUrl();
if ($this->config->get('passthrough_querystring')) {
Expand Down
27 changes: 1 addition & 26 deletions src/RedirectChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace Drupal\redirect;

use Drupal\Core\Config\ConfigFactoryInterface;
use Drupal\Core\Flood\FloodInterface;
use Drupal\Core\State\StateInterface;
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
use Symfony\Component\HttpFoundation\Request;
Expand All @@ -27,15 +26,9 @@ class RedirectChecker {
*/
protected $state;

/**
* @var \Drupal\Core\Flood\FloodInterface
*/
protected $flood;

public function __construct(ConfigFactoryInterface $config, StateInterface $state, FloodInterface $flood) {
public function __construct(ConfigFactoryInterface $config, StateInterface $state) {
$this->config = $config->get('redirect.settings');
$this->state = $state;
$this->flood = $flood;
}

/**
Expand Down Expand Up @@ -75,22 +68,4 @@ public function canRedirect(Request $request) {
return $can_redirect;
}

/**
* Checks if for the current session we are not in a loop.
*
* @param Request $request
* Current request object.
*
* @return bool
* TRUE if a redirect loop has been identified.
*/
public function isLoop(Request $request) {
if ($this->flood->isAllowed('redirection', 5, 15)) {
$this->flood->register('redirection', 60);
return FALSE;
}
else {
return TRUE;
}
}
}

0 comments on commit f4d9bc7

Please sign in to comment.