Skip to content

Commit c7651c7

Browse files
committed
waf feature: use the real client's address & port
1 parent ddfcaf0 commit c7651c7

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/ngx_http_modsecurity_rewrite.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222

2323

2424
ngx_int_t ngx_http_modsecurity_process_connection(ngx_http_request_t *r,
25-
ngx_http_modsecurity_ctx_t *ctx);
25+
ngx_http_modsecurity_ctx_t *ctx,
26+
const char *client_addr, in_port_t client_port);
2627
ngx_int_t ngx_http_modsecurity_process_url(ngx_http_request_t *r,
2728
ngx_http_modsecurity_ctx_t *ctx,
2829
const char *uri, const char *method, const char *http_version);
@@ -57,7 +58,7 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
5758
return rc;
5859
}
5960

60-
rc = ngx_http_modsecurity_process_connection(r, ctx);
61+
rc = ngx_http_modsecurity_process_connection(r, ctx, NULL, 0);
6162
if (rc > 0) {
6263
return rc;
6364
}
@@ -83,24 +84,21 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
8384

8485
ngx_int_t
8586
ngx_http_modsecurity_process_connection(ngx_http_request_t *r,
86-
ngx_http_modsecurity_ctx_t *ctx)
87+
ngx_http_modsecurity_ctx_t *ctx,
88+
const char *client_addr, in_port_t client_port)
8789
{
88-
in_port_t client_port, server_port;
90+
in_port_t server_port;
8991
ngx_int_t rc;
90-
ngx_str_t client_addr, server_addr;
92+
ngx_str_t server_addr;
9193
ngx_pool_t *old_pool;
9294
ngx_connection_t *c;
9395
u_char addr[NGX_SOCKADDR_STRLEN + 1];
9496

9597
c = r->connection;
9698

97-
client_addr = c->addr_text;
98-
client_port = ngx_inet_get_port(c->sockaddr);
99-
100-
if (client_addr.len < c->listening->addr_text_max_len) {
101-
client_addr.data[client_addr.len] = 0;
102-
} else {
103-
client_addr.data = (u_char *)ngx_str_to_char(client_addr, r->pool);
99+
if (client_addr == NULL) {
100+
client_addr = ngx_str_to_char(c->addr_text, r->pool);
101+
client_port = ngx_inet_get_port(c->sockaddr);
104102
}
105103

106104
// fill c->local_sockaddr
@@ -116,7 +114,7 @@ ngx_http_modsecurity_process_connection(ngx_http_request_t *r,
116114

117115
old_pool = ngx_http_modsecurity_pcre_malloc_init(r->pool);
118116
rc = msc_process_connection(ctx->modsec_transaction,
119-
(char *)client_addr.data, client_port,
117+
client_addr, client_port,
120118
(char *)server_addr.data, server_port);
121119
ngx_http_modsecurity_pcre_malloc_done(old_pool);
122120
if (rc != 1){

0 commit comments

Comments
 (0)