Error: RecaptchaField::validate(): Recaptcha-service error: 'invalid-request-cookie'

StackOverflow https://stackoverflow.com/questions/7015614

  •  19-12-2020
  •  | 
  •  

Вопрос

I am getting the following error message after setting up the ReCaptcha spam verification. The ReCaptcha works correctly I am just concerned about the errors.

Using Silverstripe version 2.4.5 Modules: - spamprotection - recaptcha

Error: RecatpchaField::validate(): Recaptcha-service error: 'invalid-request-cookie'
At line 285 in /var/www/example/public/recaptcha/code/RecaptchaField.php

RecatpchaField::validate(): Recaptcha-service error: 'invalid-request-cookie'
Line 285 of RecaptchaField.php
RecaptchaField->validate(RequiredFields)
Line 98 of RequiredFields.php
RequiredFields->php(Array)
Line 106 of Validator.php
Validator->validate()
Line 888 of Form.php
Form->validate()
Line 293 of Form.php
Form->httpSubmission(SS_HTTPRequest)
Line 143 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 161 of RequestHandler.php
RequestHandler->handleRequest(SS_HTTPRequest)
Line 147 of Controller.php
Controller->handleRequest(SS_HTTPRequest)
Line 199 of ContentController.php
ContentController->handleRequest(SS_HTTPRequest)
Line 67 of ModelAsController.php
ModelAsController->handleRequest(SS_HTTPRequest)
Line 282 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)
Line 125 of Director.php
Director::direct(/contact-us/ContactForm)
Line 127 of main.php

ContactPage.php

<?php
class ContactPage extends Page {

    static $db = array(
        'Mailto' => 'Varchar(100)',
        'SubmitText' => 'Text',
        'GoogleMapsAPI' => 'Varchar(255)'
    );

    function getCMSFields() {
        $fields = parent::getCMSFields();

        $fields->removeFieldFromTab("Root.Content.Main", "Graphic");
        $fields->addFieldToTab("Root.Content.Contact", new TextField('Mailto', 'Email address to recieve the contact message'));    
        $fields->addFieldToTab("Root.Content.Contact", new TextareaField('SubmitText', 'Text to display sucsesfully sending a message'));       
        $fields->addFieldToTab("Root.Content.Contact", new TextareaField('GoogleMapsAPI', 'Google Maps API Key'));      
        return $fields; 
    }

    static $icon = "cms/images/treeicons/sent";

}

class ContactPage_Controller extends Page_Controller {  

    function ContactForm() {
        // Create fields          
        $fields = new FieldSet(
            new TextField('Name', 'Name<sup></sup>'),
            new EmailField('Email', 'Email<sup></sup>'),
            new TextField('Website', 'Website (if you have one already)'),
            new TextField('Telephone', 'Telephone'),
            new TextareaField('Message','Message<sup></sup>'),
            new OptionsetField('SendMeEmail', 'Send a copy to your email also', array('Yes'=>'Yes','No'=>'No')) 
        );

        // Create action
        $actions = new FieldSet(
            new FormAction('SendContactForm', ' ')
        );

        // Create Validators
        $validator = new RequiredFields('Name', 'Email', 'Message');

        $form = new Form($this, 'ContactForm', $fields, $actions, $validator);

        SpamProtectorManager::update_form($form, 'SendMeEmail');

        return $form;
    }

    function SendContactForm($data) {    

        $From = $data['Email'];
        $To = $this->Mailto;
        $Subject = "Contact Message"; 
        $email = new Email($From, $To, $Subject);
        $email->setTemplate('ContactAdminEmail');
        $email->populateTemplate($data);
        $email->send();

        if($data['SendMeEmail'] == 'Yes'){
            $email_client = new Email($To, $From, $Subject);
            $email_client->setTemplate('ContactClientEmail');
            $email_client->populateTemplate($data);
            $email_client->send();
        }
        //return to submitted message
        Director::redirect(Director::baseURL(). $this->URLSegment . "/?success=1");
    }

} 
Это было полезно?

Решение

How to reproduce:

  • Disable JavaScript in your browser
  • Reload the form
  • Instead of typing the captcha value into the "Type the two words" field (generating the token and copying that into the field at the bottom), put the captcha value directly into the field at the bottom
  • After submitting the form, you should see the above error message

So it's a problem for users with JavaScript disabled who are not reading the given instructions properly.

You might also want to take a look at https://groups.google.com/group/recaptcha/browse_thread/thread/f881b776f3192703 for more details.

While it's working fine on my mobile phone, if this isn't working on some mobile devices, it's very nasty. Filling out the first box only to copy over a pretty long string to a second field is somewhere between cumbersome to impossible, depending on the device.

Другие советы

Fixed with https://github.com/chillu/silverstripe-recaptcha/commit/59034ab - I suspect these errors are caused by spam bots rather than users.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top