前端实现csrf防止攻击

function getCookie(name) {
let cookieValue = null;
if (document.cookie && document.cookie !== '') {
const cookies = document.cookie.split(';');
for (let i = 0; i < cookies.length; i++) {
const cookie = cookies[i].trim();
if (cookie.substring(0, name.length + 1) === (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}

const csrftoken = getCookie('csrftoken');

posted @   龙岩龙  阅读(4)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示