这是一个简单的函数,它使用AJAX并在单击按钮时获取ID = 219的数据库中的图像信息
任何加载此网页的人都可以通过转到源代码来更改javascript代码。 然后,通过单击按钮,他将运行修改后的代码(例如将image_id从219更改为300)。因此,他只需更改image_id就可以获取有关任何图像的信息
问题是如何防范客户端攻击或XSS?
function clicked () {
var xhttp = new XMLHttpRequest () ;
xhttp.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200){
var obj = JSON.parse (this.responseText);
alert (obj.description);
}
};
xhttp.open ("POST","get_title_description.php", true);
xhttp.setRequestHeader ("Content-type", "application/x-www-form-urlencoded");
xhttp.send ("image_id=219") ;
}
答案 0 :(得分:-1)
您可以使用以下方式来生成和验证Cookie:
true
如果您不需要认证和授权用户,而只需要随机的,不可预测的图像ID,则只需使用UUID。