-
Notifications
You must be signed in to change notification settings - Fork 0
[Auth] 로그아웃 핸들러 개발 #54
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
Changes from all commits
c426f09
31b0f9b
d0750a9
b6d60ba
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package app.handler; | ||
|
|
||
| import http.HttpMethod; | ||
| import http.request.HttpRequest; | ||
| import http.response.CookieBuilder; | ||
| import web.handler.SingleArgHandler; | ||
| import web.response.HandlerResponse; | ||
| import web.response.RedirectResponse; | ||
| import web.session.SessionStorage; | ||
|
|
||
| public class LogoutWithPost extends SingleArgHandler<HttpRequest> { | ||
| private final SessionStorage sessionManager; | ||
|
|
||
| public LogoutWithPost(SessionStorage sessionManager) { | ||
| super(HttpMethod.POST, "/user/logout"); | ||
| this.sessionManager = sessionManager; | ||
| } | ||
|
|
||
| @Override | ||
| public HandlerResponse handle(HttpRequest request) { | ||
| String sid = request.getCookieValue("SID").orElse(null); | ||
| if (sid != null) sessionManager.invalidate(sid); | ||
|
Comment on lines
+20
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CSRF 취약점: 로그아웃 폼이 CSRF 토큰 없이 POST 요청을 수락하고 있습니다. 헤더.html 의 폼에서 CSRF 토큰을 포함시키고, 핸들러에서 이를 검증해야 합니다. |
||
|
|
||
| RedirectResponse response = RedirectResponse.to("/"); | ||
| response.setCookie(CookieBuilder.delete("SID").path("/")); | ||
| return response; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,12 @@ public void setBody(File file, byte[] body) { | |
| setHeader("Content-Length", String.valueOf(body.length)); | ||
| } | ||
|
|
||
| public void redirectTo(String path){ | ||
| setStatus(HttpStatus.FOUND); | ||
| setHeader("Location", path); | ||
| setHeader("Content-Length", "0"); | ||
| } | ||
|
Comment on lines
+78
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 경로 검증 누락: |
||
|
|
||
| private String guessContentType(File file) { | ||
| String byName = URLConnection.guessContentTypeFromName(file.getName()); | ||
| if (byName != null) return byName; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,9 @@ | |
| <li class="header__menu__item"> | ||
| <span class="header__menu__nickname">닉네임: {{userNickname}}</span> | ||
| </li> | ||
| <form action="/user/logout" method="POST"> | ||
| <button type="submit">로그아웃</button> | ||
| </form> | ||
|
Comment on lines
+9
to
+11
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. CSRF 토큰 누락: 로그아웃 폼에서 CSRF 방지 토큰이 없습니다. 악의적 웹사이트에서 사용자를 공격할 수 있습니다. 숨겨진 입력 필드로 CSRF 토큰을 추가하세요. |
||
| {{else1}} | ||
| <li class="header__menu__item"> | ||
| <a class="btn btn_contained btn_size_s" href="/login">로그인</a> | ||
|
|
||
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.
잠재적 동시성 문제:
getCookieValue()호출 후에sessionManager.invalidate()를 호출하는데, 이 사이에 다른 요청이 같은 세션 ID로 진입할 수 있습니다. 또한 로그아웃 처리 후 쿠키 삭제까지의 과정에서 TOCTOU(Time-of-check-time-of-use) 문제가 존재할 수 있습니다. 세션 무효화 실패 여부를 확인하고 에러 핸들링을 추가하는 것이 좋습니다.