SPIP Web Application Firewall (WAF)

Web Application Firewall for SPIP. Blocks malicious requests and bans repeat offenders.

Sample screenshots

The config page, where we must set the request header that lists the correct IP
The stats page, where we can see the blocked requests
The stats page, where we can see the blocked requests

Discussion

4 discussions

  • 1

    Bonjour,
    Depuis quelques jours j’ai cette erreur (des dizaines de lignes par jour) dans les spip.log et waf_log :

    «3:erreur WAF: failed to write event to tmp/waf_events/c0b9865d8f97e5087ca6b7.jsonl (disk full or permissions?)»

    J’ai vérifié : les droits semblent bons et le disque est loin d’être plein.
    SPIP WAF 1.2.23

    Merci
    dd

    • Bonjour,
      D’accord, il arrive parfois que l’hébergeur impose également une limite sur le nombre de fichiers, et pas seulement sur l’espace disque total.

      Dans ce cas, le problème ne vient probablement pas du dossier tmp/waf_events, mais plutôt du fait qu’une ancienne version du WAF a pu générer un grand nombre de fichiers dans tmp/cache/waf.

      Vous pouvez supprimer ce dossier en toute sécurité et vérifier si cela résout l’erreur de votre côté (et aussi supprimer tmp/waf pour etre sûr).

      Ce comportement a été corrigé dans une version plus récente du WAF. Cependant, dans votre cas, il est possible que les anciens fichiers soient toujours présents et continuent de compter dans la limite du nombre de fichiers autorisé.

      Essayez:

       
      rm -r tmp/cache/waf
      rm -r tmp/waf 
       

      ou simplement supprimer le dossier tmp/cache/waf et tmp/waf via votre gestionnaire de fichiers.

    Reply to this message

  • 4

    Bonjour,
    J’utilise le plugin pour tous mes sites. Depuis l’espace occupé dans hébergement a doublé (de 83 à 150 Go) et je n’arrête pas de racheter de l’espace. Y-a-t-il un moyen de limiter ce phénomène.
    Merci
    Claude

    • Bonjour,

      Je n’ai pas encore rencontré ce problème, mais en effet il se pourrait qu’un pirate envoie des requêtes très volumineuses, qui sont mises en cache en attendant d’être traitées.

      J’ai créé un ticket ici : https://git.spip.net/spip-contrib-extensions/waf/-/work_items/4

      Je vais approfondir cette question.

      Pouvez-vous confirmer que le dossier très volumineux qui occupe tout votre espace est bien le dossier tmp/waf_events ?

      Je m’excuse pour cette réponse tardive. Nous sommes plus actifs sur ce forum : https://discuter.spip.net/

      Cordialement,
      Urs

    • Bonjour Claude,

      J’ai pris note du problème et je vérifie si je peux le reproduire et le corriger.

      Cordialement,
      Urs

    • Bonjour Claude,
      La dernière version du SPIP WAF corrige cette faille.
      Il suffit de faire la mise à jour, et le plugin gère désormais l’espace correctement.

      Avant, les requêtes n’étaient pas toutes raccourcies : des attaquants pouvaient envoyer de très grandes requêtes malveillantes, qui étaient enregistrées sur le disque et finissaient par saturer l’espace disponible.
      Maintenant, le plugin ne conserve qu’une toute petite partie de chaque requête, uniquement la portion qui déclenche le blocage (pour l’analyse dans le dashboard).

      Merci d’avoir signalé ce problème !

    • Bonjour,

      merci pour le retour, J’ai mis mes sites à jour, on verra si ça améliore la gestion mémoire.

      Claude

    Reply to this message

  • 3

    Hi,

    I’ve installed this plugin on several sites and the filtering seems to be efficient for BLOCKLISTED_IP / CMS_PROBE > BANNED IP

    But a bit too efficient for administrators : on one site I had do de-activate it quickly since the admin could no more access the site to publish (with “a server error”). The user told me he used his usual work PC.

    I fear with VPN / moving locations, etc, it may be difficult to avoid hick up.

    Thanks
    dd

    • Hello dd,
      Very true, I had the same issue on one of my sites: Authors couldn’t post certain articles, that contained certain texts like “A great System (try it)” or “”Il faut sélectionner toutes les données de la table“. The WAF triggers on anything similar to system(”reboot") and SELECT and then prevents that.

      The solution is to add thier IP to the Allowlist in the configuration form. Or to disable the WAF entirely rules for logged-in users:

      Add to config/mes_options.php :

      /**
      * Bypass WAF for authenticated SPIP authors in back-office
      */
      function waf_bypass_logged_in_editors($flux)

      include_spip(’inc/session’);

      $statut = session_get(’statut’);

      // Bypass WAF for logged-in authors (1comite or higher)
      if (in_array($statut, [’0minirezo’, ’1comite’], true))
      return true;

      return $flux;

      // Register the bypass pipeline
      $GLOBALS[’spip_pipeline’][’waf_bypass’] .= ’|waf_bypass_logged_in_editors’;

      I think this rule could be a great feature to be added as a checkbox to the config form: Disable WAF for Editors and Admins. I could add that if it’s interesting.

      What do you think?

      About VPN: I haven’t had an issue before.
      One solution there would be to have a secure form where it is easier to whitelist an IP on-the-go. And with the above change, if you are still logged-in, changing to a blocked IP will still let you through (we let logged-in users through).

      And sorry for the late reply. We are more active on the forum here: https://discuter.spip.net/

    • Thanks for the latest addition to WAF with the logged users config.
      I’ve applied it OK.

      I’ve ACPU activated on the server but I see this alert:
      Le cache OPcache est presque saturé ! Envisagez d’augmenter opcache.memory_consumption dans php.ini, ou de passer à APCu (_WAF_CACHE_BACKEND)

      Where is this WAF_CACHE defined ?

      Merci

    • Great DD,
      Thanks for the good feedback!

      For the APCU:
      To change to APCU, add this to config/mes_options.php (create the file if needed) :

      // enable apcu cache for WAF in config/mes_options.php
      define('_WAF_CACHE_BACKEND', 'apcu');
      

      I’m adding this info now here to the documentation as well.
      Urs

    Reply to this message

  • 1

    Hello,
    I have the case of a webmaster being locked out. Is there a way for another webmaster to unlock his IP ? of course I did add its IP to the whitelist but he is still unable to login ... or where to look in the db ?
    And another question: who is receiving the unlock message ? the user on its email address or the site webmaster email ?

    • Hello Pierrot,

      Yes I’ve included instructions here in the documentation: SPIP Web Application Firewall (WAF)

      The simplest is to switch to another network (if you are on your regular WiFi switch to your mobile hotspot, reconnect, and add both your IP’s to the Allowlist. Then switch back to your usual network.

      To unblock via editing a file on the server:

      **Find your IP:** go to https://iplocation.net (it looks like 203.0.113.42) or search for “What’s my IP”.

      **To allowlist an IP via code**, add this to config/mes_options.php (create the file if needed):

      define('_WAF_ALLOWLIST', '203.0.113.42');
      

      If mes_options.php does not exist yet in your config/ folder, create it. Don’t forget to add the “< ? php” at the start of it (without spaces between the characters).

      If you want to add multiple IPs, add one per line:

      define('_WAF_ALLOWLIST',
      '203.0.113.42
      198.51.100.7
      198.51.100.8'
      );
      

      Once saved, the WAF lets these IPs through.

      **As a last resort**, to allow all IPs:

      define('_WAF_ALLOWLIST',
      '0.0.0.0/0
      ::/0'
      );
      

      This allows all IPv4 and IPv6 addresses. So remove it again after you’ve logged into SPIP and added your IP to the whitelist in the configuration form.

      Regarding your question about the unlock message: It is shown to the user/bot doing the violation. They can unblock themselves for x times after which they are hardblocked (configurable in config form).

      And: Don’t hesitate to post any follow up questions in the main forum, we are more active over there: https://discuter.spip.net/

      Kind regards,
      Urs

    Reply to this message

Add a comment

Avant de faire part d’un problème sur un plugin X, merci de lire ce qui suit :

  • Désactiver tous les plugins que vous ne voulez pas tester afin de vous assurer que le bug vient bien du plugin X. Cela vous évitera d’écrire sur le forum d’une contribution qui n’est finalement pas en cause.
  • Cherchez et notez les numéros de version de tout ce qui est en place au moment du test :
    • version de SPIP, en bas de la partie privée
    • version du plugin testé et des éventuels plugins nécessités
    • version de PHP (exec=info en partie privée)
    • version de MySQL / SQLite
  • Si votre problème concerne la partie publique de votre site, donnez une URL où le bug est visible, pour que les gens puissent voir par eux-mêmes.
  • En cas de page blanche, merci d’activer l’affichage des erreurs, et d’indiquer ensuite l’erreur qui apparaît.

Merci d’avance pour les personnes qui vous aideront !

Par ailleurs, n’oubliez pas que les contributeurs et contributrices ont une vie en dehors de SPIP.

Who are you?
[Log in]

To show your avatar with your message, register it first on gravatar.com (free et painless) and don’t forget to indicate your Email addresse here.

Enter your comment here

This form accepts SPIP shortcuts {{bold}} {italic} -*list [text->url] <quote> <code> and HTML code <q> <del> <ins>. To create paragraphs, just leave empty lines.

Add a document

Follow the comments: RSS 2.0 | Atom