From be909c35b0b2ad737b701fde9c63105251800b14 Mon Sep 17 00:00:00 2001 From: Maxim Dounin Date: Mon, 5 Mar 2012 12:49:32 +0000 Subject: Merge of r4473: Core: protection from cycles with named locations and post_action. Now redirects to named locations are counted against normal uri changes limit, and post_action respects this limit as well. As a result at least the following (bad) configurations no longer trigger infinite cycles: 1. Post action which recursively triggers post action: location / { post_action /index.html; } 2. Post action pointing to nonexistent named location: location / { post_action @nonexistent; } 3. Recursive error page for 500 (Internal Server Error) pointing to a nonexistent named location: location / { recursive_error_pages on; error_page 500 @nonexistent; return 500; } --- src/http/ngx_http_core_module.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/http/ngx_http_core_module.c') diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 43e6f56fa..7a1751d06 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -2524,6 +2524,16 @@ ngx_http_named_location(ngx_http_request_t *r, ngx_str_t *name) ngx_http_core_main_conf_t *cmcf; r->main->count++; + r->uri_changes--; + + if (r->uri_changes == 0) { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "rewrite or internal redirection cycle " + "while redirect to named location \"%V\"", name); + + ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); + return NGX_DONE; + } cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module); -- cgit