针对黑客尝试返回正确的 HTTP 状态
我有一个记录信息的系统,有时会发现某个特定的 IP 地址正在做一些令人讨厌的事情,例如尝试利用 phpMyAdmin(即使它甚至没有安装在系统上)。
当我发现这些违规者时,我会将 IP 地址添加到阻止列表中,无论该页面是否存在,该列表都会返回一条小消息,并记录 IP 地址及其查询字符串,以便我可以密切关注它们。
问题是,它们中的大多数似乎都是扫描脚本,而且从技术上讲,我仍然通过小消息返回 HTTP 状态代码 200。我想更进一步地了解状态代码,但我不确定哪一个最适用。
我在此处找到了列表,似乎401< /code> 或
403
最适用。 “禁止”IP 地址的最佳代码是什么?
I have a system that logs information and sometimes find a particular IP address doing something nasty, like trying to exploit phpMyAdmin (even though it isn't even installed on the system).
When I find these offenders, I add the IP address to a block list that returns a small message whether the page exists or not and log the IP address and their query string so I can keep tabs on them.
Problem is, most of them appear to be scripts that scan, and I am still technically returning a HTTP status code of 200 with the small message. I want to be more forward with the status code, but I am not sure which one best applies.
I found the list here, and it seems that 401
or 403
best apply. Which is the best code for "banning" an IP address?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
403
或404
最适合。请参阅403
的参考:"(...) 如果请求方法不是 HEAD 并且服务器希望公开请求未得到满足的原因,则应描述原因实体中的拒绝。如果服务器不希望向客户端提供此信息,则可以使用状态代码 404(未找到)。”
来源:https://www.rfc-editor.org/rfc/rfc2616#section- 10.4.4
例如,您可以返回状态
403 - Forbidden
并在响应正文中描述原因。我不确定是否允许返回类似403 - Banned for ...
的状态代码。无论如何,无辜的用户可能对 403 的原因特别感兴趣。403
or404
is best suited. See the reference for403
:"(...) If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. If the server does not wish to make this information available to the client, the status code 404 (Not Found) can be used instead."
Source: https://www.rfc-editor.org/rfc/rfc2616#section-10.4.4
For example you can return a status
403 - Forbidden
and describe the reason in the response body. I'm not sure whether it is allowed to return a status code like403 - Banned for ...
. In any case, innocent users are probably especially interested in the reason for the 403.