停止机器人 [SO] - PHP
我将此代码保存在index.php中,填写后单击“提交”按钮,然后向我显示一个验证页面!
我的问题是它如何检测到它不是来自原始服务器?
[我希望他们不要使用引荐来源网址,因为它很容易被禁用]
我的假代码
<html>
<form id="post-form" action="http://stackoverflow.com/questions/ask/submit" method="post">
<input id="title" name="title" type="text" maxlength="300" tabindex="100" class="ask-title-field" value="">
<textarea id="wmd-input" name="post-text" cols="92" rows="15" tabindex="101"></textarea>
<input id="tagnames" name="tagnames" type="text" size="60" value="" tabindex="103">
<input id="submit-button" type="submit" value="Post Your Question" tabindex="120">
</form>
</html>
任何人都可以指导我创建这样的安全页面[如果用户尝试从一个乏味的页面发帖,他会被要求验证]?
I saved this code in index.php and after filling i clicked Submit button, and then a verification page was shown to me !
My question is how did it detected that it was not from the original server ?
[i hope they do not use the referrer as it can be disabled easily]
My Fake Code
<html>
<form id="post-form" action="http://stackoverflow.com/questions/ask/submit" method="post">
<input id="title" name="title" type="text" maxlength="300" tabindex="100" class="ask-title-field" value="">
<textarea id="wmd-input" name="post-text" cols="92" rows="15" tabindex="101"></textarea>
<input id="tagnames" name="tagnames" type="text" size="60" value="" tabindex="103">
<input id="submit-button" type="submit" value="Post Your Question" tabindex="120">
</form>
</html>
Can anyone guide me creating such secure page [where if a user tries to post from a dull page, he will be asked for verification] ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我怀疑这就是问题提交表单上的
的用途。
I suspect that this is what
<input id="fkey" type="hidden" value="..." name="fkey">
on the question submission form is for.您可以创建一个反 XSRF 令牌,而不必在服务器上记住它们。
您可以通过将要验证的信息放入令牌中来做到这一点,通常包括:
然后将此信息与密钥一起散列并将其吐出到隐藏字段中。当令牌返回时,您可以查看给定的信息,再次使用密钥对其进行散列,然后查看散列是否与用户的提交匹配,
例如,对于用户 ID 18936,到期时间戳为 1304861680(大约现在的 Unix 时间)。 ,您可以创建一个如下令牌:
其中 2A956E39 是一些随机盐,末尾的位是使用不太好的密钥的
18936.1304861680.2A956E39
的十六进制编码的 HMAC-SHA1 哈希secretkey
。这达到了反XSRF的目的,但有时一次性服务器存储的令牌也用于防止表单重复提交。按原样,哈希方法对此没有帮助。但在创建新实体的具体情况下,这是部署双重提交预防的常见地方,您可以使用令牌作为唯一值插入数据库作为新实体的一部分,然后拒绝创建如果已经存在带有令牌的实体,则为新实体。
You can create an anti-XSRF token without the element of having to remember them all on the server.
You can do this by putting the information you want to verify inside the token, typically including:
then hash this information together with a secret key and spit it out in the hidden field. When the token comes back in, you can look at the information given, hash it with the key again and see if the hash matches the user's submission.
So for example, for user ID 18936 with expiry timestamp 1304861680 (Unix time for about now), you could create a token like:
where 2A956E39 is some random salt, and the bit at the end is the hex-encoded HMAC-SHA1 hash of
18936.1304861680.2A956E39
using the not-very-good secret keysecretkey
.This achieves the anti-XSRF purpose, but sometimes the one-time-server-stored-token is also used to prevent a form double-submission. As-is, the hash method doesn't help with that bit. But in the specific case of creating a new entity, which is a common place double-submission-prevention is deployed, you can use the token as a unique value inserted into the DB as part of the new entity, and then refuse to create a new entity if there's already one with the token in it.