Welcome! Log In Create A New Profile

Advanced

[nginx] Referer: fixed $invalid_referer.

August 04, 2017 01:04AM
details: http://hg.nginx.org/nginx/rev/7564a919d333
branches:
changeset: 7079:7564a919d333
user: Ruslan Ermilov <ru@nginx.com>
date: Fri Aug 04 08:01:55 2017 +0300
description:
Referer: fixed $invalid_referer.

The variable was considered non-existent in the absence of any
valid_referers directives.

Given the following config snippet,

location / {
return 200 $invalid_referer;
}

location /referer {
valid_referers server_names;
}

"location /" should work identically and independently on other
"location /referer".

The fix is to always add the $invalid_referer variable as long
as the module is compiled in, as is done by other modules.

diffstat:

src/http/modules/ngx_http_referer_module.c | 39 +++++++++++++++++++----------
1 files changed, 25 insertions(+), 14 deletions(-)

diffs (77 lines):

diff -r 1eb753aa8e5e -r 7564a919d333 src/http/modules/ngx_http_referer_module.c
--- a/src/http/modules/ngx_http_referer_module.c Tue Aug 01 19:12:10 2017 +0300
+++ b/src/http/modules/ngx_http_referer_module.c Fri Aug 04 08:01:55 2017 +0300
@@ -32,6 +32,7 @@ typedef struct {
} ngx_http_referer_conf_t;


+static ngx_int_t ngx_http_referer_add_variables(ngx_conf_t *cf);
static void * ngx_http_referer_create_conf(ngx_conf_t *cf);
static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
void *child);
@@ -77,7 +78,7 @@ static ngx_command_t ngx_http_referer_c


static ngx_http_module_t ngx_http_referer_module_ctx = {
- NULL, /* preconfiguration */
+ ngx_http_referer_add_variables, /* preconfiguration */
NULL, /* postconfiguration */

NULL, /* create main configuration */
@@ -107,6 +108,9 @@ ngx_module_t ngx_http_referer_module =
};


+static ngx_str_t ngx_http_invalid_referer_name = ngx_string("invalid_referer");
+
+
static ngx_int_t
ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
uintptr_t data)
@@ -263,6 +267,23 @@ valid:
}


+static ngx_int_t
+ngx_http_referer_add_variables(ngx_conf_t *cf)
+{
+ ngx_http_variable_t *var;
+
+ var = ngx_http_add_variable(cf, &ngx_http_invalid_referer_name,
+ NGX_HTTP_VAR_CHANGEABLE);
+ if (var == NULL) {
+ return NGX_ERROR;
+ }
+
+ var->get_handler = ngx_http_referer_variable;
+
+ return NGX_OK;
+}
+
+
static void *
ngx_http_referer_create_conf(ngx_conf_t *cf)
{
@@ -452,19 +473,9 @@ ngx_http_valid_referers(ngx_conf_t *cf,
{
ngx_http_referer_conf_t *rlcf = conf;

- u_char *p;
- ngx_str_t *value, uri, name;
- ngx_uint_t i;
- ngx_http_variable_t *var;
-
- ngx_str_set(&name, "invalid_referer");
-
- var = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
- if (var == NULL) {
- return NGX_CONF_ERROR;
- }
-
- var->get_handler = ngx_http_referer_variable;
+ u_char *p;
+ ngx_str_t *value, uri;
+ ngx_uint_t i;

if (rlcf->keys == NULL) {
rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[nginx] Referer: fixed $invalid_referer.

ru@nginx.com 704 August 04, 2017 01:04AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 300
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready