<div dir="ltr"><div>Hello!</div><div><br></div><div>There is a incident occur in our team, when we use auth_request_set like this in many server, and print $upstream_http_x_auth_request_email in log:</div><div><br></div><div>server {<br>  Â  listen Â  Â  Â  8080 reuseport;<br>  Â  server_name  <a href="http://test.io">test.io</a>;<br>  Â  location / {<br>  Â  Â  Â  auth_request Â  Â  Â  Â  Â  Â /oauth2/auth;<br>  Â  Â  Â  auth_request_set  Â  Â $email $upstream_http_x_auth_request_email;<br>  Â  }<br>}<br></div><div><br></div><div>But when we add a bad auth_request_set like below: </div><div>server {<br>  Â  listen Â  Â  Â  8080 reuseport;<br>  Â  server_name  <a href="http://test2.io">test2.io</a>;<br>  Â  location / {<br>  Â  Â  Â  auth_request Â  Â  Â  Â  Â  Â /oauth2/auth;<br>  Â  Â  Â  auth_request_set  Â  Â  $upstream_http_x_auth_request_email $email;<br>  Â  }<br>}<br></div><div><br></div><div>We will lost all $upstream_http_x_auth_request_email even the server haven't use, because there is a new variable $upstream_http_x_auth_request_email, and the prefix variable can't be read any more.</div><div><br></div><div>So I think we can fix it like this, to avoid the wrong configuration:</div><div><br></div><div><br></div># HG changeset patch<br># User Jinhua Tan <<a href="mailto:312841925@qq.com">312841925@qq.com</a>><br># Date 1611143620 -28800<br># Â  Â  Â Wed Jan 20 19:53:40 2021 +0800<br># Node ID fd7e9432a59abcfcf380ddedb1e892098a54a845<br># Parent Â 61d0df8fcc7c630da35e832ba8e983db0061a3be<br>Http: protect prefix variable when add variable<br><br>diff -r 61d0df8fcc7c -r fd7e9432a59a src/http/ngx_http_variables.c<br>--- a/src/http/ngx_http_variables.c        Tue Jan 19 20:35:17 2021 +0300<br>+++ b/src/http/ngx_http_variables.c     Wed Jan 20 19:53:40 2021 +0800<br>@@ -393,6 +393,20 @@<br> };<br> <br> <br>+static ngx_str_t Â ngx_http_protect_variables_prefix[] = {<br>+ Â  Â ngx_string("arg_"),<br>+ Â  Â ngx_string("http_"),<br>+ Â  Â ngx_string("sent_http_"),<br>+ Â  Â ngx_string("sent_trailer_"),<br>+ Â  Â ngx_string("cookie_"),<br>+ Â  Â ngx_string("arg_"),<br>+ Â  Â ngx_string("upstream_http_"),<br>+ Â  Â ngx_string("upstream_trailer_"),<br>+ Â  Â ngx_string("upstream_cookie_"),<br>+ Â  Â ngx_null_string<br>+};<br>+<br>+<br> ngx_http_variable_value_t Â ngx_http_variable_null_value =<br>  Â  Â ngx_http_variable("");<br> ngx_http_variable_value_t Â ngx_http_variable_true_value =<br>@@ -410,6 +424,7 @@<br>  Â  Â ngx_hash_key_t Â  Â  Â  Â  Â  Â  *key;<br>  Â  Â ngx_http_variable_t Â  Â  Â  Â *v;<br>  Â  Â ngx_http_core_main_conf_t Â *cmcf;<br>+ Â  Â ngx_str_t Â  Â  Â  Â  Â  Â  Â  Â  Â *p;<br> <br>  Â  Â if (name->len == 0) {<br>  Â  Â  Â  Â ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,<br>@@ -421,6 +436,18 @@<br>  Â  Â  Â  Â return ngx_http_add_prefix_variable(cf, name, flags);<br>  Â  Â }<br> <br>+ Â  Â if (flags & NGX_HTTP_VAR_CHANGEABLE) {<br>+ Â  Â  Â  Â for (p = ngx_http_protect_variables_prefix; p->len; p++) {<br>+ Â  Â  Â  Â  Â  Â if (name->len >= p.len<br>+ Â  Â  Â  Â  Â  Â  Â  Â && ngx_strncasecmp(name->data, p->data, p->len) == 0)<br>+ Â  Â  Â  Â  Â  Â {<br>+ Â  Â  Â  Â  Â  Â  Â  Â ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,<br>+ Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  Â  "similar to prefix variable \"%V\"", *p);<br>+ Â  Â  Â  Â  Â  Â  Â  Â return NULL;<br>+ Â  Â  Â  Â  Â  Â }<br>+ Â  Â  Â  Â }<br>+ Â  Â }<br>+<br>  Â  Â cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);<br> <br>  Â  Â key = cmcf->variables_keys->keys.elts;<br></div>