We are seeing sporadic cases, where captcha prints this error message to the screen:
CATPCHA session reuse attack detected
( from catcha.module #363 if statement).
Looking at the issue queue, various other people have reported problems with this, but none of the usecases seem to fit.
Furthermore, it seems to be sporadic and I have not found a way to reproduce this error reliably ( or at all). Whenever this occurs, the captcha still proceeds, and we are getting all the information from the form; however this is very confusing to the end-user who thinks something went wrong ( we had several people contact us about this).
In one of the other treads, somebody suggested to simply turn this error message into a watchdog message ( or in D8, a logger), and not write to the screen any longer. I would like to request this officially.
( I marked it as 'bug,' as there is an underlying problem somewhere).
So in our case, we have changed
drupal_set_message(t('CAPTCHA session reuse attack detected.'), 'error');
into
\Drupal::logger('captcha')->error(t('CAPTCHA session reuse attack detected.'));
I understand this is at best a workaround, but since the underlying problem seems to be hard to diagnose and does not cause a problem to the enduser, I think this solution is OK. We would still see the error in the DB log, and could then debug this further, but at least it is more user friendly.
Comments
Comment #2
arunkumark@horror thanks for more information on this issue. Instead of error making as a log will help to end user to avoid confusions. As per your suggestion, i have created a patch.
Comment #4
andyg5000The tests failed because they depend on the message being rendered on the page. I started to rewrite the tests against your patch, but I think the error should be shown when it is a legitimate error. The wording "attack" is very bad to show to visitors on accident as it makes them question the security of your website, especially for e-commerce sites.
There are two things I think need to happen:
1) Fix the issue with the cached/stale captcha token
The work in #1395184: Forms with AJAX trigger "CAPTCHA session reuse attack detected." error has been committed. Can you see if the current -dev release resolves your issue?
I confirmed that the
captcha_tokenvalue was persisting on my install, but have not tried the update from the issue above yet.2) Rewrite the error message so it doesn't make the user think they've been hacked when there is a false positive.
Maybe something like:
drupal_set_message(t('Your form submission could not be validated due an issue with the CAPTCHA.'), 'warn');Comment #5
borisson_@andyg5000: the patch here was created after #1395184: Forms with AJAX trigger "CAPTCHA session reuse attack detected." error was committed a year ago.
We're running the latest tagged release, which is at this time only one commit behind on the -dev release (#2855165: Deprecated methods and function). On that version we're still getting this issue. We had a customer mention this last week.
The problem seems to be that I can't reproduce this issue, so I can't give any more helpful information either.
For now, we've applied the patch in #2, but I agree with the initial assesment that this is not a solid longtime solution.
I'm not sure if rewriting the message is sufficient, we should try to find why this is happening and fix the root cause.
Comment #6
borisson_Comment #7
borisson_Comment #8
benjifisherI think #2968549: Log CAPTCHA session reuse attacks is a duplicate of this issue, except that one adds logging and keeps the on-screen error message. Also, the other issue logs the expected and actual CAPTCHA response.
Comment #9
elachlan commentedComment #10
blacklabel_tom commentedHi,
Re-opening this one as I think this is a better solution than https://www.drupal.org/project/captcha/issues/2968549.
If this warning doesn't stop users from submitting the form then we should just log the warning instead of displaying it. The patch in the above issue does both which I don't think makes sense.
Looking at the code in _captcha_get_posted_captcha_info() the check is to make sure that the CAPTCHA is valid per form, but doesn't stop submissions.
I think it would be best to log that this token mis match has happened and move on.
Cheers
Tom
Comment #11
blacklabel_tom commentedHi,
I've attached a patch to show what I mean. I've refactored the code a little to make the testing a bit easier as I can't for the life of me figure out how you're meant to test if watchdog entries have been populated.
I've done the tests refactoring blind because I cant run tests locally for some reason.
Cheers
Tom
Comment #12
klidifia commentedDespite the latest dev branch and https://cgit.drupalcode.org/captcha/commit/?id=1c2632a7f6d0b4e2c87066b1a...
This message incorrectly persists. Makes sense to db log and not to drupal_set_message it!
Comment #13
klidifia commentedReroll against dev. Removed the now unused testing constant and put both IF conditions in the same statement (introduced in #2974083: Port to D8: support for cacheable captcha (recaptcha)
Comment #14
klidifia commentedComment #16
elachlan commentedComment #18
pelicani commentedThis may or may not help someone else.
But since Dev hasn't been updated in a while, someone may need this fix for the beta1 version of captcha.
Here is a patch that applies #14 to beta1.
I'm including this in my composer.json file for update.
peace,
Michael