[javascript] SameSite 경고 Chrome 77

마지막 업데이트 이후 SameSite 속성과 관련된 쿠키에 오류가 있습니다.

쿠키는 타사 개발자 (Fontawesome, jQuery, Google Analytics, Google reCaptcha, Google Fonts 등)의 쿠키입니다.

Chrome 콘솔의 오류는 다음과 같습니다.

A cookie associated with a cross-site resource at <URL> was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at <URL> and <URL>.
(index):1 A cookie associated with a cross-site resource at http://jquery.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
(index):1 A cookie associated with a cross-site resource at http://fontawesome.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
(index):1 A cookie associated with a cross-site resource at http://google.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
(index):1 A cookie associated with a cross-site resource at https://google.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
(index):1 A cookie associated with a cross-site resource at https://www.google.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
(index):1 A cookie associated with a cross-site resource at http://www.google.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
(index):1 A cookie associated with a cross-site resource at http://gstatic.com/ was set without the `SameSite` attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set with `SameSite=None` and `Secure`. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.

로컬 컴퓨터 나 서버에서해야 할 일이 있습니까? 아니면 라이브러리의 향후 릴리스에서 구현해야하는 기능일까요?



답변

이 콘솔 경고는 오류나 실제 문제가 아닙니다. Chrome은 개발자의 채택률을 높이기 위해이 새로운 표준에 대해 널리 알리고 있습니다.

코드와 관련이 없습니다. 그것은 뭔가 자신의 웹 서버를 지원해야합니다.

수정 사항의 출시 날짜는 다음과 같이 2020 년 2 월 4 일입니다.
https://www.chromium.org/updates/same-site

2020 년 2 월 : Chrome 80 안정에 대한 시행 롤아웃 : SameSite-by-default 및 SameSite = None-requires-Secure 동작은 2020 년 2 월 17 일 부터 시작되는 초기 제한 인구에 대해 Chrome 80 Stable에 롤아웃하기 시작합니다 . 월요일에 미국 대통령의 날 휴일. 점진적인 롤아웃을 통해 초기 제한 단계에서 생태계 영향을 면밀히 모니터링하고 평가할 것입니다.

전체 Chrome 출시 일정 은 여기를 참조하십시오 .

응답 헤더를 추가하여 동일한 문제를 해결했습니다.

response.setHeader("Set-Cookie", "HttpOnly;Secure;SameSite=Strict");

SameSite브라우저가 사이트 간 요청과 함께 쿠키를 보내지 못하게합니다. 주요 목표는 출처 간 정보 유출의 위험을 줄이는 것입니다. 또한 크로스 사이트 요청 위조 공격에 대한 보호 기능도 제공합니다. 플래그의 가능한 값은 Lax 또는 Strict입니다.

SameSite 쿠키는 여기에 설명

옵션을 적용하기 전에 이것을 참조하십시오 .

이것이 도움이되기를 바랍니다.


답변

localhost에서 테스트 중이고 응답 헤더를 제어 할 수없는 경우 chrome 플래그를 사용하여 비활성화 할 수 있습니다.

URL을 방문하여 비활성화하십시오. chrome : // flags / # same-site-by-default-cookies
쿠키 기본 쿠키 스크린 샷

Chrome Canary가 막 약 V 82.0.4078.2부터이 규칙을 시행하기 시작하여 쿠키를 설정하지 않기 때문에 사용 중지해야합니다.

참고 : 개발에 사용하는 Chrome Canary에서만이 플래그를 설정합니다. Google이 소개하는 것과 같은 이유로 매일 Chrome을 탐색 할 때 플래그를 설정하지 않는 것이 좋습니다.


답변

Rahul Mahadik의 답변을 자세히 설명하기 위해 MVC5 C # .NET에서 작동합니다.

AllowSameSiteAttribute.cs

public class AllowSameSiteAttribute : ActionFilterAttribute
{
    public override void OnActionExecuting(ActionExecutingContext filterContext)
    {
        var response = filterContext.RequestContext.HttpContext.Response;

        if(response != null)
        {
            response.AddHeader("Set-Cookie", "HttpOnly;Secure;SameSite=Strict");
            //Add more headers...
        }

        base.OnActionExecuting(filterContext);
    }
}

HomeController.cs

    [AllowSameSite] //For the whole controller
    public class UserController : Controller
    {
    }

또는

    public class UserController : Controller
    {
        [AllowSameSite] //For the method
        public ActionResult Index()
        {
            return View();
        }
    }


답변

스크립트 태그에 crossorigin을 추가하여 수정했습니다.

보낸 사람 : https://code.jquery.com/

<script
  src="https://code.jquery.com/jquery-3.4.1.min.js"
  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  crossorigin="anonymous"></script>

무결성 및 crossorigin 속성은 SRI (Subresource Integrity) 확인에 사용됩니다. 이를 통해 브라우저는 타사 서버에서 호스팅되는 리소스가 변경되지 않도록 할 수 있습니다. 라이브러리를 타사 소스에서로드 할 때마다 SRI를 사용하는 것이 가장 좋습니다. srihash.org에서 더 읽어보기


답변