Skip to content

Commit

Permalink
#35 [trouble shooting] 첫번째 시도
Browse files Browse the repository at this point in the history
cookie에 same-site 옵션과 secure 옵션 추가
  • Loading branch information
Anna-Jin committed Jul 18, 2022
1 parent 4623e05 commit e99e1eb
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions src/main/java/com/mpnp/baechelin/util/CookieUtil.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mpnp.baechelin.util;

import org.springframework.http.ResponseCookie;
import org.springframework.util.SerializationUtils;

import javax.servlet.http.Cookie;
Expand Down Expand Up @@ -27,13 +28,23 @@ public static Optional<Cookie> getCookie(HttpServletRequest request, String name

// 쿠키 생성
public static void addCookie(HttpServletResponse response, String name, String value, int maxAge) {
Cookie cookie = new Cookie(name, value);
ResponseCookie cookie = ResponseCookie.from(name, value)
.path("/")
.httpOnly(true)
.maxAge(maxAge)
.secure(true)
.sameSite("None")
.build();

cookie.setPath("/");
cookie.setHttpOnly(true); // XSS 공격을 막기 위한 설정
cookie.setMaxAge(maxAge);

response.addCookie(cookie);
response.addHeader("Set-Cookie", cookie.toString());
// Cookie cookie = new Cookie(name, value);
//
// cookie.setPath("/");
// cookie.setHttpOnly(true); // XSS 공격을 막기 위한 설정
// cookie.setMaxAge(maxAge);
// cookie.setSecure(true);
//
// response.addCookie(cookie);
}

// 쿠키 삭제
Expand All @@ -46,6 +57,7 @@ public static void deleteCookie(HttpServletRequest request, HttpServletResponse
cookie.setValue("");
cookie.setPath("/");
cookie.setMaxAge(0);
cookie.setSecure(false);

response.addCookie(cookie);
}
Expand Down

0 comments on commit e99e1eb

Please sign in to comment.