fischerdigital / contao-form-delay-protection-bundle
Time-based spam protection for Contao forms using HMAC-signed timestamps
Package info
github.com/fischer-digital/contao-form-delay-protection-bundle
Type:contao-bundle
pkg:composer/fischerdigital/contao-form-delay-protection-bundle
Requires
- php: ^8.1
- contao/core-bundle: ^5.0
Requires (Dev)
- contao/manager-plugin: ^2.6
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Time-based spam protection for Contao forms. Adds a minimum delay between page load and form submission using HMAC-signed timestamps.
How it works
- When the form is rendered, the bundle injects a hidden field containing a UNIX timestamp and an HMAC-SHA256 signature (signed with the application's kernel secret).
- On submission, the server verifies the signature and checks whether the configured minimum delay has elapsed.
- If the form was submitted too quickly, an error message is shown and the form is not processed (no email sent, no data stored).
This approach is completely session-independent — it works reliably with HTTP caching, AJAX forms and without session cookies.
Requirements
- Contao 5.0+
- PHP 8.1+
Installation
Via Composer (recommended)
composer require fischerdigital/contao-form-delay-protection-bundle
Manual installation
Clone or download this repository into your vendor/fischerdigital/contao-form-delay-protection-bundle directory and add a path repository to your composer.json:
"repositories": [ { "type": "path", "url": "vendor/tbo/contao-form-delay-protection-bundle", "options": { "relative": true, "symlink": true } } ]
Then run:
composer install
Configuration
- Open the Contao backend and navigate to Forms.
- Edit the form you want to protect.
- In the Form configuration legend, enable Enable time-based spam protection.
- Select the Minimum time (3, 5, 10 or 15 seconds).
That's it — no JavaScript, no additional configuration.
How the token works
The hidden field value format is timestamp.hmac:
- timestamp: UNIX timestamp (seconds) at render time
- hmac: HMAC-SHA256 over
timestamp|formId, signed with%kernel.secret%
The HMAC prevents bots from submitting arbitrary timestamps. The signature can only be generated by the server, making it tamper-proof.
Security
- The HMAC is signed with the application's
kernel.secret— the same secret used for CSRF tokens and session signing. - The token is regenerated on every page load (including AJAX re-renders after failed submissions).
- The signature binds the timestamp to the specific form ID, preventing token reuse across forms.
Compatibility
This bundle works alongside other spam protection methods:
- Contao's built-in security question and honeypot
- ALTCHA (antispam widget)
- Any other form validation
License
MIT