aboutsummaryrefslogtreecommitdiff
path: root/src/http/modules/ngx_http_referer_module.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2017-08-04 08:01:55 +0300
committerRuslan Ermilov <ru@nginx.com>2017-08-04 08:01:55 +0300
commitc09bba400d233331f1b405e18c6912a30502dee9 (patch)
tree84fddc2eb166e397cab2ba5362b3b9ed9fe97074 /src/http/modules/ngx_http_referer_module.c
parentd846f27638525f478ea07f5574b5569ce2ab1ac2 (diff)
downloadnginx-c09bba400d233331f1b405e18c6912a30502dee9.tar.gz
nginx-c09bba400d233331f1b405e18c6912a30502dee9.zip
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 (limited to 'src/http/modules/ngx_http_referer_module.c')
-rw-r--r--src/http/modules/ngx_http_referer_module.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/src/http/modules/ngx_http_referer_module.c b/src/http/modules/ngx_http_referer_module.c
index 3f0f78e11..599dd3a12 100644
--- a/src/http/modules/ngx_http_referer_module.c
+++ b/src/http/modules/ngx_http_referer_module.c
@@ -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_commands[] = {
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_command_t *cmd, void *conf)
{
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));