我的Ajax调用受“Access-Control-Allow-Origin”保护
但是,仍然可以从Google Chrome工具进行一些ajax调用。
有没有办法阻止Google Chrome调用ajax?
(设置CSRF保护的简单方法?)
发布于 2015-06-29 20:09:39
正如本杰明在第一条评论中所说的那样,永远不要信任客户端,你需要在服务器端进行验证。但我仍然可以给你一个解决方案,以防止用户从控制台发送Ajax请求。
您只需将XMLHttpRequest构造函数设置为私有,然后就可以将其设置为null
(function (xhr) {
// Your code here ...
// Here you can send Ajax Requests without any problem
// You just need to call the sendAjaxReq with options
function sendAjaxReq(options) {
window.XMLHttpRequest = xhr;
$.ajax(options);
window.XMLHttpRequest = null;
}
}(window.XMLHttpRequest));
window.XMLHttpRequest = null;
// Now you can't send Ajax requests from here, and not from console as well.https://stackoverflow.com/questions/31114753
复制相似问题