Nginx – Add SameSite to Cookies Using Nginx as Reverse Proxy

cookiesnginxreverse-proxyrewrite

With Nginx as reverse proxy, how do you add samesite=strict or samesite=lax to cookies?

Best Answer

With this code you can define all your application cookies as secure, httponly and/or samesite using proxy_cookie_path (http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cookie_path)

location / {
        # your usual config ...
        # hack, set all cookies to secure, httponly and samesite (strict or lax)
        proxy_cookie_path / "/; secure; HttpOnly; SameSite=strict";
    }