Skip to content

Commit 6c4b1be

Browse files
committed
2 parents 64f594a + 0db0767 commit 6c4b1be

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

README.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
# jwt-redis-ip-protection-backend
22

3-
> > #### 배경
3+
> #### 배경
44
> >
55
> > 사내 CRM 프로젝트에서 기존 서버 사이드 JSP 프로젝트를 Cilent를 Vue로 전환하면서 Server가 stateless 형식을 가지고 의존성을 분리 시키는 작업이 필요했다.
66
> > 일반적인 Spring Security, JWT, Redis 방식으로 보안성을 증가 시키고 분리시키는 기획을 가졌지만 항상 Token 탈취 우려가 있어 Client IP 까지 추가적으로 넣어 해당 컴퓨터로 로그인한 사용자만 우리 서버를 이용하는 방식으로 전략 짜보았다. 이를 전면 개발해보고 개선 사항을 기록한다.
77
> > Spring Security + JWT + Redis에 IP 검증을 이용한 보안 필터 개발하기.
88
> > JWT 토큰만으로 보안을 지킬 수 있는가 의문을 시작으로 고도화 작업.
99
>
10-
> > #### 목표
10+
> #### 목표
1111
> >
1212
> > Client가 JWT 토큰을 발급 시 XSS로 인한 토큰 탈취를 방지하기 위한 Cookie HTTPS 설정 추가 ( 브라우저에서 토큰 접근 불가 )
1313
> > Client가 JWT 토큰을 탈취 당할 시, 토큰에 저장된 IP와 Request IP를 검증을 통해 CSRF를 방지 고도화
1414
1515
## 목차
1616

17-
1. [분석](##-▶-분석)
18-
2. [설계](##-▶-설계)
19-
3. [구현](##-▶-구현)
20-
4. [테스트](##-▶-테스트)
21-
5. [Problem-Solving and Key Considerations](##-▶-Problem-Solving-and-Key-Considerations)
17+
1. [분석](#-분석)
18+
2. [설계](#-설계)
19+
3. [구현](#-구현)
20+
4. [테스트](#-테스트)
21+
5. [Problem-Solving and Key Considerations](#-Problem-Solving-and-Key-Considerations)
2222

2323
---
2424

@@ -228,18 +228,7 @@ sequenceDiagram
228228
- dofilter 넘어 가기 전 반드시 token에서 Authentication 객체를 SecurityContextHolder 등록 해줘야 한다.
229229
- 등록이 없다면 그 뒤에 AnonymousAuthenticationFilter, ExceptionTranslationFilter, AuthorizationFilter에서 요청이 거부되고 403 혹은 401 에러를 반환한다.
230230
- SecurityContextHolder은 Spring Security 전역 객체라 생각해야한다. 다음 필터들이 인증된 객체를 가지고 security 프로세스를 흘러가기에 요청 쓰레드 마다 인증이 되었다면 인증 객체를 꼭 등록이 필요하다
231-
- **Spring Security 공식 문서에도 나와 있지만 SecurityContextHolder는 기본적으로 스레드 로컬 변수를 사용하여 보안 컨텍스트를 관리하는데, SecurityContextHolder.getContext() 메서드를 사용하여 보안 컨텍스트를 설정할 때, 동일한 보안 컨텍스트를 여러 스레드에서 동시에 접근하고 수정할 가능성이 있기에 꼭 한 쓰레드 마다 별도에 SecurityContext 생성하고 등록 해주자**
232231

233-
```Java
234-
// 인증 객체 발급
235-
AuthenticationToken authenticationToken = jwtTokenProvider.getAuthenticationToken(accessToken);
236-
237-
SecurityContext context = SecurityContextHolder.createEmptyContext();
238-
context.setAuthentication(authenticationToken);
239-
240-
// SecurityContextHolder 인증 객체 저장
241-
SecurityContextHolder.setContext(context);
242-
```
243232

244233
### LogOut 구현
245234

0 commit comments

Comments
 (0)