mirror of
https://github.com/nginx/nginx.git
synced 2025-06-28 10:10:39 +08:00
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.
This commit is contained in:
parent
d846f27638
commit
c09bba400d
@ -32,6 +32,7 @@ typedef struct {
|
|||||||
} ngx_http_referer_conf_t;
|
} 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 void * ngx_http_referer_create_conf(ngx_conf_t *cf);
|
||||||
static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
|
static char * ngx_http_referer_merge_conf(ngx_conf_t *cf, void *parent,
|
||||||
void *child);
|
void *child);
|
||||||
@ -77,7 +78,7 @@ static ngx_command_t ngx_http_referer_commands[] = {
|
|||||||
|
|
||||||
|
|
||||||
static ngx_http_module_t ngx_http_referer_module_ctx = {
|
static ngx_http_module_t ngx_http_referer_module_ctx = {
|
||||||
NULL, /* preconfiguration */
|
ngx_http_referer_add_variables, /* preconfiguration */
|
||||||
NULL, /* postconfiguration */
|
NULL, /* postconfiguration */
|
||||||
|
|
||||||
NULL, /* create main configuration */
|
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
|
static ngx_int_t
|
||||||
ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
ngx_http_referer_variable(ngx_http_request_t *r, ngx_http_variable_value_t *v,
|
||||||
uintptr_t data)
|
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 *
|
static void *
|
||||||
ngx_http_referer_create_conf(ngx_conf_t *cf)
|
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;
|
ngx_http_referer_conf_t *rlcf = conf;
|
||||||
|
|
||||||
u_char *p;
|
u_char *p;
|
||||||
ngx_str_t *value, uri, name;
|
ngx_str_t *value, uri;
|
||||||
ngx_uint_t i;
|
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;
|
|
||||||
|
|
||||||
if (rlcf->keys == NULL) {
|
if (rlcf->keys == NULL) {
|
||||||
rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));
|
rlcf->keys = ngx_pcalloc(cf->temp_pool, sizeof(ngx_hash_keys_arrays_t));
|
||||||
|
Loading…
Reference in New Issue
Block a user