사용자 도구

사이트 도구


python:django:csrf

차이

문서의 선택한 두 판 사이의 차이를 보여줍니다.

차이 보기로 링크

다음 판
이전 판
python:django:csrf [2023/04/09 12:59] – 만듦 taekgupython:django:csrf [2025/08/14 12:53] (현재) taekgu
줄 1: 줄 1:
 +====== CSRF protection ======
 +CSRF를 이용하여 시스템을 보호하는 것이 완전하지는 않지만 해주어야 하는군요.
  
 +<code html>
 +     <form method="post">
 +         {% csrf_token %}
 +         <input type="text" name="username">
 +         <button type="submit">Submit</button>
 +     </form>
 +</code>
 +
 +<code>
 +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');
 +</code>