Google reCAPTCHA v2

Google reCAPTCHA v2 CAPTCHA extension

The Google reCAPTCHA v2 extension protects actions with reCAPTCHA v2, Google’s “I’m not a robot” checkbox. The visitor ticks the checkbox, and may be asked to solve an image puzzle.

When a visitor performs a protected action, their browser loads Google’s script and talks to Google. 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 reCAPTCHA script and shows the checkbox in a small dialog. Once the visitor passes it, the dialog closes.
  2. The resulting token is sent along with the action.
  3. Comentario has Google verify the token, and checks that it was obtained on one of the domain’s hosts.

Unlike reCAPTCHA v3, reCAPTCHA v2 doesn’t tell which action a token was obtained for, so Comentario can’t check it: a token solved for registering, say, is just as good for posting a comment. Every token can be used only once, so each action still costs a solved challenge.

If Google 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. Register a site of type Challenge (v2), “I’m not a robot” Checkbox, in the reCAPTCHA admin console. Keys of the other types, such as v3 or invisible v2 keys, don’t work with this extension.
  2. List the domains 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 site key and the secret key.

Configuration

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

  • Globally, in the secrets, as extensions.recaptcha2.key and extensions.recaptcha2.secret.
  • Per domain, in the extension configuration, which takes precedence over the global key:
siteKey=6Lc...
secret=6Lc...

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.recaptcha2.disable in the secrets.

Content Security Policy

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

script-src https://www.google.com/recaptcha/ https://www.gstatic.com/recaptcha/;
frame-src https://www.google.com/recaptcha/ https://recaptcha.google.com/recaptcha/;

Privacy

reCAPTCHA sends data about the visitor and their browser to Google, and is subject to Google’s Privacy Policy and Terms of Service. Mention it in your site’s privacy policy when you enable the extension.

See also