Download the PHP package azymuthia/turnstile-bundle without Composer

On this page you can find all versions of the php package azymuthia/turnstile-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package turnstile-bundle

Turnstile bundle

Strict Cloudflare Turnstile verification for Symfony firewalls and forms.

Requires PHP 8.3 or later and Symfony 7.4 or 8.

Installation

Add the bundle to config/bundles.php if Flex did not:

Create a widget in the Cloudflare dashboard (Turnstile → Add widget). Use one widget per application and environment, and Managed mode unless you have a reason to pick another. Then configure the bundle:

The visitor's IP behind Cloudflare

Behind Cloudflare or another proxy, Request::getClientIp() is the proxy's address unless the proxy is a trusted proxy. If it is not, implement VisitorIpResolver and name the service in visitor_ip_resolver:

Login (form_login)

List the firewall under firewalls and render the widget inside the login form:

azymuthia_turnstile_widget(action, options) accepts field_name (default cf-turnstile-response), theme (auto, light or dark; default auto), size (flexible, normal or compact; default flexible) and language (default: the request locale). The action must match the firewall's action, and the field name must match its field.

A refused login throws Azymuthia\TurnstileBundle\Security\TurnstileAuthenticationException. Its message key, Verification failed. Refresh the page and try again., is translated in the security domain and is the same whether the check failed or Cloudflare could not be reached. getErrorCodes() tells the two apart, for a LoginFailureEvent listener to log:

A Turnstile failure counts towards login throttling like any other failed login.

Only form_login is covered: remember-me, HTTP basic and other authenticators on the same firewall are left alone. A custom authenticator can require a token itself, on any firewall, by adding a badge to its passport:

Forms

The field renders the widget and validates the token with the Turnstile constraint. The violation message is translated in the validators domain. The field is not mapped. Options:

Option Default Meaning
turnstile_action (required) The widget's action, which the token must match.
turnstile_validation true Validate the token when the form is submitted.
turnstile_theme auto auto, light or dark.
turnstile_size flexible flexible, normal or compact.
turnstile_language request locale The widget's language.

The widget is rendered by the turnstile_widget block, which the bundle adds to twig.form_themes.

Verifying later

Tokens are single-use. If something has to be checked before Turnstile, for example a rate limit, render the field with 'turnstile_validation' => false and verify the token yourself afterwards:

TurnstileVerifier is a public service (also azymuthia_turnstile.verifier).

Error codes

A refused check carries Cloudflare's error codes, sanitized, or one of these (constants on Azymuthia\TurnstileBundle\Verifier\ErrorCode):

Code Meaning
unreachable Siteverify timed out, could not be reached, or answered non-2xx or malformed.
missing-input-response No token was posted.
invalid-input-response The token is longer than any Turnstile token.
invalid-input-secret The secret is empty, or is a dummy secret in prod.
hostname-mismatch The token was issued on another hostname.
action-mismatch The token was issued for another action.

Tokens and secrets are never logged. The bundle logs on the turnstile channel when Monolog is installed.

Development: Cloudflare's dummy keys

Cloudflare publishes dummy keys for development. The secrets 1x0000000000000000000000000000000AA (always passes), 2x0000000000000000000000000000000AA (always fails) and 3x0000000000000000000000000000000AA (token already spent) answer with the hostname localhost and the action test. For these secrets alone the hostname and action match is skipped, so the dummy site keys work on any development host:

When kernel.environment is prod, a dummy secret refuses every check and logs at critical. An always-passing secret in production would silently switch Turnstile off. Set the real keys in production.

Testing your application

The bundle never calls Cloudflare in tests if you swap its HTTP client, azymuthia_turnstile.http_client, for a MockHttpClient answering through TurnstileMockResponseFactory:

TurnstileMockResponseFactory::token($action) returns a token that passes for that action. Anything else is refused with invalid-input-response, as Cloudflare would refuse it:

The response's hostname is localhost, the test client's default. For another host, pass it to the factory: arguments: ['app.example.com']. Use a secret that is not one of the dummy secrets in test (e.g. CLOUDFLARE_TURNSTILE_SECRET_KEY=test-secret in .env.test). Otherwise the hostname and action are not checked, and a token for the wrong action would pass.

Licence

MIT, see LICENSE.


All versions of turnstile-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.3
psr/log Version ^2.0 || ^3.0
symfony/config Version ^7.4 || ^8.0
symfony/dependency-injection Version ^7.4 || ^8.0
symfony/form Version ^7.4 || ^8.0
symfony/framework-bundle Version ^7.4 || ^8.0
symfony/http-client Version ^7.4 || ^8.0
symfony/http-client-contracts Version ^3.4
symfony/http-foundation Version ^7.4 || ^8.0
symfony/http-kernel Version ^7.4 || ^8.0
symfony/options-resolver Version ^7.4 || ^8.0
symfony/security-bundle Version ^7.4 || ^8.0
symfony/security-core Version ^7.4 || ^8.0
symfony/security-http Version ^7.4 || ^8.0
symfony/twig-bundle Version ^7.4 || ^8.0
symfony/uid Version ^7.4 || ^8.0
symfony/validator Version ^7.4 || ^8.0
twig/twig Version ^3.12
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package azymuthia/turnstile-bundle contains the following files

Loading the files please wait ...