看起来我们将为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>兼容的验证码,如果可能的话。

想法吗?


当前回答

非常简单的算术很好。盲人也能回答。(但正如Jarod所说,要注意操作符优先级。)我想有人可以编写一个解析器,但这使得垃圾邮件的成本更高。

足够简单,并且围绕它编写代码并不困难。我看到了两个威胁:

随机的垃圾邮件机器人和可能支持它们的人类垃圾邮件机器人;而且 机器人创建游戏堆栈溢出

通过简单的算术,你可以打败威胁1,但不能打败威胁2。

其他回答

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.

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

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

我认为文本验证码方法的问题在于文本可以被解析并因此得到回答。

如果你的网站很受欢迎(如Stackoverflow),人们喜欢代码挂在它(如Stackoverflow),很有可能有人会把“打破验证码”作为一个挑战,很容易赢得一些简单的javascript + greasemonkey。

因此,例如,在线程的某个地方建议隐藏彩色字母的方法(确实是一个很酷的想法,想法),可以通过以下示例行简单解析轻松打破:

<div id = "captcha">
 <span class = "red">s</span>
 asdasda
 <span class = "red">t</span>
 asdff
 <span class = "red">a</span>
 jeffwerf
 <span class = "red">c</span>
 sdkk
 <span class = "red">k</span>
</div>

同样,解析这个也很简单:

3 + 4 = ?

如果它遵循模式(x + y)或类似的。

类似地,如果你有一组问题(橙色是什么颜色?比如,白雪公主周围有多少个小矮人?),除非你有成千上万个小矮人,否则你可以从其中挑选30个,生成一个问答散列,然后让脚本机器人重新加载页面,直到找到这30个小矮人中的一个。

如何显示9个随机的几何形状,并要求用户选择两个正方形,或两个圆或其他。应该很容易写,也很容易使用。

没有什么比你无法正确阅读短信更糟糕的了……

有史以来最好的验证码!也许你需要像这样的东西来注册,以防止庸人进入。

最近,我开始添加一个标签,名称和id设置为“message”。我将它设置为隐藏与CSS(显示:none)。垃圾邮件机器人看到它,填写并提交表单。服务器端,如果文本区域与id名称填写我标记为垃圾邮件。

我正在研究的另一项技术是随机生成名称和id,其中一些是垃圾邮件检查,另一些是常规字段。

这对我来说非常有效,我还没有收到任何成功的垃圾邮件。然而,我的网站的访问者却少得多:)