Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting 428 response and no digits in the captcha #177

Open
pascalrobert opened this issue Oct 26, 2017 · 6 comments
Open

Getting 428 response and no digits in the captcha #177

pascalrobert opened this issue Oct 26, 2017 · 6 comments

Comments

@pascalrobert
Copy link

pascalrobert commented Oct 26, 2017

Hi,

We have a Symfony 3 app that have a captcha on a page. It works on a developer's workstation, but not on mine. When the captcha should be generated, I get:

Failed to load resource: the server responded with a status of 428 (Precondition Required)
http://localhost:8000/generate-captcha/gcb_captcha?n=13606794422fa6e0d9847c4d227ea896

The captcha is built like this:

        $form = $this->createFormBuilder()
            ->add('captcha', CaptchaType::class,[
                'width' => 318,
                'height' => 70,
                'as_url' =>true,
                'reload' =>true,
                'invalid_message' => $tr->trans('Ce champ est obligatoire.'),
                'attr'=>['oninvalid'=>""],
                'required' => false
            ])
            ->getForm();

        $form->handleRequest($request);
       $variables['form'] = $form->createView();

What is missing? I have the latest version of Captcha and CapthaBundle. PHP 7.1, with GD support. No error in the logs.

@Gregwar
Copy link
Owner

Gregwar commented Nov 3, 2017

Hello,
First, be sure that the sessions are enabled in your configuration

The controller that generates the captcha is handling another requests, the field options are transported using the session, and retrieved in the generator controller. The 428 error indicates that the controller can't retrieve valid options for generation from the session and is done here:

https://github.com/Gregwar/CaptchaBundle/blob/master/Controller/CaptchaController.php#L32

The session is filled by the Captcha Genrator when the form is issued. As a side effect, loading directly the URL of the captcha without running the form will result in 428

Maybe you can inspect the contents of the session and check what it contains at this time

@pascalrobert
Copy link
Author

pascalrobert commented Nov 8, 2017

Hi,

The session is not empty.

print_r($options, true) gives:

Array ( [charset] => 2054353 [length] => 6 [width] => 130 [height] => 50 [font] => /Users/xxxxx/Code/xxxx-web/xxxxx/vendor/gregwar/captcha-bundle/DependencyInjection/../Generator/Font/captcha.ttf [keep_value] => [as_file] => [as_url] => [reload] => [image_folder] => captcha [web_path] => /Users/xxxxx/Code/xxxxx-web/xxxx/app/../web [gc_freq] => 100 [expiration] => 60 [quality] => 30 [invalid_message] => Bad code value [bypass_code] => [whitelist_key] => captcha_whitelist_key [humanity] => 0 [distortion] => 1 [max_front_lines] => [max_behind_lines] => [interpolation] => 1 [text_color] => Array ( ) [background_color] => Array ( ) [background_images] => Array ( ) [disabled] => [ignore_all_effects] => ) []
print_r($session->has($whitelistKey), true) gives:

[2017-11-08 19:05:13] app.ERROR: []

@pascalrobert
Copy link
Author

Looking at the session data in Symfony Profiler, I do see captcha_whitelist_key:

captcha_whitelist_key | [0 => gcb_captcha]

The printout of $session->has($whitelistKey) in my previous comment is from CaptchaController, so it looks like captcha_whitelist_key is not part of the session when coming into CaptchaController.generateCaptchaAction

@pascalrobert
Copy link
Author

The problem was with... framework->session->cookie_secure: true. Had to set it to false.

@vipinbose
Copy link

The problem was with... framework->session->cookie_secure: true. Had to set it to false.

Yes .. this has helped us too. Thanks..

@HishamHuneidie
Copy link

I have the same problem. But I'm trying to change the same that you changed, but it doesn't solve my problem.
Do you have any idea?
@pascalrobert and @Gregwar thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants