보안 공부/Web 보안

Http secure flag (http 보안 플래그)

H.J.World 2022. 4. 28. 10:10
728x90
반응형

쿠키란

쿠키(Cookie)란 서버가 브라우저에게 주는 정보이다. 주로 사용자의 로그인 결과 정보를 응답 헤더의 Set-Cookie에 담아 브라우저에게 전달하면, 브라우저는 해당 정보를 로컬에 저장하여 활용한다. 대개 브라우저를 종료하면 같이 소멸되는 짧은 수명의 쿠키를 가장 많이 사용하고, 브라우저를 종료해도 오랫동안 유지되는 긴 수명의 쿠키 또한 사용한다.

 

secure

브라우저에서 쿠키는 기본적으로 HTTP, HTTPS 프로토콜에 관계없이 서버에 전달된다. 이 경우 HTTP 요청시 외부의 공격자에게 쿠키 정보를 탈취당할 수 있어 위험하다. secure를 명시하면 HTTPS 프로토콜일 경우에만 쿠키를 전달하여 외부의 공격자로부터 쿠키 정보를 보호할 수 있다.

-> Secure attribute is more straight-forward to understand. A Secure cookie is only sent to the server with an encrypted request over the HTTPS protocol. Note that insecure sites (http:) can't set cookies with the Secure directive.

Set-Cookie: name=value; secure

 

HttpOnly

서버 응답으로 획득한 쿠키는 기본적으로 브라우저의 클라이언트(JavaScript)에서 읽고 수정하는 것이 가능하다. 이 경우 공격자로부터 탈취될 수 있어 위험하다. HttpOnly를 명시하면 클라이언트에서의 접근이 완전히 차단되어 보안을 강화할 수 있다. 사용자 인증에 사용되는 access_token 또는 remember_token은 반드시 secure, HttpOnly을 모두 명시해야 한다.

- > HttpOnly attribute focus is to prevent access to cookie values via JavaScript, mitigation against Cross-site scripting (XSS) attacks.

Set-Cookie: name=value; HttpOnly

 

SameSite

"None"은 동일 사이트과 크로스 사이트에 모두 쿠키 전송이 가능합니다. 그리고 "Strict"로 설정할 경우 서로 다른 도메인에서는 아예 전송이 불가능해 지기 때문에 CSRF를 100% 방지할 수 있으나 사용자 편의성을 많이 해치게 된다. 그래서 Strict 설정에 일부  예외( HTTP get method / a href / link href )를 두어 적용되는 설정이 이번에 기본값으로 변경되는 "Lax이다.

-> Asserts that a cookie must not be sent with cross-origin requests, providing some protection against cross-site request forgery attacks (CSRF). CSRF is mostly related to third party cookies, By “third parties” we mean other websites that we don’t visit directly. The SameSite attribute allows developers to specify cookie security for each particular case.

 

 

728x90
반응형