Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/ngx_http_modsecurity_access.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ ngx_http_modsecurity_access_handler(ngx_http_request_t *r)
int server_port = ngx_inet_get_port(connection->local_sockaddr);

const char *client_addr = ngx_str_to_char(addr_text, r->pool);
if (client_addr == (char*)-1) {
if (client_addr == (char*)-1 || client_addr == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

Expand Down Expand Up @@ -155,7 +155,7 @@ ngx_http_modsecurity_access_handler(ngx_http_request_t *r)
}

const char *server_addr = ngx_str_to_char(s, r->pool);
if (server_addr == (char*)-1) {
if (server_addr == (char*)-1 || server_addr == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

Expand Down Expand Up @@ -259,11 +259,16 @@ ngx_http_modsecurity_access_handler(ngx_http_request_t *r)
*/

dd("Adding request header: %.*s with value %.*s", (int)data[i].key.len, data[i].key.data, (int) data[i].value.len, data[i].value.data);
msc_add_n_request_header(ctx->modsec_transaction,
if (msc_add_n_request_header(ctx->modsec_transaction,
(const unsigned char *) data[i].key.data,
data[i].key.len,
(const unsigned char *) data[i].value.data,
data[i].value.len);
data[i].value.len) != 1)
{
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
"ModSecurity: failed to add request header \"%V\" "
"for inspection", &data[i].key);
}
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/ngx_http_modsecurity_body_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ ngx_http_modsecurity_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
&ngx_http_modsecurity_module, NGX_HTTP_INTERNAL_SERVER_ERROR);

}

/*
* msc_process_response_body() is a one-shot finalize. A filter
* upstream of us (sub_filter, gzip, ...) may append a trailing
* buffer after the last_buf link in the same chain; without this
* break we'd loop into it and call msc_append_response_body()
* again on an already-finalized transaction. The full chain is
* still forwarded below regardless of where we stop inspecting.
*/
break;
}
}
if (!is_request_processed)
Expand Down
28 changes: 22 additions & 6 deletions src/ngx_http_modsecurity_header_filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,11 +321,16 @@ ngx_http_modsecurity_resolv_header_connection(ngx_http_request_t *r, ngx_str_t n
ngx_http_modsecurity_store_ctx_header(r, &name2, &value);
#endif

msc_add_n_response_header(ctx->modsec_transaction,
if (msc_add_n_response_header(ctx->modsec_transaction,
(const unsigned char *) name2.data,
name2.len,
(const unsigned char *) value.data,
value.len);
value.len) != 1)
{
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
"ModSecurity: failed to add response header "
"\"%V\" for inspection", &name2);
}
}
} else {
connection = "close";
Expand Down Expand Up @@ -475,9 +480,15 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
(int) ngx_http_modsecurity_headers_out[i].name.len,
ngx_http_modsecurity_headers_out[i].name.data);

ngx_http_modsecurity_headers_out[i].resolver(r,
if (ngx_http_modsecurity_headers_out[i].resolver(r,
ngx_http_modsecurity_headers_out[i].name,
ngx_http_modsecurity_headers_out[i].offset);
ngx_http_modsecurity_headers_out[i].offset) != 1)
{
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
"ModSecurity: failed to add response header "
"\"%V\" for inspection",
&ngx_http_modsecurity_headers_out[i].name);
}
}

for (i = 0 ;; i++)
Expand All @@ -500,11 +511,16 @@ ngx_http_modsecurity_header_filter(ngx_http_request_t *r)
/*
* Doing this ugly cast here, explanation on the request_header
*/
msc_add_n_response_header(ctx->modsec_transaction,
if (msc_add_n_response_header(ctx->modsec_transaction,
(const unsigned char *) data[i].key.data,
data[i].key.len,
(const unsigned char *) data[i].value.data,
data[i].value.len);
data[i].value.len) != 1)
{
ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
"ModSecurity: failed to add response header \"%V\" "
"for inspection", &data[i].key);
}
}

/* prepare extra paramters for msc_process_response_headers() */
Expand Down
Loading