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

When clean called more than once captcha is deleted and then validation error is ensured? #131

Open
skyl opened this issue Jan 14, 2018 · 4 comments

Comments

@skyl
Copy link

skyl commented Jan 14, 2018

I'm trying to shim in a captcha to this wizard: https://github.com/Bouke/django-two-factor-auth/blob/master/two_factor/views/core.py#L64

When I override the default django.contrib.auth.forms.AuthenticationForm with a subclass that has a CaptchaField added, within the context of the above wizard, I always get form validation error on the captcha field. I did some investigating and it looks like the clean method of the CaptchaField is getting called a bunch (5-10 times?) and so, it's coming back valid maybe the first time and finally, the CaptchaStore gets deleted at some point and CaptchaStore.DoesNotExist gets triggered.

As a hack, I've just overridden the clean method so that it doesn't call delete on the CaptchaStore instance. This seems to work ... idk what the security implications are yet. I'm thinking that remove_expired() will maybe do just as well.

@ziima
Copy link
Contributor

ziima commented Jan 19, 2018

Deletion is necessary part of captcha validation. Otherwise a single captcha image could be used to pass multiple forms. In my opinion, there is something wrong with the django-two-factor-auth or your application, because no form should be validated more than once.

@mbi
Copy link
Owner

mbi commented Jan 19, 2018

@ziima that's how Django's form wizard behaves, it's per design and I'm not sure there is a proper way around it.

@ziima
Copy link
Contributor

ziima commented Jan 19, 2018

I haven't used the wizard myself, but I probably found the source of the problem in django-formtools. Anyhow IdempotentSessionWizardView seems to be able to mitigate that problem according to its description.

@mlieqo
Copy link

mlieqo commented Apr 3, 2019

Same problem for me, spend almost whole day trying to figure out some kind of captcha validation caching, but in the end realized that it's probably going to be easier to switch to django-recaptcha.

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