看起来我们将为Stack Overflow添加CAPTCHA支持。这对于防止机器人、垃圾邮件发送者和其他恶意脚本活动是必要的。我们只希望人类在这里发布或编辑东西!

我们将使用JavaScript (jQuery)验证码作为第一道防线:

http://docs.jquery.com/Tutorials:Safer_Contact_Forms_Without_CAPTCHAs

这种方法的优点是,对于大多数人来说,CAPTCHA永远不会可见!

然而,对于禁用JavaScript的人,我们仍然需要一个备用方案,这就是棘手的地方。

我为ASP编写了一个传统的CAPTCHA控件。NET,我们可以重复使用。

但是,我更倾向于使用一些文本化的东西,以避免为每个请求在服务器上创建所有这些图像的开销。

我见过这样的事情…

ASCII文本验证码:\/\/(_)\/\/ 数学难题:7减3乘以2等于多少? 小问题:癞蛤蟆和冰棍,哪个更好吃?

也许我只是在风车这里倾斜,但我希望有一个更少的资源密集型,非图像为基础的<noscript>兼容的验证码,如果可能的话。

想法吗?


当前回答

Make an AJAX query for a cryptographic nonce to the server. The server sends back a JSON response containing the nonce, and also sets a cookie containing the nonce value. Calculate the SHA1 hash of the nonce in JavaScript, copy the value into a hidden field. When the user POSTs the form, they now send the cookie back with the nonce value. Calculate the SHA1 hash of the nonce from the cookie, compare to the value in the hidden field, and verify that you generated that nonce in the last 15 minutes (memcached is good for this). If all those checks pass, post the comment.

This technique requires that the spammer sits down and figures out what's going on, and once they do, they still have to fire off multiple requests and maintain cookie state to get a comment through. Plus they only ever see the Set-Cookie header if they parse and execute the JavaScript in the first place and make the AJAX request. This is far, far more work than most spammers are willing to go through, especially since the work only applies to a single site. The biggest downside is that anyone with JavaScript off or cookies disabled gets marked as potential spam. Which means that moderation queues are still a good idea.

从理论上讲,这可以作为通过模糊性的安全,但在实践中,这是很好的。

我从未见过垃圾邮件发送者试图破解这种技术,尽管可能每隔几个月我就会收到一个手动输入的主题垃圾邮件条目,这有点怪异。

其他回答

谁说每个请求都必须在服务器上创建所有映像?也许你可以有一个静态的图片列表,或者从flickr中获取它们。我喜欢“点击小猫”验证码的想法。http://www.thepcspy.com/kittenauth

我曾经在一个朋友的网站上看到过这个。他卖了20美元。这是ASCII艺术!

http://thephppro.com/products/captcha/

  .oooooo.         oooooooo 
 d8P'  `Y8b       dP""""""" 
888      888     d88888b.   
888      888 V       `Y88b '
888      888           ]88  
`88b    d88'     o.   .88P  
 `Y8bood8P'      `8bd88P'   

简单的数学并不是答案——垃圾邮件发送者甚至不需要编写一个简单的解析器。谷歌将为他们做这件事,即使你使用单词而不是数字,所以它只需要在谷歌上快速搜索,它就完成了。

它也可以很容易地进行文本到数字的转换。

似乎有某种错误在SO的渲染,因为它只显示第一个链接时,这是张贴,即使预览工作正常。第二个链接是-进入谷歌,搜索“1 * 42”

音频呢?提供一个有声音在说话的音频样本。让用户输入他听到的内容。也可能是被他识别出来的声音效果。

作为奖励,这可以帮助语音识别器创建封闭的标题,就像RECAPTCHA帮助扫描书籍一样。

可能愚蠢……我有个想法。

在我的博客上,除非有javascript,否则我不接受评论,而是通过ajax发布评论。它把所有的机器人挡在外面。我收到的唯一垃圾邮件来自人类垃圾邮件发送者(他们通常从站点复制并粘贴一些文本来生成评论)。

如果你必须要有一个非javascript版本,可以这样做:

下面字符串[y]中[x]的[某些操作]

给定一个足够复杂的[x]和[y],无法用正则表达式求解,那么编写解析器就很难了

数一下[dog,dangerous,danceable,cat]中短单词的个数= 2

在[dog,dangerous,danceable,catastrophe] = dog中最短的单词是什么

哪个单词以x结尾,[fish,mealy,box,stackoverflow] = box

在[apple.com, stackoverflow.com, fish oil.com] = fish oil.com中,哪个url是非法的

所有这些都可以在服务器端轻松完成;如果选项的数量足够大,并且频繁轮换,那么就很难获得所有选项,再加上永远不要每天给同一用户相同类型的内容超过一次