CAPTCHA started to behave strange today. It is working OK on most forms, but one. A that specific form it always blocks, saying, that provided solution was not correct (but it is!). After some debugging I found out, that captcha generates a new CAPTCHA session before checking existing one. "Old" solution then fails with new session.
While researching the problem, I found the problem in captcha_element_process():
<?php
list($posted_form_id, $posted_captcha_sid) = _captcha_get_posted_captcha_info($element, $form_state, $this_form_id);
if ($this_form_id == $posted_form_id && isset($posted_captcha_sid)) {
$captcha_sid = $posted_captcha_sid;
}
else {
// Generate a new CAPTCHA session if we could not reuse one from a posted form.
$captcha_sid = _captcha_generate_captcha_session($this_form_id, CAPTCHA_STATUS_UNSOLVED);
}
....
?>
it seems like _captcha_get_posted_captcha_info() returns NULL for $posted_form_id. I went down to this function and found out that problem lies in previously determined form and captcha ID, since $form_state['captcha_info']['form_id'] is NULL.
<?php
if (isset($form_state['captcha_info'])) {
// We already determined the posted form ID and CAPTCHA session ID
// for this form, so we reuse this info
$posted_form_id = $form_state['captcha_info']['form_id'];
$posted_captcha_sid = $form_state['captcha_info']['captcha_sid'];
}
else {
// We have to determine the posted form ID and CAPTCHA session ID
// from the post data.
// TODO: is this enough? We had to check more sources in Drupal 6 (see over there).
......
?>
If I baypass prevously determined ID
<?php
if (FALSE) {
// We already determined the posted form ID and CAPTCHA session ID
// for this form, so we reuse this info
$posted_form_id = $form_state['captcha_info']['form_id'];
$posted_captcha_sid = $form_state['captcha_info']['captcha_sid'];
}
else {
// We have to determine the posted form ID and CAPTCHA session ID
// from the post data.
// TODO: is this enough? We had to check more sources in Drupal 6 (see over there).
......
?>
CAPTCHA works fine. I have not found the reason for $form_state['captcha_info']['form_id'] being NULL.
Comment | File | Size | Author |
---|---|---|---|
#22 | captcha.patch | 622 bytes | rocnhorse |
#13 | 0001-reworked-patch-from-http-drupal.org-node-1024370-com.patch | 910 bytes | soxofaan |
#10 | 1024370_Keep_CAPTCHA_from_failing.patch | 325.81 KB | Pancho |
Comments
Comment #1
soxofaan CreditAttribution: soxofaan commentedCan you describe the form where it doesn't work? Is it from Drupal Core? From a contrib module? A custom module?
Comment #2
slashrsm CreditAttribution: slashrsm commentedIt is a node-edit form. I have a content type, that can be added by anonymous user and then checked and published by editor. Since form is open to the internet i use CAPTCHA to protect it.
Comment #3
chadd CreditAttribution: chadd commentedi also have captcha (both the default math and reCaptcha) failing every time, but only on a form built with a custom module.
drupal v6.20
captcha 6.x-2.3
this just started happening since the upgrade to 6.20
did something change with 6.20's forms API?
Comment #4
soxofaan CreditAttribution: soxofaan commented@chadd: please open a separate issue, this issue is about CAPTCHA 7.x-1.x
@slashrsm: what kind of fields are on the node type? Is there perhaps any AJAX involved?
Comment #5
slashrsm CreditAttribution: slashrsm commentedThere are Title, Body, 3 text fields and image field. Latter uploads images over AJAX, AFAIK.
It is this form.
http://pogledi.si/node/add/pisma-bralcev
It works now because of fix from Description of this issue.
Comment #6
slashrsm CreditAttribution: slashrsm commentedI forgot about standard tags field.
Comment #7
soxofaan CreditAttribution: soxofaan commentedI'm afraid is the AJAX stuff. (related issue: #918856: CAPTCHA Session Reuse message on webforms )
Can you try without the image field?
Comment #8
Chi CreditAttribution: Chi commentedI have similar problem with comment form. CAPTCHA fails every time.
But it works properly if remove file and image fields from the form.
Comment #9
nineLemon CreditAttribution: nineLemon commentedI ran into the very same problem while having an ajax powered form rendered into a block. After hours of debugging I came to the same conclusion as slashrsm, but I found a different solution:
Find the following lines in the captcha_element_process function:
and change it to:
To wrap it up:
Comment #10
PanchoI'd say this is critical.
Solution #9 works FWIK, so here's a patch.
Please review and commit soon! THX
Comment #12
postscripter CreditAttribution: postscripter commentedSolution #9 worked for me.
Comment #13
soxofaan CreditAttribution: soxofaan commented@postscripter: please don't flag this issue as fixed, as long as the fix is not committed yet
@pancho in #10: There is something wrong with your patch: it also contains the removal of all translation files, but those are already removed.
In attachment the reworked patch from #10
Comment #14
PanchoOops, something was wrong there. However #13 works fine on our site.
Comment #15
Chi CreditAttribution: Chi commentedPatch in #13 worked for me.
Comment #16
e5sego CreditAttribution: e5sego commentedPatch in #13 worked for me.
Comment #17
wundo CreditAttribution: wundo commentedThanks folks, committed.
Comment #18
valderama CreditAttribution: valderama commentedfyi: this patch is not applied in 7.x-1.0-alpha3; for now either use the dev version or add the change to the alpha3 version..
and another info, this patch solved the issue that the captcha on a user-register form always failed..
greets,
walter
Comment #19
Jim Kirkpatrick CreditAttribution: Jim Kirkpatrick commentedNot fixed in latest 6.x-2.x DEV with Math Captcha added via Form ID to a Mailchimp block...
Comment #20
jorisdv CreditAttribution: jorisdv commentedI am currently stuck on the same problem (Drupal 6.20, Captcha 6.x-2.4). the proposed solutions did not work... Did anyone get captcha to work in a mailchimp form?
Comment #21
rocnhorse CreditAttribution: rocnhorse commentedIt looks like the problem is #tree=true.
With #tree=true, $form_state['values']['captcha_response'] doesn't exist it's something like $form_state['values']['captcha']['captcha_widgets']['captcha_response']
Comment #22
rocnhorse CreditAttribution: rocnhorse commentedadding
$element['#tree'] = FALSE;
to the captcha_process function seems to fix this.
Here is a patch for 6.x-2.x-dev.
Comment #24
soxofaan CreditAttribution: soxofaan commentedCommitted patch #22 by rocnhorse
http://drupalcode.org/project/captcha.git/commit/2ca5d91
Comment #25
soxofaan CreditAttribution: soxofaan commentedAlso committed it on D7 version
http://drupalcode.org/project/captcha.git/commitdiff/538446c3dcf0abdf060...
Comment #26
soxofaan CreditAttribution: soxofaan commentedcommit of patch #13 by #17 should be reverted.
$posted_form_id = $this_form_id makes no sense: there could be multiple forms on same page, but there can only one be posted.
It also breaks things: #1328272: "10 more examples of this challenge"
Comment #27
soxofaan CreditAttribution: soxofaan commentedas mentioned in #26, I reverted the commit of patch #13:
http://drupalcode.org/project/captcha.git/commit/1161a4d
Comment #28
skitten6 CreditAttribution: skitten6 commentedI seem to have the same problem. when i remove the extra image field the problem is fix. But since im new with drupal codes, im not really sure how to fix this problem with the patch. Maybe a different or easier way for newbies to fix this problem?
Comment #29
soxofaan CreditAttribution: soxofaan commented@ skitten6: your problem is probably this: #918856: CAPTCHA Session Reuse message on webforms
Comment #30
soxofaan CreditAttribution: soxofaan commentedthis issue should be fixed for Drupal 7 version by http://drupalcode.org/project/captcha.git/commit/ef22105
Comment #31
tommeir CreditAttribution: tommeir commentedtesting #22 + #13 against captcha 6.x - 2.4.
anonymous mailchimp works :)
thank you guys. you are a life saver.
btw - changing versions from 2.4 to 2.dev result in empty settings form in the captcha settings. even if you try to add forms to it.
Comment #33
danisha CreditAttribution: danisha at TATA Consultancy Services for Pfizer, Inc. commentedThe issue is not fixed.
https://www.drupal.org/node/2233569#comment-12339687
Can someone help?
Comment #34
Anonymous (not verified) CreditAttribution: Anonymous commentedI have the same Issue, Drupal 7.34 and Zen Theme
Did anyone get any fix for it?
Comment #35
wundo CreditAttribution: wundo at Chuva Inc. for Chuva Inc. commented