From 3c55ae6d3fbf186efb8f13bd3fe14f04dbcd8a28 Mon Sep 17 00:00:00 2001 From: Ilya Shevyrev Date: Tue, 10 Mar 2020 09:18:59 +0100 Subject: [PATCH 1/3] SameSite=none added --- README.md | 4 ++-- ngx_http_cookie_flag_filter_module.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e8e71fc..504d047 100644 --- a/README.md +++ b/README.md @@ -52,11 +52,11 @@ It is possible to set a default value using symbol "*". In this case flags will -| - --- | --- -**Syntax** | **set_cookie_flag** \ [HttpOnly] [secure] [SameSite\|SameSite=[Lax\|Strict]]; +**Syntax** | **set_cookie_flag** \ [HttpOnly] [secure] [SameSite\|SameSite=[Lax\|Strict|none]]; **Default** | - **Context** | server, location Description: Add flag to desired cookie. ## Author -Anton Saraykin [] \ No newline at end of file +Anton Saraykin [] diff --git a/ngx_http_cookie_flag_filter_module.c b/ngx_http_cookie_flag_filter_module.c index b0316aa..1398695 100644 --- a/ngx_http_cookie_flag_filter_module.c +++ b/ngx_http_cookie_flag_filter_module.c @@ -12,6 +12,7 @@ typedef struct { ngx_flag_t samesite; ngx_flag_t samesite_lax; ngx_flag_t samesite_strict; + ngx_flag_t samesite_none; } ngx_http_cookie_t; typedef struct { @@ -165,6 +166,7 @@ ngx_http_cookie_flag_filter_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) cookie->samesite = 0; cookie->samesite_lax = 0; cookie->samesite_strict = 0; + cookie->samesite_none = 0; // normalize and check 2nd and 3rd parameters for (i = 2; i < cf->args->nelts; i++) { @@ -178,6 +180,8 @@ ngx_http_cookie_flag_filter_cmd(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) cookie->samesite_lax = 1; } else if (ngx_strncasecmp(value[i].data, (u_char *) "samesite=strict", 15) == 0 && value[i].len == 15) { cookie->samesite_strict = 1; + } else if (ngx_strncasecmp(value[i].data, (u_char *) "samesite=none", 13) == 0 && value[i].len == 13) { + cookie->samesite_none = 1; } else { ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "The parameter value \"%V\" is incorrect", &value[i]); return NGX_CONF_ERROR; @@ -287,6 +291,16 @@ ngx_http_cookie_flag_filter_append(ngx_http_request_t *r, ngx_http_cookie_t *coo header->value.len = tmp.len; } + if (cookie->samesite_none == 1 && ngx_strcasestrn(header->value.data, "; SameSite=none", 15 - 1) == NULL) { + tmp.data = ngx_pnalloc(r->pool, header->value.len + sizeof("; SameSite=none") - 1); + if (tmp.data == NULL) { + return NGX_ERROR; + } + tmp.len = ngx_sprintf(tmp.data, "%V; SameSite=none", &header->value) - tmp.data; + header->value.data = tmp.data; + header->value.len = tmp.len; + } + return NGX_OK; } From 267b78719203a32e85ee0d2c7accc564824397bd Mon Sep 17 00:00:00 2001 From: Ilya Shevyrev Date: Tue, 10 Mar 2020 11:04:48 +0100 Subject: [PATCH 2/3] num arg to 4 --- ngx_http_cookie_flag_filter_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx_http_cookie_flag_filter_module.c b/ngx_http_cookie_flag_filter_module.c index 1398695..a91a8d7 100644 --- a/ngx_http_cookie_flag_filter_module.c +++ b/ngx_http_cookie_flag_filter_module.c @@ -2,7 +2,7 @@ #include #include -#define NUM_FLAGS 3 +#define NUM_FLAGS 4 #define MIN_ARGS 3 typedef struct { From 9c26cb71042484a2bf96c59889b8000e0ad71b6a Mon Sep 17 00:00:00 2001 From: Ilya Shevyrev Date: Tue, 10 Mar 2020 11:20:15 +0100 Subject: [PATCH 3/3] num arg to 3 --- ngx_http_cookie_flag_filter_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ngx_http_cookie_flag_filter_module.c b/ngx_http_cookie_flag_filter_module.c index a91a8d7..1398695 100644 --- a/ngx_http_cookie_flag_filter_module.c +++ b/ngx_http_cookie_flag_filter_module.c @@ -2,7 +2,7 @@ #include #include -#define NUM_FLAGS 4 +#define NUM_FLAGS 3 #define MIN_ARGS 3 typedef struct {