사용자 도구

사이트 도구


python:django:csrf

CSRF protection

CSRF를 이용하여 시스템을 보호하는 것이 완전하지는 않지만 해주어야 하는군요.

     <form method="post">
         {% csrf_token %}
         <input type="text" name="username">
         <button type="submit">Submit</button>
     </form>
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();
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) === (name + '=')) {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}
const csrftoken = getCookie('csrftoken');
python/django/csrf.txt · 마지막으로 수정됨: 2025/08/14 12:53 저자 taekgu