-
Notifications
You must be signed in to change notification settings - Fork 5
세션 & CSRF 관리 프로세스
Lee Dogyeong edited this page Dec 2, 2020
·
4 revisions
세션 : {}
유저별 세션 : {}
쿠키 : {}
서버에서 세션 생성, csrf 토큰 생성
세션 id를 쿠키로 전달, csrf 토큰 전달
클라이언트는 csrf 토큰을 메모리에 저장
세션 : {
sid001: {
user: john,
scrfToken: csrfTokenABCDE,
expires: 20201225,
isPassedWithOTP: false,
}
}
유저별 세션 : {
john: [sid001],
}
쿠키 : {
cookie: sid001
}
요청시에 쿠키는 자동으로 전달, csrf 토큰은 요청 파라미터에 넣어서 전달
서버는 쿠키에 있는 세션id를 보고 세션을 찾는다
세션이 있는지, 세션이 만료되었는지, 파라미터로 온 csrf 토큰이 일치하는지 체크한다
요청과 마찬가지로 쿠키, csrf 토큰, 추가로 OTP를 전달
서버는 체크 후 isPassedWithOTP를 true로 변경
세션 : {
sid001: {
user: john,
scrfToken: csrfTokenABCDE,
expires: 20201225,
isPassedWithOTP: true,
}
}
유저별 세션 : {
john: [sid001],
}
쿠키 : {
cookie: sid001
}
요청과 마찬가지로 쿠키, csrf 토큰 전달
서버는 체크 후 세션을 삭제하고 클라이언트도 쿠키를 삭제하도록 명령
클라이언트는 새로고침하면 메모리에 있는 csrf토큰이 삭제된다.
그래서 csrf 토큰을 새로 생성하는 api를 요청
서버에서 해당 세션에 새로운 csrf 토큰을 생성해서 전달한다
세션 : {
sid001: {
user: john,
scrfToken: csrfTokenQWERTY,
expires: 20201225,
isPassedWithOTP: true,
}
}
유저별 세션 : {
john: [sid001],
}
쿠키 : {
cookie: sid001
}
세션 : {
sid001: {
user: john,
scrfToken: csrfTokenQWERTY,
expires: 20201225,
isPassedWithOTP: true,
}
sid002: {
user: john,
scrfToken: csrfTokenFASDE,
expires: 20201230,
isPassedWithOTP: true,
}
}
유저별 세션 : {
john: [sid001, sid002],
}
쿠키 : {
cookie: sid001
}
다른 브라우저의 쿠키 : {
cookie: sid002
}
Request
POST /api/auth/password/email
{
id: 'user-id',
name: 'name',
birth: 'birth',
totp: '123456',
reCaptchaToken: "afagewgnjrwfwfjwefjqjp"
}
Response
200 OK
{
message: "mail was sent"
}
400 Bad Request
{
"message": "bad id"
}
Reqeust Response
© Boostcamp