Skip to content

Installation

phil/spam-protection-bundle

Requirements

RequirementWhy
PHP 8.5 or later, ext-sodiumThe nonce's hexadecimal, timing-safe.
phil/spam-protectionThe signals, tokens, timing, proof of work and content rules.
phil/bot-detection-bundleThe Verdict an inspection gives.
symfony/form, symfony/options-resolverThe spam_protection option of every form.
symfony/http-foundationThe client's address, from the current request, for the rate limit's key.
symfony/translation-contractsThe message of a held submission.
psr/cache, psr/clock, psr/logThe used tokens, the time, and the log of held submissions.
symfony/rate-limiter (optional)The rate limit per form and client.

The application registers FrameworkBundle, with forms, a cache pool and the clock service.

Installing

composer require phil/spam-protection-bundle
// config/bundles.php
return [
    // …
    Phil\SpamProtectionBundle\PhilSpamProtectionBundle::class => ['all' => true],
];

The Stimulus controller

The proof of work is solved in the browser by a Stimulus controller the bundle ships, declared in assets/package.json as Symfony UX bundles declare theirs. With StimulusBundle and AssetMapper or Webpack Encore, it is found like any UX controller:

composer require symfony/stimulus-bundle
// assets/controllers.json — added by Flex, or by hand
{
    "controllers": {
        "@phil/spam-protection-bundle": {
            "proof-of-work": { "enabled": true, "fetch": "eager" }
        }
    }
}

The controller's identifier is phil--spam-protection-bundle--proof-of-work; the form extension puts it on the proof field with its two values. A page without the controller submits no proof: with a difficulty above 0, its forms are held — set proof_of_work: 0 until the controller is loaded everywhere (Proof of work).