umbraco / Umbraco.Forms.Issues

Public issue tracker for Umbraco Forms
29 stars 0 forks source link

Recaptcha not working for Umbraco Forms version 10.5.x #1158

Closed ramon-perplex closed 7 months ago

ramon-perplex commented 8 months ago

Recently we noticed for some of our websites that recaptcha (V2 and V3) does not work anymore.

After submitting the form the server returns "Please provide a valid value for recaptcha". We have also tested this in a clean install of Umbraco.

We checked the google recaptcha settings and keys which all seem to be in order. The problem stil persists.

Reproduction

Clean install Umbraco (version 10.5) and install Umbraco Forms (version 10.5.x). Setup a valid recaptcha and set the keys for localhost. Setup a form with recaptcha and submit it.

Bug summary

Recaptcha server validation always returns an error on submit.

Specifics

Umbraco Version 10.5 Umbraco Forms Version 10.5.x Any form with recaptcha.

Error message is: "Please provide a valid value for recaptcha".

Steps to reproduce

See above.

Expected result

That recaptcha does what it supposed to do which is submit the form and process the data and not create errors.

Actual result

Form is not submitted and error is displayed.

AndyButland commented 8 months ago

I'm having trouble replicating this I'm afraid @ramon-perplex - can I just play back to what I've done, and maybe you can spot what's different from your tests? Thanks.

Created new Umbraco site on the latest Umbraco 10 with:

dotnet new install Umbraco.Templates::10.8.3
dotnet new umbraco --name TestFormRecaptcha
cd .\TestFormRecaptcha\
dotnet add package Umbraco.Forms --version 10.5.3
code .

Updated appSettings.json to add the following config for unattended install:

"CMS": {
  "Unattended": {
    "InstallUnattended": true,
    "UnattendedUserName": "Administrator",
    "UnattendedUserEmail": "admin@example.com",
    "UnattendedUserPassword": "1234567890",
    "UpgradeUnattended": true
  }
}

And the following config for Forms:

"Forms": {
  "FieldTypes": {
    "Recaptcha3": {
      "SiteKey": "<site key>",
      "PrivateKey": "<private key>",
      "Domain": "Recaptcha"
    }
  }
}

Back to the command line:

dotnet run

I then logged into the backoffice, and created a form with a short answer field and a reCAPTCHA V3 field, configured with a threshold of 0.5.

Created a doc type with a form picker, and rendered it using the following template:

@using Umbraco.Cms.Web.Common.PublishedModels;
@using Umbraco.Forms.Web;
@using Umbraco.Forms.Web.Extensions;
@using Umbraco.Cms.Core.Configuration.Models;
@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage<ContentModels.HomePage>
@using ContentModels = Umbraco.Cms.Web.Common.PublishedModels;
@{
    Layout = null;
}
<html>
<head>
<title>Sample Form Page</title>
</head>
<body>
<h1>Sample Form Page</h1>
@if (Model.Form.HasValue)
{
    @await Component.InvokeAsync("RenderForm", new { formId = Model.Form, theme = "default", includeScripts = true })
}
@Html.RenderUmbracoFormDependencies()

</body>
</html>

I found the form submitted as expected without error.

I then increased the threshold to 1.0 and got the expected default error message of: The Google reCAPTCHA failed to validate your submission.

AndyButland commented 7 months ago

Closing given no further discussion.