]> git.kaiwu.me - nginx.git/commitdiff
Realip: fixed duplicate processing on redirects (ticket #1098).
authorMaxim Dounin <mdounin@mdounin.ru>
Thu, 6 Oct 2016 20:16:05 +0000 (23:16 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Thu, 6 Oct 2016 20:16:05 +0000 (23:16 +0300)
Duplicate processing was possible if the address set by realip was
listed in set_realip_from, and there was an internal redirect so module
context was cleared.  This resulted in exactly the same address being set,
so this wasn't a problem before the $realip_remote_addr variable was
introduced, though now results in incorrect $realip_remote_addr being
picked.

Fix is to use ngx_http_realip_get_module_ctx() to look up module context
even if it was cleared.  Additionally, the order of checks was switched to
check the configuration first as it looks more effective.

src/http/modules/ngx_http_realip_module.c

index dba3c527b2008923560ca66b0241f0bb4cdc74f9..5e3355c96713b634679aa0b06bde1f1117c26aa4 100644 (file)
@@ -141,15 +141,15 @@ ngx_http_realip_handler(ngx_http_request_t *r)
     ngx_http_realip_ctx_t       *ctx;
     ngx_http_realip_loc_conf_t  *rlcf;
 
-    ctx = ngx_http_get_module_ctx(r, ngx_http_realip_module);
+    rlcf = ngx_http_get_module_loc_conf(r, ngx_http_realip_module);
 
-    if (ctx) {
+    if (rlcf->from == NULL) {
         return NGX_DECLINED;
     }
 
-    rlcf = ngx_http_get_module_loc_conf(r, ngx_http_realip_module);
+    ctx = ngx_http_realip_get_module_ctx(r);
 
-    if (rlcf->from == NULL) {
+    if (ctx) {
         return NGX_DECLINED;
     }