Problem with google recaptcha v2

PCZero

Well-Known Member
Dec 13, 2003
715
85
178
Earth
I got a second server recently and I am migrating a handful of sites off of the old box. Many of them use contact us forms with Google recaptcha v2. They all worked flawlessly on the old box but it seems that the recaptcha test fails on the new server.


Contact us page code:

In the head section ->
<script src="https://www.google.com/recaptcha/api.js" async defer></script>

In thebody secction ->
<form action="https://www.mydomain.com/cgi-bin/contact.cgi" method="post" name="feedback">
...
...
...
<div class="g-recaptcha" data-sitekey="my_local_site_key" data-theme="light" ></div>
</form>

In the contact.cgi ->


sub check_captcha {
use LWP::UserAgent;
$capurl = 'https://www.google.com/recaptcha/api/siteverify';
$capres = $Form{'g-recaptcha-response'};
$capsec = '6LdvyBITAAAAABGfcRNeJY6_ww1h3v9cHi4o66VF';
$capadr = $ENV{'REMOTE_ADDR'};
my $ua = LWP::UserAgent->new();
my $response = $ua->post($capurl, [ 'secret' => $capsec, 'response' => $capres, 'remoteip' => $capadr ]);
if ($response->is_success) {
$capcnt = $response->decoded_content;
$capnum = index($capcnt, 'true');
if ($capnum == -1) {
$validinput = 2048;
return;
} else {
return;
}
} else {
$validinput = 4096;
return;
}
}


On the old box it al worked fine. on the new box the script always returns $valid_input as 4096.



I tried installing the LWP::User Agent module but that did not resolve things.

I do have csf installed on both boxes, disabling csf on the new box has no impact.

Any help/advice would be appreciated.
 
Last edited by a moderator:

PCZero

Well-Known Member
Dec 13, 2003
715
85
178
Earth
Spoke too soon. I think the issue is with LWP:UserAgent. This module is required for Google recaptcha v2.

So I go to WHM -> Software -> Module Installers, Search for LWP::UserAgent and click Install.

Results are...

Installing Perl Module "LWP::UserAgent"


Checking C compiler....C compiler (/usr/bin/gcc) OK (cached Sat Oct 2 05:00:18 2021)
Tuned C compiler (/usr/bin/gcc -march=native) OK (cached Sat Oct 2 05:00:18 2021)....Done
Method: Using cpanminus
LWP::UserAgent is up to date. (6.57)



When I go to shell and run instmodsh and then l
I get this response

Installed modules are:
CPAN
CPAN::Meta::Requirements
CPAN::Meta::YAML
Canary::Stability
Encode
Expect
ExtUtils::MakeMaker
HTTP::Message
HTTP::Tiny
IO::Tty
JSON::XS
Net::HTTP
Perl
Try::Tiny
Types::Serialiser
YAML::Syck
common::sense
libwww::perl
local::lib
version

I see that LWP::UserAgent is not listed as an installed module. How do I ensure that this module is installed?
 
Last edited:

PCZero

Well-Known Member
Dec 13, 2003
715
85
178
Earth
Welll I foudn a work around. I rewrote the php form page to call itself an processed all the input on page load. Got rid of the cgi completely.