【发布时间】:2021-01-26 20:28:24
【问题描述】:
我对 isTrusted 的使用有疑问,我想分享一下。如何拒绝服务器端脚本抓取我的 HTML 源代码并对我的操作 URL 进行 POST HTTP 调用?通过这种方式,isTrusted 属性可以很容易地传递过来。很遗憾,我不能使用 CAPTCHA 或 reCAPTCHA。
我有一个这样的示例表单:
<form id="mod" action="otherPage.php" onsubmit="return false;">
<input type="text" name="yourName">
<input type="hidden" name="noCSRF" value="eweifwo23-423dad13123.ljk9879">
<input type="submit" id="sender">
</form>
还有一个像这样的简单脚本:
document.getElementById("mod").submit=function(){ return false; };
document.getElementById("sender").addEventListener("click", function (event) {
var replicant=true;
if ("isTrusted" in event)
{
if (event.isTrusted)
{
replicant=false;
}
if (!replicant)
{
alert("you are a human");
//XMLHttpRequest to action URL
}
else
{
alert("YOU ARE A REPLICANT!!");
}
}
else
{
alert("nothing to do!");
}
});
【问题讨论】:
标签: javascript forms captcha