比较Referer http头足以防止CSRF,我有下面的html代码。在
<div id="Message"></div><br>
Username:<br>
<input type="text" name="Username" id="Username"><br>
Password:<br>
<input type="password" name="Password" id="Password"><br>
Keep me logged in:<br>
<input type="checkbox" id="KeepSessionAlive"><br>
<input type="submit" onClick="ProcessLogin();">
<script>
function ProcessLogin(){
Username=document.getElementById("Username").value;
Password=document.getElementById("Password").value;
KeepSessionAlive=document.getElementById("KeepSessionAlive").value;
var xmlhttp;
if (window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if (xmlhttp.readyState==4 && xmlhttp.status==200){
document.getElementById("Message").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("POST","/Login/Process",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("<A>Username</A><B>"+Username+"</B><A>Password</A><B>"+Password+"</B><A>KeepSessionAlive</A><B>"+KeepSessionAlive+"</B>");
}
</script>
这只是一个标准的html表单,但我想知道如果我使用下面的代码,我可以完全保护我免受CSRF攻击。在
^{pr2}$
是的,这已经足够了,但它被认为是一种较弱的保护形式:
如果您想要一个防止来自XHR的CSRF的“快速方法”,您可以设置并检查一个自定义头,如^{} 。目前这是安全的,但是推荐的方法是Synchronizer Token Pattern。这对于浏览器插件中的缺陷更为强大,比如允许设置通常不可能设置的头的old vulnerability in Flash。在
相关问题 更多 >
编程相关推荐