Skip to content

Commit 3d82ee2

Browse files
turchanovFelipe Zimmerle
authored and
Felipe Zimmerle
committed
Fix incorrect handling of request/response body
Fix incorrect handling of request/response body data chain of ngx_buf_t buffers. The documentation [http://nginx.org/en/docs/dev/development_guide.html#buffer] clearly states that .pos, .last must be used to reference actual data contained by the buffer. Whereas .start, .end denote the boundaries of the memory block allocated for the buffer (in case of dynamically allocated data) or just NULL (when .pos, .last reference a static memory location - one can see that kind of usage in ngx_http_gzip_filter_module.c:ngx_http_gzip_filter_gzheader()). To back up my words I invite to examine ngx_http_charset_filter_module.c:ngx_http_charset_recode() as an example of iteration over data contained in data buffer. Without this fix ngx_http_modsecurity_body_filter feeds random bytes from memory pointed by .start, .end range to msc_append_response_body. In my case is was 8KB of data instead of 10 bytes when referenced by (.pos, .last). That is this vulnerability may disclose sensitive data like passwords or whatever from nginx heap. The fix for ngx_http_modsecurity_pre_access_handler is to use .pos not .start to reference data as they may differ in general case.
1 parent 831d82a commit 3d82ee2

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

Diff for: src/ngx_http_modsecurity_body_filter.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,9 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
150150

151151
for (chain = in; chain != NULL; chain = chain->next)
152152
{
153-
u_char *data = chain->buf->start;
153+
u_char *data = chain->buf->pos;
154154

155-
msc_append_response_body(ctx->modsec_transaction, data, chain->buf->end - data);
155+
msc_append_response_body(ctx->modsec_transaction, data, chain->buf->last - data);
156156
ret = ngx_http_modsecurity_process_intervention(ctx->modsec_transaction, r);
157157
if (ret > 0) {
158158
return ngx_http_filter_finalize_request(r,

Diff for: src/ngx_http_modsecurity_pre_access.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ ngx_http_modsecurity_pre_access_handler(ngx_http_request_t *r)
163163

164164
while (chain && !already_inspected)
165165
{
166-
u_char *data = chain->buf->start;
166+
u_char *data = chain->buf->pos;
167167

168168
msc_append_request_body(ctx->modsec_transaction, data,
169-
chain->buf->last - chain->buf->pos);
169+
chain->buf->last - data);
170170

171171
if (chain->buf->last_buf) {
172172
break;

0 commit comments

Comments
 (0)