Commit e903b936 authored by Sergey Loginov's avatar Sergey Loginov
Browse files

Issue #3243343 by Erwin De Vylder: Cache poisoning on high traffic sites with...

Issue #3243343 by Erwin De Vylder: Cache poisoning on high traffic sites with content translation and pathauto enabled
parent 45a611d4
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
services:
  advban.ip_manager:
    class: Drupal\advban\AdvbanIpManager
    arguments: ['@database','@config.factory','@date.formatter','@datetime.time']
    arguments: ['@database','@config.factory','@date.formatter']
    tags:
      - { name: backend_overridable }
  advban.middleware:
+8 −16
Original line number Diff line number Diff line
@@ -6,9 +6,7 @@ use Drupal\Core\Controller\ControllerBase;
use Drupal\Core\Database\Connection;
use Drupal\Component\Render\FormattableMarkup;
use Drupal\Core\Config\ConfigFactory;
use Drupal\Core\Datetime\DateFormatter;
use Drupal\Component\Datetime\Time;
use Drupal\advban\AdvbanHelper;

/**
 * Ban IP manager.
@@ -29,13 +27,6 @@ class AdvbanIpManager extends ControllerBase implements AdvbanIpManagerInterface
   */
  protected $config;

  /**
   * The date formatter service.
   *
   * @var \Drupal\Core\Datetime\DateFormatter
   */
  protected $dateFormatter;

  /**
   * The time service.
   *
@@ -50,15 +41,12 @@ class AdvbanIpManager extends ControllerBase implements AdvbanIpManagerInterface
   *   The database connection which will be used to check the IP against.
   * @param \Drupal\Core\Config\ConfigFactory $config
   *   The configuration factory service.
   * @param \Drupal\Core\Datetime\DateFormatter $dateFormatter
   *   The date formatter service.
   * @param \Drupal\Component\Datetime\Time $time
   *   The time service.
   */
  public function __construct(Connection $connection, ConfigFactory $config, DateFormatter $dateFormatter, Time $time) {
  public function __construct(Connection $connection, ConfigFactory $config, Time $time) {
    $this->connection = $connection;
    $this->config = $config;
    $this->dateFormatter = $dateFormatter;
    $this->time = $time;
  }

@@ -258,8 +246,12 @@ class AdvbanIpManager extends ControllerBase implements AdvbanIpManagerInterface
        $ip_end = long2ip($ip_end);
      }

      $format_text = $this->config->get('advban.settings')->get('range_ip_format') ?: '@ip_start ... @ip_end';
      $text = new FormattableMarkup($format_text, ['@ip_start' => $ip, '@ip_end' => $ip_end]);
      $format_text = $this->config->get('advban.settings')
        ->get('range_ip_format') ?: '@ip_start ... @ip_end';
      $text = new FormattableMarkup($format_text, [
        '@ip_start' => $ip,
        '@ip_end' => $ip_end,
      ]);
      return $text;
    }
    else {
@@ -321,7 +313,7 @@ class AdvbanIpManager extends ControllerBase implements AdvbanIpManagerInterface
    $expiry_date = $variables['expiry_date'];
    if (!empty($expiry_date)) {
      $ban_text = $this->config->get('advban.settings')->get('advban_ban_expire_text') ?: '@ip has been banned up to @expiry_date';
      $ban_text_params['@expiry_date'] = $this->dateFormatter->format($expiry_date);
      $ban_text_params['@expiry_date'] = date('r', $expiry_date);
    }
    return new FormattableMarkup($ban_text, $ban_text_params);
  }
+4 −1
Original line number Diff line number Diff line
@@ -301,7 +301,10 @@ class AdvbanAdmin extends FormBase {
    $formatIp = $this->ipManager->formatIp($ip, $ip_end);
    $this->messenger()->addMessage(!$expiry_date ?
      $this->t('The IP address(es) %ip has been banned.', ['%ip' => $formatIp]) :
      $this->t('The IP address(es) %ip has been banned until %expiry', ['%ip' => $formatIp, '%expiry' => $this->dateFormatter->format($expiry_date)])
      $this->t('The IP address(es) %ip has been banned until %expiry', [
        '%ip' => $formatIp,
        '%expiry' => $this->dateFormatter->format($expiry_date),
      ])
    );

    $form_state->setRedirect('advban.admin_page');
+3 −3
Original line number Diff line number Diff line
@@ -35,9 +35,9 @@ class IpAddressBlockingTest extends BrowserTestBase {
    $this->drupalLogin($admin_user);
    $this->drupalGet('admin/config/people/advban');

    /** @var $storage \Drupal\advban\AdvbanIpManager */
    /** @var \Drupal\advban\AdvbanIpManager $storage */
    $ipManagerService = $this->container->get('advban.ip_manager');
    /** @var $connection \Drupal\Core\Database\Connection */
    /** @var \Drupal\Core\Database\Connection $connection */
    $connection = $this->container->get('database');

    // Ban a valid IP address.
@@ -123,7 +123,7 @@ class IpAddressBlockingTest extends BrowserTestBase {

    // Submit your own IP address. This fails, although it works when testing
    // manually.
    // TODO: On some systems this test fails due to a bug/inconsistency in cURL.
    // @todo On some systems this test fails due to a bug/inconsistency in cURL.
    // $edit = array();
    // $edit['ip'] = \Drupal::request()->getClientIP();
    // $this->drupalGet('admin/config/people/advban');