Cloudflare Turnstile

Cloudflare Turnstile CAPTCHA extension

The Cloudflare Turnstile extension protects actions with Turnstile, Cloudflare’s CAPTCHA service. It tells humans from bots mostly without asking the visitor to do anything.

Unlike Proof of work, Turnstile is a third-party service: when a visitor performs a protected action, their browser loads Cloudflare’s script and talks to Cloudflare. Nothing is loaded while the visitor merely reads the comments.

How it works

  1. When a visitor submits a protected action, the comments widget loads the Turnstile script and shows the challenge in a small dialog. Most of the time, Turnstile decides on its own, and the dialog closes in a second; sometimes it asks the visitor to tick a checkbox.
  2. The resulting token is sent along with the action.
  3. Comentario has Cloudflare verify the token, and checks that it was obtained on one of the domain’s hosts and for the action being performed.

If Cloudflare can’t be reached, a comment without registration is still accepted, but held for moderation, so that an outage doesn’t silence your site. Logging in goes ahead without the challenge. Registering a commenter fails with a message to try again later.

Setup

  1. Add a widget in the Turnstile section of the Cloudflare dashboard. Any widget mode will do; Managed is a good default.
  2. List the hostnames the comments are embedded on, i.e. the domain’s host and any other origin it allows. For the Administration UI, list Comentario’s own hostname.
  3. Copy the widget’s site key and secret key.

Configuration

The site key and the secret can be provided in two ways:

  • Globally, in the secrets, as extensions.turnstile.key and extensions.turnstile.secret. This suits an installation serving a single website, or several listed under the same widget.
  • Per domain, in the extension configuration, which takes precedence over the global key:
siteKey=0x4AAAAAAA...
secret=0x4AAAAAAA...

Both values must be given together. If no global key is configured, the domain has to provide its own, otherwise the domain can’t be saved.

The extension can be disabled for the whole instance with extensions.turnstile.disable in the secrets.

Content Security Policy

If the embedding page has a Content Security Policy, allow Turnstile’s script and frame:

script-src https://challenges.cloudflare.com;
frame-src https://challenges.cloudflare.com;

Privacy

Turnstile sends data about the visitor’s browser to Cloudflare. Mention it in your site’s privacy policy when you enable the extension.

See also