Skip to content

cookie-flag: NGINX cookie flag module

Installation

CentOS/RHEL 6, 7, 8 or Amazon Linux 2

yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install nginx-module-cookie-flag

Enable the module by adding the following at the top of /etc/nginx/nginx.conf:

load_module modules/ngx_http_cookie_flag_filter_module.so;

This document describes nginx-module-cookie-flag v1.1.0 released on Dec 15 2017.


License

The Nginx module for adding cookie flag

Synopsis

location / {
    set_cookie_flag Secret HttpOnly secure SameSite;
    set_cookie_flag * HttpOnly;
    set_cookie_flag SessionID SameSite=Lax secure;
    set_cookie_flag SiteToken SameSite=Strict;
}

Description

This module for Nginx allows to set the flags "HttpOnly", "secure" and "SameSite" for cookies in the "Set-Cookie" response headers. The register of letters for the flags doesn't matter as it will be converted to the correct value. The order of cookie declaration among multiple directives doesn't matter too. It is possible to set a default value using symbol "*". In this case flags will be added to the all cookies if no other value for them is overriden.

Directives

- -
Syntax set_cookie_flag \<cookie_name|*> [HttpOnly][secure] [SameSite|SameSite=[Lax|Strict]];
Default -
Context server, location

Description: Add flag to desired cookie.

Author

Anton Saraykin [Airisenator@gmail.com]

GitHub

You may find additional configuration tips and documentation for this module in the GitHub repository for nginx-module-cookie-flag.

Back to top