如何阻止机器人发帖并引发异常

发布于 2024-10-24 22:08:56 字数 359 浏览 4 评论 0原文

我有一个表格,任何人都可以填写对某事的评论,并且该表格不在登录区域内。

在越来越多的机器人试图输入垃圾邮件后,我开始使用验证码。 现在的问题是某种机器人并没有放弃。我每天都会收到大量异常电子邮件,因为机器人尝试输入“危险”数据,而 .NET 不允许这样做,因为请求已经过验证。 验证码根本没有帮助,因为甚至不需要填写它来尝试发布会导致异常的帖子。机器人似乎不明白它每次都会失败。

昨天我尝试更改文本框的名称,还添加了一个“蜜罐”。但这与验证码有同样的问题,异常发生在任何内容实际发布到后面的代码之前。

我真的应该设置 ValidateRequest="false" 以使机器人能够更进一步并可能停止发出请求吗?

所有的想法都非常值得赞赏。

I have a form where anyone can fill in a review about something and this form is not inside a login area.

I started to use captcha after more and more bots was trying to input spam.
The problem now is that some sort of bot just isn't giving up. I receive loads of exception emails everyday since the bot tries to input "dangerous" data and .NET doesn't allow this because the request is validated.
The captcha doesn't help at all since it doesn't even need to be filled in to try to make a post which will cause an exception. The bot doesn't seem to understand that it fails everytime.

Yesterday I tried changing the names of the text boxes and I also added a "honeypot". But it's the same problem as with captcha, the exception occurs before anything is actually posted to the code behind.

Should I really have to set ValidateRequest="false" to enable the bot to make it a step further and maybe stop making requests?

All ideas are very appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

零崎曲识 2024-10-31 22:08:56

您可以:

  • 在页面上设置 ValidateRequest="false",从而打开 XSS 的可能性。
  • 重写Page_Error(),然后捕获异常并以您自己的方式处理它。

我认为你可能必须将两者结合起来才能使其发挥作用。

protected void Page_Error(object sender, EventArgs e)
{
  Exception oops = Server.GetLastError();

  if(oops.GetBaseException() is System.Web.HttpRequestValidationException) 
  {
    System.Diagnostics.Debug.Assert(false);
  }
}

You can either:

  • Set ValidateRequest="false" on the page, opening up the possibility of XSS.
  • Override the Page_Error() and then capture the exception and deal with it in your own way.

I think you might have to combine the 2 to get this to work.

protected void Page_Error(object sender, EventArgs e)
{
  Exception oops = Server.GetLastError();

  if(oops.GetBaseException() is System.Web.HttpRequestValidationException) 
  {
    System.Diagnostics.Debug.Assert(false);
  }
}
隔岸观火 2024-10-31 22:08:56

也许机器人很愚蠢。不要使用 html 中的表单框,而是使用 JavaScript 对其进行加密。这可能会让机器人感到非常困惑。

Maybe the bot is quite stupid. Instead of having that form box in html encrypt it with javascript. It is possible that this will confuse the bot sufficiently.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文