Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

README.md

Node + CSRF

CSRF 공격을 막기 위해서 서버에서 토큰을 클라이언트로 발행한다. 클라이언트에서 글 작성 후 데이터 전송 시 서버가 발행한 토큰을 같이 신고한다. 서버에서 생성한 토큰과 맞는지 값을 비교한 후에 토큰이 일치하는 경우에만 글을 작성하도록 구현한다.

새 프로젝트

express my-node-csrf --view=hbs --css=sass

CSRF 모듈 설치

https://www.npmjs.com/package/csurf

npm i csurf

클라이언트에서 서버로 서버가 발행한 토큰을 신고하는 방법

The default value is a function that reads the token from the following locations, in order:

  1. req.body._csrf - typically generated by the body-parser module.
  2. req.query._csrf - a built-in from Express.js to read from the URL query string.
  3. req.headers['csrf-token'] - the CSRF-Token HTTP request header.
  4. req.headers['xsrf-token'] - the XSRF-Token HTTP request header.
  5. req.headers['x-csrf-token'] - the X-CSRF-Token HTTP request header.
  6. req.headers['x-xsrf-token'] - the X-XSRF-Token HTTP request header