Skip to content

Commit 2019155

Browse files
liudongmiaoLiu Dongmiao
authored and
Liu Dongmiao
committed
Restore method name for error_page in audit log
Nginx handles `error_page` via `ngx_http_internal_redirect`, and audit log in `ModSecurity-nginx` is trigged in the next handler. In nginx's code, it's harded to `GET` for non-`HEAD`, refers https://github.com/nginx/nginx/blob/master/src/http/ngx_http_special_response.c#L618-L621: ```c if (r->method != NGX_HTTP_HEAD) { r->method = NGX_HTTP_GET; r->method_name = ngx_http_core_get_method; } ``` This patch use `method_name` from `request_line` to fix this issue. This should fix method name in #182, and solve #258.
1 parent 2497e6a commit 2019155

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

Diff for: src/ngx_http_modsecurity_rewrite.c

+11-1
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,17 @@ ngx_http_modsecurity_rewrite_handler(ngx_http_request_t *r)
143143
}
144144

145145
const char *n_uri = ngx_str_to_char(r->unparsed_uri, r->pool);
146-
const char *n_method = ngx_str_to_char(r->method_name, r->pool);
146+
const char *n_method = ngx_str_to_char(r->request_line, r->pool);
147+
if (n_method != NULL && n_method != (char *)-1) {
148+
char *p = (char *) n_method;
149+
while (*p) {
150+
if (*p == ' ') {
151+
*p = '\0';
152+
break;
153+
}
154+
p++;
155+
}
156+
}
147157
if (n_uri == (char*)-1 || n_method == (char*)-1) {
148158
return NGX_HTTP_INTERNAL_SERVER_ERROR;
149159
}

0 commit comments

Comments
 (0)