Search by

derhansen / form_crshield

derhansen

Challenge/response spambot protection for ext:form - Challenge/response spambot protection for TYPO3 ext:form - Adds a hidden input field containing a challenge string to forms. Client must execute included JavaScript to calculate the expected response.

Package info

github.com/derhansen/form_crshield

Type:typo3-cms-extension

pkg:composer/derhansen/form_crshield

Statistics

Installs: 308 579

Dependents: 3

Suggesters: 1

Stars: 20

Open Issues: 2

4.1.0 2026-12-04 12:04 UTC

README

Latest Stable Version Acceptance Tests Monthly Downloads Project Status: Active – The project has reached a stable, usable state and is being actively developed.

Challenge/response spam shield for TYPO3 ext:form

What is it?

This TYPO3 extension provides a Challenge/response spam shield for TYPO3 ext:form to prevent automated form submissions.

How does it work?

Challenge/response spam shield adds a hidden input field to every form generated by the TYPO3 form extension. The input field has a precalculated value with a challenge. The included JavaScript will use the challenge to calculate an expected response which will be checked on every form submission. If the expected response is not submitted, validation for the hidden input field is considered as failed and no email will be sent.

In order to make automatic form submissions harder for spambots with active JavaScript, a configurable delay for the JavaScript response calculation can be defined in the extension settings (default value: 3 seconds).

Can the protection be bypassed?

Yes, the challenge/response spam shield can be bypassed, if the algorithm used by the extension is implemented to a spambot. This is however unlikely, since the spambot either has to use JavaScript (which I believe most spambots do not) or has to extract the challenge from the parsed HTML and must calculate and submit the response correctly.

A solved response is bound to the page and the form (and not to a single submission), so a captured form submission can be sent again (replayed) until the response expires. If this is a problem for your website, the optional replay protection can be enabled (see below).

Replay protection (optional)

When the extension setting replayProtection is enabled, the final submission of every form requires a single-use nonce ("number used once") in addition to the challenge/response. A captured form submission can then not be replayed. The replay protection is disabled by default.

How it works:

  • When the last page of a form is submitted, the included JavaScript fetches a nonce from the uncached endpoint /form-crshield/nonce and adds it to the form submission. The nonce is signed and expires after 5 minutes. Issuing a nonce does not store any data.
  • The nonce is validated together with the other form fields. If it is invalid or expired, the form is shown again with all entered values and the next submission automatically uses a new nonce.
  • When the form is valid, the extension marks the nonce as used, right before the finishers (e.g. sending an email) are executed. If the nonce has already been used, no finisher is executed and a general error message is shown instead.
  • Steps of multi-step forms before the last page and going back to a previous step do not require a nonce.

No further configuration is required. The finisher is added automatically to all forms rendered in the frontend, which are loaded from a form definition and use the form prototype standard. It is never saved to the form definition, so the form editor is not affected. Other forms (e.g. forms created by a PHP form factory or forms using a custom prototype) are not covered by the replay protection and do not require a nonce.

What the replay protection does (and does not) protect against

The replay protection prevents, that a captured form submission (including a valid challenge/response) is sent again unchanged, e.g. by a spambot, which repeatedly posts recorded form data. Each submission requires a new nonce, which must be fetched from the rate limited nonce endpoint.

The nonce is not bound to a form or a client. A bot, which fetches a nonce from the endpoint for each submission, is therefore only slowed down by the rate limit, but not stopped. The checks of the nonce endpoint for the browser headers Sec-Fetch-Site and Sec-Fetch-Mode only prevent requests from other websites and direct calls in the browser, they are no protection against bots.

Caching, rate limit and server setup

Used nonces are stored in the caching framework cache formcrshield (file backend by default, so no database changes are required) until they expire. Expired entries are cleaned up automatically. Note, that flushing all caches also removes the used nonces, so nonces used within the last 5 minutes can be used once again.

If TYPO3 runs on multiple web servers, the cache must use a backend shared by all servers (e.g. database or Redis), otherwise a nonce used on one server can be used again on another server. When using the database backend, create the cache tables using the database analyzer afterwards. Note, that the lock used when marking a nonce as used only works per server, so a nonce sent to multiple servers at exactly the same time may still be accepted more than once.

$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['formcrshield']['backend']
    = \TYPO3\CMS\Core\Cache\Backend\Typo3DatabaseBackend::class;

The nonce endpoint is rate limited per client IP (60 requests per minute). If required, the limit can be adjusted:

$GLOBALS['TYPO3_CONF_VARS']['SYS']['rateLimiter']['form-crshield-nonce'] = [
    'limit' => 120,
    'interval' => '1 minute',
];

If TYPO3 runs behind a reverse proxy or load balancer, make sure $GLOBALS['TYPO3_CONF_VARS']['SYS']['reverseProxyIP'] (and reverseProxyHeaderMultiValue) are configured, so TYPO3 detects the real client IP. Otherwise all visitors share the IP of the proxy and therefore one rate limit, so form submissions of regular users may be rejected when the limit is exceeded.

If replay protection is enabled, make sure the endpoint /form-crshield/nonce is not blocked (e.g. by a web application firewall or a Content Security Policy connect-src directive).

The error message can be changed using a TYPO3 language override for the label LLL:EXT:form_crshield/Resources/Private/Language/locallang.xlf:replayProtection.rejected.

Forms submitted by JavaScript (AJAX)

The included JavaScript intercepts the final form submission to add the nonce. If a form is submitted by another script (e.g. using fetch() and FormData), the script must add the nonce itself:

  1. Add the attribute data-crshield-submit="manual" to the <form> element, so the included JavaScript does not submit the form.
  2. Call window.FormCrShield.prepare(form) and wait for the returned promise before the form data is read.
form.addEventListener('submit', async event => {
  event.preventDefault()
  await window.FormCrShield.prepare(form)
  const response = await fetch(form.action, { method: 'POST', body: new FormData(form, event.submitter) })
  // ...
})

prepare() resolves false, if no nonce could be fetched. If the form is replaced by the server response, call window.FormCrShield.init() after the new form has been inserted. This is only required, if replay protection is enabled.

Own submit handlers

The included JavaScript handles the submit event on the document, so submit handlers registered on the form itself (e.g. a custom client side validation) are executed first. If such a handler prevents the submission using event.preventDefault(), the form is not submitted. Note the following limitations:

  • If a submit handler on the form calls event.stopPropagation(), the included JavaScript does not receive the submit event and the form is submitted without nonce, so the submission is rejected.
  • Submit handlers registered on the window or registered on the document after the included JavaScript (e.g. jQuery $(document).on('submit', ...)) are executed after the submission has already been started, so they can not prevent it. Register such handlers on the form instead.
  • The attributes formaction, formmethod, formenctype and formtarget of submit buttons are not supported.

Requirements

The extension uses JavaScript to calculate the expected response, so if JavaScript is disabled on client side, form submission will not be possible.

A modern webbrowser is required to run the JavaScript. Internet Explorer < 11 is not supported.

Installation

Just install the extension on your TYPO3 website using composer or the TYPO3 extension manager. No further configuration is required.

Extension settings

The extension has the following extension settings, which can be adjusted if required. The default values should however be fine for most websites.

crJavaScriptDelay

Defines the delay in seconds for the JavaScript response calculation. The default value is 3 seconds.

minimumPageExpirationTime

If the calculated page cache lifetime if very low (e.g. 60 seconds), it may not be possible to fill out a form before the expiration time for the CR response is reached. This setting defines the minimum amount of second, the calculated page cache lifetime must have. Default value is 900 seconds.

additionalPageExpirationTime

Defines the amount of seconds, which is added to the calculated page cache lifetime, if the calculated page cache lifetime is below the defined value in minimumPageExpirationTime.

obfuscationMethod

Defines the obfuscation method used for the challenge/response calculation. Possible values are:

  • 1 - ROT13 (default value)
  • 2 - Reverse String

replayProtection

Enables the optional replay protection (see "Replay protection (optional)"). Default value is 0 (disabled).

Logging

To log failed requests, it is possible to use a dedicated logfile like shown below:

$GLOBALS['TYPO3_CONF_VARS']['LOG']['Derhansen']['FormCrshield']['writerConfiguration'] = [
    \TYPO3\CMS\Core\Log\LogLevel::DEBUG => [
        \TYPO3\CMS\Core\Log\Writer\FileWriter::class => [
            'logFile' => \TYPO3\CMS\Core\Core\Environment::getVarPath() . '/log/form-crshield.log',
        ]
    ]
];

Usage in own extensions

The extension provides the service ChallengeResponseService which can be used to retrieve and validate the challenge and the expected response. 3rd party extensions can use this service and the included JavaScript snippet to implement the challenge/response protection in their own forms (e.g. Extbase forms).

Versions

Version TYPO3 PHP Support/Development
4.x 14.x 8.2 - 8.5 Features, Bugfixes, Security Updates
3.x 13.x 8.2 - 8.5 Features, Bugfixes, Security Updates
2.x 13.x 8.2 - 8.4 Features, Bugfixes, Security Updates
1.x 10.4 - 12.4 7.2 - 8.4 Features, Bugfixes, Security Updates

Reporting a Vulnerability

Please report vulnerabilities to security@typo3.org.

Extensions using the challenge/response algorithm

The following extensions use the challenge/response algorithm:

Thanks for sponsoring

  • Thanks to 3m5. Media GmbH for supporting my open source work on this extension