Problem/Motivation

Hello,

When I run the drush "site-install" command, it throws the following error: The Math question field is required.

This error occurs when Drupal executes the "install_configure_form" task when the "enable_globally" configuration is set to 1.
If I set it to 0, I don't get this error.

The Drupal installation uses a Drupal form for this task (see web/core/includes/install.core.inc line 815), and it seems that the captcha is automatically generated in the form.

Steps to reproduce

  1. From an existing site (tested with Drupal 11.1.6), with the Captcha module enabled.
  2. Enable captchas on all forms (set the "enable_globally" property to 1 in the captcha.settings.yml file)
  3. Export the configuration
  4. Reinstall the site with Drush using the existing configurations: vendor/bin/drush site-install minimal --existing-config ...
  5. The error "The field Math question is required." appears immediately after the "install_import_translations" task (if "locale" is enabled), otherwise after the "install_config_revert_install_changes" task.

Proposed resolution

To work around the problem, I had to create a "captcha_point" for "install_configure_form" where I disable the captcha.
Example:

uuid: aa47f69a-7e7b-4b8f-9ead-94907dc0fed7
langcode: fr
status: false
dependencies: {  }
_core:
  default_config_hash: XbughDuwgOtc_8ztmYxz84gaXBeR760xH3bGSKD9v1Q
formId: install_configure_form
captchaType: default
label: 'install_configure_form (needed to prevent error on drush site-install)'

Remaining tasks

As a long-term solution, I propose adding a condition in the captcha_form_alter method to prevent the captcha from being added to the install_configure_form form.

Do you have a better suggestion?

Issue fork captcha-3526792

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

s3b0un3t created an issue. See original summary.

s3b0un3t’s picture

Issue summary: View changes
avpaderno’s picture

Version: 2.0.7 » 2.x-dev
aherczeg’s picture

Assigned: Unassigned » aherczeg

aherczeg’s picture

Assigned: aherczeg » Unassigned
Status: Active » Needs review

peri22 made their first commit to this issue’s fork.

peri22’s picture

Status: Needs review » Reviewed & tested by the community

Added a kernel test: it fails on 2.x with the reported "Math question field is required" error and passes with the MR applied.
RTBC.

japerry’s picture

I've pushed one change on top of the MR. Instead of matching the install_configure_form ID, the hook now returns early when InstallerKernel::installationAttempted() is true. That also covers install-time forms that profiles and distributions add, which would fail the same way, and nobody wants CAPTCHA in the installer anyway. Once installation finishes, the global CAPTCHA applies as before.

Tests:

  • New functional test CaptchaInstallerTest: installs a throwaway profile whose hook_install() turns on enable_globally, through the same non-interactive installer drush uses. On 2.x it fails with "Math question (4 + 9 =) field is required."; with the fix it installs, and user/password gets the global CAPTCHA afterwards.
  • The kernel test from #8 is kept, now simulating the installer state rather than relying on the form ID.

  • japerry committed 0b6a0abe on 2.x authored by aherczeg
    Issue #3526792 Skip CAPTCHA on the site installation configuration form.
    
japerry’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.