# Fix bug in http\_referer\_module that using incorrect input string length in the regex matching proces

**URL:** <https://www.ruby-forum.com/t/fix-bug-in-http-referer-module-that-using-incorrect-input-string-length-in-the-regex-matching-proces/246032>\
**Category:** NGINX\
**Created:** [August 12, 2013, 7:27am UTC](https://www.ruby-forum.com/t/fix-bug-in-http-referer-module-that-using-incorrect-input-string-length-in-the-regex-matching-proces/246032 "2013-08-12T07:27:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 12, 2013, 7:27am UTC](https://www.ruby-forum.com/t/fix-bug-in-http-referer-module-that-using-incorrect-input-string-length-in-the-regex-matching-proces/246032/1 "2013-08-12T07:27:22Z")

</div>

— 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);

---

<div class="post-metadata">

**Author:** ![Liangbin\_Li](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@Liangbin\_Li](https://www.ruby-forum.com/u/Liangbin_Li)\
**Post date:** [August 12, 2013, 8:06am UTC](https://www.ruby-forum.com/t/fix-bug-in-http-referer-module-that-using-incorrect-input-string-length-in-the-regex-matching-proces/246032/2 "2013-08-12T08:06:32Z")

</div>

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> ```
> ref += 8;
> referer.data = ref;
> 
> rc = ngx_regex_exec_array(rlcf->regex, &referer,
> 
> ```
> 
> r-\>connection-\>log);
> 
> * * *
> 
> nginx mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [mailman.nginx.org archive](http://mailman.nginx.org/mailman/listinfo/nginx)

–  
Weibin Y.  
Developer @ Server Platform Team of Taobao

---

<div class="post-metadata">

**Author:** ![Liangbin\_Li](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/f4b2a3/32.png) [@Liangbin\_Li](https://www.ruby-forum.com/u/Liangbin_Li)\
**Post date:** [August 13, 2013, 5:25pm UTC](https://www.ruby-forum.com/t/fix-bug-in-http-referer-module-that-using-incorrect-input-string-length-in-the-regex-matching-proces/246032/3 "2013-08-13T17:25:34Z")

</div>

On Aug 12, 2013, at 9:27 AM, Liangbin Li [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> ref += 8;
> referer.data = ref;
> 
> rc = ngx_regex_exec_array(rlcf->regex, &referer, r->connection->log);
> 
> ```

Committed, thanks!

–  
Sergey Kandaurov  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
