-
Notifications
You must be signed in to change notification settings - Fork 4
feat: JWT 인증 필터에서 액세스 토큰 및 검증 토큰 처리 로직 개선 #398
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
개요JWT 인증 필터가 액세스 토큰과 검증 토큰을 처리하기 위해 별도의 제어 경로를 포함하도록 재구성되었습니다. 토큰 검증 실패 시 쿠키가 명확하게 삭제되고, 검증 토큰용 전문화된 인증 경로가 추가되었으며, 구조화된 오류 처리가 도입되었습니다. 변경 사항
시퀀스 다이어그램sequenceDiagram
participant Client
participant Filter as JwtAuthenticationFilter
participant TokenValidator as Token Validator
participant SecurityMgr as SecurityContext Manager
participant CookieMgr as Cookie Manager
Client->>Filter: HTTP 요청 (Access/Verification Token)
rect rgb(230, 245, 250)
Note over Filter,CookieMgr: 액세스 토큰 처리
Filter->>TokenValidator: 액세스 토큰 검증
alt 검증 성공
TokenValidator-->>Filter: 유효한 토큰
Filter->>SecurityMgr: SecurityContext에 인증 설정
else 검증 실패
TokenValidator-->>Filter: 검증 오류
Filter->>CookieMgr: 액세스 토큰 쿠키 삭제
Filter->>SecurityMgr: SecurityContext 초기화
end
end
rect rgb(245, 240, 245)
Note over Filter,SecurityMgr: 검증 토큰 처리
Filter->>Filter: 검증 토큰 존재 확인
alt 검증 토큰 있음
Filter->>TokenValidator: 검증 토큰 검증
alt 검증 성공
TokenValidator-->>Filter: 이메일 추출
Filter->>SecurityMgr: 검증용 전문화된 인증 설정
else 검증 실패
TokenValidator-->>Filter: INVALID_TOKEN 예외
Filter->>CookieMgr: 검증 토큰 쿠키 삭제
end
end
end
Filter->>Filter: 다음 필터로 진행 (chain.doFilter)
Filter-->>Client: HTTP 응답
코드 리뷰 소요 시간🎯 4 (복잡함) | ⏱️ ~45분 시
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/main/java/org/ject/support/common/security/jwt/JwtAuthenticationFilter.java (1)
69-84: 예외 처리 로직에서AuthException이 손실됩니다.Line 69에서 던진
AuthException(AuthErrorCode.INVALID_TOKEN)이 Line 80의 catch 블록에서 잡혀GlobalException(GlobalErrorCode.INVALID_ACCESS_TOKEN)으로 변환됩니다. 이로 인해 verification token 관련 에러가 access token 에러로 잘못 표시됩니다.또한,
chain.doFilter()에서 발생하는IOException/ServletException도INVALID_ACCESS_TOKEN으로 변환되어 실제 오류 원인을 파악하기 어렵습니다.🔎 AuthException을 별도로 처리하는 수정 제안
chain.doFilter(request, response); + } catch (AuthException e) { + log.error("JWT 인증 처리 중 에러 발생", e); + SecurityContextHolder.clearContext(); + throw e; } catch (Exception e) { log.error("JWT 인증 처리 중 에러 발생", e); SecurityContextHolder.clearContext(); throw new GlobalException(GlobalErrorCode.INVALID_ACCESS_TOKEN); }
🧹 Nitpick comments (1)
src/main/java/org/ject/support/common/security/jwt/JwtAuthenticationFilter.java (1)
99-106: 쿠키에SameSite속성이 누락되었습니다.CSRF 공격 방지를 위해
SameSite속성을 설정하는 것이 권장됩니다. Java의Cookie클래스는SameSite를 직접 지원하지 않으므로,Set-Cookie헤더를 직접 구성하거나 Spring의ResponseCookie를 사용해야 합니다.🔎 ResponseCookie를 사용한 수정 제안
+import org.springframework.http.ResponseCookie;private void clearAuthCookie(HttpServletResponse response, String cookieName) { - Cookie cookie = new Cookie(cookieName, null); - cookie.setMaxAge(0); - cookie.setPath("/"); - cookie.setHttpOnly(true); - cookie.setSecure(true); - response.addCookie(cookie); + ResponseCookie cookie = ResponseCookie.from(cookieName, "") + .maxAge(0) + .path("/") + .httpOnly(true) + .secure(true) + .sameSite("Strict") + .build(); + response.addHeader("Set-Cookie", cookie.toString()); }
📜 Review details
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
src/main/java/org/ject/support/common/security/jwt/JwtAuthenticationFilter.java
🧰 Additional context used
🪛 ast-grep (0.40.3)
src/main/java/org/ject/support/common/security/jwt/JwtAuthenticationFilter.java
[warning] 104-104: The application does not appear to verify inbound requests which can lead to a Cross-site request forgery (CSRF) vulnerability. If the application uses cookie-based authentication, an attacker can trick users into sending authenticated HTTP requests without their knowledge from any arbitrary domain they visit. To prevent this vulnerability start by identifying if the framework or library leveraged has built-in features or offers plugins for CSRF protection. CSRF tokens should be unique and securely random. The Synchronizer Token or Double Submit Cookie patterns with defense-in-depth mechanisms such as the sameSite cookie flag can help prevent CSRF. For more information, see: [Cross-site request forgery prevention](https://cheatsheetseries.owasp.org/cheatsheets/Cross-Site_Req\ uest_Forgery_Prevention_Cheat_Sheet.html).
Context: response.addCookie(cookie);
Note: [CWE-352] Cross-Site Request Forgery (CSRF). [REFERENCES]
- https://stackoverflow.com/questions/42717210/samesite-cookie-in-java-application
(cookie-missing-samesite-java)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: check-application
🔇 Additional comments (1)
src/main/java/org/ject/support/common/security/jwt/JwtAuthenticationFilter.java (1)
50-76: 두 토큰이 동시에 존재할 경우의 동작 확인 필요.
accessToken과verificationToken이 모두 유효한 경우, verification 인증이 access token 인증을 덮어씁니다. 이것이 의도된 동작인지 확인해 주세요.만약 두 토큰이 동시에 존재하면 안 되는 경우라면, 명시적인 검증 로직을 추가하는 것이 좋습니다.
src/main/java/org/ject/support/common/security/jwt/JwtAuthenticationFilter.java
Show resolved
Hide resolved
📊테스트 커버리지
|
023-dev
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생하셨습니다.
#️⃣연관된 이슈
close #343
📝 작업 내용
임시 AccessToken 발급 작업의 연장선으로 Token 처리 방식을 개선했습니다.
1. accessToken 처리 방식 개선
2. verificationToken 처리 명확화 (의도적 인증)
3. 쿠키 삭제 로직 공통화
Summary by CodeRabbit
릴리스 노트
버그 수정
개선 사항
✏️ Tip: You can customize this high-level summary in your review settings.