Use flood service

Created on 19 October 2023, about 1 year ago
Updated 20 September 2024, 3 months ago

Problem/Motivation

Sometimes we want to be more forgiving regarding banning perimeter offenders than ban on the first offence.

Steps to reproduce

Proposed resolution

Add core flood integration with settings regarding threshold and time window.

Remaining tasks

User interface changes

API changes

Data model changes

Feature request
Status

Fixed

Version

3.0

Component

Code

Created by

🇸🇮Slovenia primsi

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @primsi
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    2 pass
  • 🇸🇮Slovenia primsi

    Initial patch

  • Status changed to Needs work about 1 year ago
  • 🇨🇭Switzerland berdir Switzerland
    +++ b/src/EventSubscriber/PerimeterSubscriber.php
    @@ -58,12 +73,15 @@ class PerimeterSubscriber implements EventSubscriberInterface {
    -  public function __construct(LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, AccountProxyInterface $current_user, BanIpManagerInterface $ban_manager) {
    +  public function __construct(LoggerChannelFactoryInterface $logger_factory, ConfigFactoryInterface $config_factory, AccountProxyInterface $current_user, BanIpManagerInterface $ban_manager, FloodInterface $flood) {
         $this->loggerFactory = $logger_factory;
         $this->configFactory = $config_factory;
         $this->currentUser = $current_user;
         $this->banManager = $ban_manager;
    +    $this->flood = $flood;
       }
    

    to avoid early bootstrap errors and problems with subclasses and so on, I'd suggest making the argument optional with a fallback to \Drupal::service().

  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    2 pass
  • 🇸🇮Slovenia primsi

    Thanks for the review. Something like that?

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    2 pass
  • 🇸🇮Slovenia primsi

    NID for patch name is wrong. No change in content.

  • Status changed to RTBC about 1 year ago
  • 🇸🇪Sweden alayham

    Tested this patch on a live site, and got myself banned multiple times. This patch works.

  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    Patch Failed to Apply
  • Merge request !14Work by Primsi plus two tests → (Merged) created by alayham
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.x + Environment: PHP 8.1 & MySQL 8
    last update about 1 year ago
    9 pass
  • Status changed to Needs review about 1 year ago
  • 🇸🇪Sweden alayham

    I created a MR for this patch, and added two tests for the new configurations.

  • Status changed to Needs work 11 months ago
  • 🇩🇪Germany Anybody Porta Westfalica

    LGTM in general! But needs a rebase.

  • Pipeline finished with Failed
    11 months ago
    Total: 176s
    #78779
  • Status changed to Needs review 11 months ago
  • 🇸🇮Slovenia primsi

    I rebased. There is one more thing that @Berdir noticed: perimeter_honeypot_reject() needs to use the service instead of the class.

  • Pipeline finished with Failed
    11 months ago
    Total: 231s
    #78782
  • Pipeline finished with Success
    11 months ago
    Total: 311s
    #79675
  • Status changed to Needs work 10 months ago
  • 🇨🇭Switzerland berdir Switzerland

    Left a comment. As written, my point point about perimeter_honeypot_reject() is that it needs to use the same flood behaviour.

  • Status changed to Needs review 10 months ago
  • 🇨🇭Switzerland berdir Switzerland

    Added that. Wasn't sure if it should use the same flood key or not, but then it should probably just be perimeter.

  • Pipeline finished with Success
    10 months ago
    Total: 154s
    #92058
  • Pipeline finished with Success
    10 months ago
    Total: 156s
    #92143
  • 🇩🇪Germany Anybody Porta Westfalica

    Just took a look and LGTM! I'll ask @Grevil to review it finally. Thanks @Berdir, great work as always!

  • Assigned to Grevil
  • 🇩🇪Germany Anybody Porta Westfalica

    Let's make this major as it would be very useful to the modules functionality. Especially being able to not block at first wrong access.

  • First commit to issue fork.
  • Status changed to Needs work 3 months ago
  • 🇩🇪Germany Grevil

    Seems that Make perimeter compatible with fast404 module and use DI for ban.ip_manager Fixed causes handleBannedUrls() being called twice and therefore messing up the threshold logic.

  • 🇩🇪Germany Grevil

    Alright, going to finish this on Monday, just added a few comments for myself.

  • 🇩🇪Germany Grevil

    Note, the method being called twice is fixed in 🐛 "handleBannedUrls()" is executed twice on 404 pages Active .

  • 🇩🇪Germany Grevil

    I have no idea, why the tests fail...

    After some debugging, I find that "onKernelException" is only executed on the first "drupalGet()" inside the tests for some reason.

    I can not replicate this issue locally...

  • Issue was unassigned.
  • 🇩🇪Germany Grevil

    Maybe @berdir has any idea?

  • 🇨🇭Switzerland berdir Switzerland

    drupalGet() doesn't expect have a leading /, try without that. Tests there run in a subfolder, that might end up outside of Drupal.

  • 🇨🇭Switzerland berdir Switzerland

    The other thing is caching. It should be consistent in a test, but I'd expect that multiple requests to the same URL would end up in page cache. I'd suggest using different unique URL's.

  • 🇩🇪Germany Grevil

    Thanks, @berdir!

    I'll check that tomorrow!

  • 🇩🇪Germany Anybody Porta Westfalica

    I removed the leading slahes, let's see what happens, so you'll have a result tomorrow!

  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany Anybody Porta Westfalica
  • Status changed to Needs work 3 months ago
  • 🇨🇭Switzerland berdir Switzerland

    Reviewed and verified the test fails are due to caching.

  • Status changed to Needs review 3 months ago
  • 🇩🇪Germany Grevil

    All tests are green now! Setting back to "Needs Review" for reviewing final changes.

  • Status changed to RTBC 3 months ago
  • 🇩🇪Germany Grevil

    Alright, that's it! Thanks all! 🙂👍

  • Status changed to Fixed 3 months ago
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • 🇯🇵Japan ilfelice

    Howdy,

    Awesome module!

    Is this fix included in the latest release (3.0.4/28 August 2024)?

  • 🇩🇪Germany Grevil

    Indeed! The MR title was incorrect, so it doesn't properly show up in the change notes.

Production build 0.71.5 2024