elusive recaptcha bug. Copy code always fails

rakitin picture rakitin · Feb 13, 2015 · Viewed 8.3k times · Source

A very small amount of my users get a captcha that asks them to copy and paste a code, but it always fails for them - while most of the users get the normal one (checkbox) which goes through correctly. Googling only returned three instances of people getting that captcha none of which had any valuable information

Any ideas as to why they're getting that captcha and most importantly why does it fail?

Answer

Alexander O'Mara picture Alexander O'Mara · Feb 25, 2015

Why this happens:

This happens when the client has JavaScript disabled. Let's take a look at the following sample code.

Example code from reCAPTCHA: Tips and Guidelines API documentation:

<script type="text/javascript"
   src="https://www.google.com/recaptcha/api/challenge?k=your_public_key">
</script>

<noscript>
   <iframe src="https://www.google.com/recaptcha/api/noscript?k=your_public_key"
       height="300" width="500" frameborder="0"></iframe><br>
   <textarea name="recaptcha_challenge_field" rows="3" cols="40">
   </textarea>
   <input type="hidden" name="recaptcha_response_field"
       value="manual_challenge">
</noscript>

As we can see, there are noscript tags containing an iframe, a textarea, and a hidden input. When JavaScript is disabled, it will render the contents of the noscript tags and it will look something like this.

JavaScript disabled

The iframe contains a form where a user can enter the captcha and submit the form, upon which the iframe will load a new page containing the response code. Since JavaScript is disabled, the only way to get that token to the parent page's form is to have the user copy-and-paste the token into the textarea in the example.

Workaround?:

So long as the user correctly copy-and-pastes the token, it should work fine. Double-check that the HTML for the captcha contains the correct fallback elements. You can also disable JavaScript in your browser to test it yourself.