<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>