Drupal 8 invalid-input-response in beta 7 update

Created on 2 February 2023, almost 2 years ago
Updated 17 October 2023, about 1 year ago

Problem/Motivation

After updating to the latest version (beta 7) of the Simple Google reCAPTCHA module I keep getting the error:
"reCAPTCHA validation failed, error codes: invalid-input-response"

This is on a Drupal 8 installation. Drupal version: 8.9.20.

When downgrading to beta 6 version, the problem is resolved.

Steps to reproduce

Drupal version: 8.9.20.
Install Simple Google reCAPTCHA module and Simple Google reCAPTCHA webform module
Add reCAPTCHA v3 credentials
Add webform id
Test form

🐛 Bug report
Status

Needs review

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @JensBNS
  • Status changed to Postponed: needs info almost 2 years ago
  • 🇵🇱Poland sandboxpl Poland 🇵🇱

    Hi, the webform submodule provides webform specific handler,
    please remove webform ID from /admin/config/services/simple_recaptcha
    and add handler via /admin/structure/webform/manage/{webform_id}/handlers

    If the problem still occurs, please check the page source, the webform should contain a hidden input with name "simple_recaptcha_token" ,
    and this one should be prefilled when you click on submit button, also please check if there's no errors showing up in browser console

    If this doesn't solve your problem please add some additional details such as:
    - webform module version
    - steps to reproduce with https://simplytest.me/
    - or dump webform configuration ( yml dump would be nice )
    As webform module is extremely flexible and provides a lot of contribs extending the default functionality,
    it is hard to test and cover all scenario, thus if you could provide more usueful details and steps it will be easier to dig in :)

  • 🇵🇱Poland sandboxpl Poland 🇵🇱

    oooh, w8, I think it might be related to the latest commit making the module compatible with drupal 10, see: #3289651 📌 Automated Drupal 10 compatibility fixes Fixed

    We have moved from deprecated jquery/once to , see:
    https://www.drupal.org/node/3158256

    I believe that for core versions lower than 9.2.x JS is now throwing errors related to missing once function, can you confirm that ?

  • Hi
    I'm getting the same error. I will offer my findings for hopeful solution..
    When I was debugging it I noticed thath the simple_recaptcha_token is set successfully when inspecting with dev tools.
    But on the validation part the $form_state->getValue('simple_recaptcha_token') is empty.
    So I checked the form payload on submission, and the payload also was empty.

    Any idea what could cause this or how to solve this?

    Sorry English is not my first language.

    Thanks.

  • 🇵🇱Poland sandboxpl Poland 🇵🇱

    @forzakenus which drupal core version are you using for the testing? if it is below 9.2.x it is most likely caused by following change:
    https://www.drupal.org/node/3158256
    We are planning to drop support for Drupal core 8.x as it is not supported anyway.

  • @sandboxpl

    I'm using latest d9 security release so 9.5.5.
    Also I think i should mention that I'm using multiple webforms with ajax.

  • 🇳🇱Netherlands Gerben Spil

    We are having the same issue and I have found the cause, but not yet the solution. In our case we have a node add form that anonymous users can submit. On this form we have recaptcha v3. There is also a file field, where the user can upload an image. This file field is the culprit. The upload is handled with AJAX and this triggers the validation of the form. But the token is not generated untill you use the submit button of the form. So when the file uploads there is no token in the form and the validation fails.

    Drupal version: 9.5.3
    Module version: 1.0-beta7

    Steps to reproduce:

    - a form without AJAX handling, for example a node add form
    - a field with a file upload
    - upload the file
    - press submit button

  • 🇳🇱Netherlands Gerben Spil

    Not sure if the following code is valid so I do not add a patch here, but it works in my project.

    
    public function validateCaptchaToken(&$form, FormStateInterface &$form_state) {
        $triggering_element = $form_state->getTriggeringElement();
        if ($triggering_element['#submit'][0] == 'file_managed_file_submit') {
          return;
        }
    
    
  • Status changed to Active about 1 year ago
  • 🇧🇬Bulgaria valthebald Sofia

    once() should explicitly pass the form instead of relying on "this" argument. Also, when chaining Drupal.Ajax.prototype.beforeSubmit(),
    it's better to use Function.call() instead of direct invocation, to pass thisArgument to original function.

  • 🇧🇬Bulgaria valthebald Sofia

    On a separate note (and this probably deserves separate issue), I don't quite understand isFormActions check. Triggering element is not necessarily part of .form-actions, no?

                   if (typeof currentFormIsRecaptcha !== 'undefined') {
                     let isFormActions = $(this.element).closest('.form-actions').length;
                     let token = $form.find('input[name="simple_recaptcha_token"]').val();
                     if (isFormActions && (typeof token === 'undefined' || token === '')) {
                       this.ajaxing = false;
                       return false;
                     }
                   }
    
    
  • Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    Not currently mergeable.
  • @valthebald opened merge request.
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    38 pass
  • 🇧🇬Bulgaria valthebald Sofia

    To answer original concern of @JensBNS - Drupal 8.9.2 won't work with the latest versions of simple_recaptcha 8.x-1.x, because core/once library was introduced only in 9.2.0, see CR [#3158256]

  • Issue was unassigned.
  • Status changed to Needs review about 1 year ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.1.4 + Environment: PHP 8.1 & MySQL 5.7
    last update about 1 year ago
    38 pass
Production build 0.71.5 2024