Forum: NGINX fix bug in http_referer_module that using incorrect input string length in the regex matching proces

Da5e694a9f814ff9fd6b268b18a4f32d?d=identicon&s=25 Liangbin Li (Guest)
on 2013-08-12 07:27
(Received via mailing list)
--- ngx_http_referer_module.c
+++ ngx_http_referer_module.c
@@ -147,10 +147,12 @@

         if (ngx_strncasecmp(ref, (u_char *) "http://", 7) == 0) {
             ref += 7;
+            len -= 7;
             goto valid_scheme;

         } else if (ngx_strncasecmp(ref, (u_char *) "https://", 8) == 0)
{
             ref += 8;
+            len -= 8;
             goto valid_scheme;
         }
     }
@@ -191,7 +193,7 @@
         ngx_int_t  rc;
         ngx_str_t  referer;

-        referer.len = len - 7;
+        referer.len = len;
         referer.data = ref;

         rc = ngx_regex_exec_array(rlcf->regex, &referer,
r->connection->log);
8a92465c849dda1cd172e8727e5c77d2?d=identicon&s=25 Weibin Yao (yaoweibin)
on 2013-08-12 08:06
(Received via mailing list)
Hi,

In the rerferer module, the length of scheme in regular referer
expression is treated as 'http://'. It's incorrect for the https
request. And the regular referer rule will be invalid. This patch
could fix this bug.

2013/8/12 Liangbin Li <lilb.edwin@gmail.com>:
>              ref += 8;
>          referer.data = ref;
>
>          rc = ngx_regex_exec_array(rlcf->regex, &referer,
> r->connection->log);
>
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx



--
Weibin Yao
Developer @ Server Platform Team of Taobao
5cede995240b2c8749c2e41d13cd33ce?d=identicon&s=25 Sergey Kandaurov (Guest)
on 2013-08-13 17:25
(Received via mailing list)
On Aug 12, 2013, at 9:27 AM, Liangbin Li <lilb.edwin@gmail.com> wrote:
>              ref += 8;
>          referer.data = ref;
>
>          rc = ngx_regex_exec_array(rlcf->regex, &referer, r->connection->log);

Committed, thanks!

--
Sergey Kandaurov
pluknet@nginx.com
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.