본문 바로가기

TIL

TIL 072523

Q: 테스트코드에서 setup 함수와 setupclass의 차이는 무엇입니까?

A:

 

The difference manifests itself when you have more than one test method in your class. setUpClass and tearDownClass are run once for the whole class; setUp and tearDown are run before and after each test method.

 

https://stackoverflow.com/questions/23667610/what-is-the-difference-between-setup-and-setupclass-in-python-unittest

 

What is the difference between setUp() and setUpClass() in Python unittest?

What is the difference between setUp() and setUpClass() in the Python unittest framework? Why would setup be handled in one method over the other? I want to understand what part of setup is done i...

stackoverflow.com

 

 

 

Q: Template Engine을 사용할 때, 발생하는 CSRF Error가 무엇이고 어떻게 해결합니까?

A: 

What is CSRF?

CSRF is an acronym for Cross-Site Request Forgery. It is a vector of attack that attackers commonly use to get into your system.

The way you usually protect against CSRF is to send a unique token generated by each HTTP request. If the token that is on the server doesn't match with the one from the request, you show an error to the user.

 

https://www.freecodecamp.org/news/csrf-protection-problem-and-how-to-fix-it/

 

CSRF Protection Problem and How to Fix it

One day I was working on a feature at work. I had many branches created in JIRA tickets, so I wanted to open a bunch of PRs (Pull Requests) all at once in different tabs. This is how I usually work – I have a lot of tabs open

www.freecodecamp.org

 

Cross-Site Request Forgery
사이트 간 요청 위조의 줄임말.
웹 애플리케이션 취약점 중 하나로 사용자가 자신의 의지와 무관하게 공격자가 의도한 행동을 해서 특정 웹페이지를 보안에 취약하게 한다거나 수정, 삭제 등의 작업을 하게 만드는 공격 방법이다.

 

https://namu.wiki/w/CSRF

 

https://namu.wiki/w/CSRF

 

namu.wiki

 

2. CSRF 토큰?

 

Django Framework는 form tag로 데이터를 전송할 때 필수로 {% csrf_token %} 코드를 요구한다.

 

CSRF는 Cross-site Request Forgery의 약자이다.

사이트 간 위조 요청 정도로 해석할 수 있다.

 

csrf_token의 작동 원리는 다음과 같다.

서버는 클라이언트의 세션에 무작위 난수를 저장한다.

이후 클라이언트가 {% csrf_token %} 코드를 포함한 모든 request에 대해

서버에 저장된 난수 값과 클라이언트 세션에 저장된 난수 값이 동일한지 확인한다.

 

따라서 위조된 페이지는 서버가 발행한 token값이 일치하지 않으므로 접근이 불가능하다.

이러한 보안 시스템을 무력화시키기 위해서는

정상 발행된 페이지에서 token값을 탈취 한 이후 새로고침 되어 token 값이 교체되기 전에

위조된 페이지를 만들어 접근해야 하며 이를 위해서는 까다로운 기술이 필요하다고 한다.

 

https://dpcalfola.tistory.com/entry/Django-pojc-E5-CSRF-token%EC%97%90-%EB%8C%80%ED%95%98%EC%97%AC-%ED%86%A0%ED%81%B0-%EA%B2%80%EC%A6%9D-%EB%AC%B8%EC%A0%9C-%ED%95%B4%EA%B2%B0-%ED%94%84%EB%A1%9C%EC%A0%9D%ED%8A%B8-%EB%A7%88%EA%B0%90-%EC%B6%94%EA%B0%80%EA%B8%80-2%EB%B2%88

 

Django poj.c E5) CSRF token에 대하여, 토큰 검증 문제 해결 - 프로젝트 마감 추가글 2번

Code E - Server 5번 글, 6월 1일 (수) 자격증 시험 준비로 미뤄 두었던 프로젝트 34~35일 차 (5월 21일~22일) 프로젝트 진행 과정 기록 ( 프로젝트 마감 추가글 2번 ) < CSRF 검증 실패(CSRF trust) 문제 해결 > 1.

dpcalfola.tistory.com

 

https://squirmm.tistory.com/entry/Postman-CSRF-Failed-CSRF-token-missing-or-incorrect-%ED%95%B4%EA%B2%B0

 

[Postman] "CSRF Failed: CSRF token missing or incorrect." 해결

*Django 개발 중 postman 요청 전송 시 나오는 에러 1. CSRF란? csrf는 Cross-site request forgery, 풀어서 설명하면 사이트 간 요청 위조이다. 공격자가 희생자의 권한을 도용하여 특정 웹 사이트의 기능을 실

squirmm.tistory.com

 

https://todoist.com/ko/help/articles/csrf-token-error-messages

 

CSRF 토큰 오류 메세지

공통 질문과 답변을 찾아 당신의 팀과 Todoist를 이용하는 방법에 대해 알아보세요.

todoist.com

 

'TIL' 카테고리의 다른 글

TIL 072723  (0) 2023.07.27
TIL 072623  (0) 2023.07.26
TIL 072423  (0) 2023.07.24
TIL 072123  (0) 2023.07.24
TIL 072023  (0) 2023.07.20