diff --git a/src/http/modules/ngx_http_dav_module.c b/src/http/modules/ngx_http_dav_module.c index dd960ca27..1e66c2336 100644 --- a/src/http/modules/ngx_http_dav_module.c +++ b/src/http/modules/ngx_http_dav_module.c @@ -539,7 +539,7 @@ static ngx_int_t ngx_http_dav_copy_move_handler(ngx_http_request_t *r) { u_char *p, *host, *last, ch; - size_t len, root; + size_t len, root, alias; ngx_err_t err; ngx_int_t rc, depth; ngx_uint_t overwrite, slash, dir, flags; @@ -649,15 +649,19 @@ destination_done: } clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module); + alias = clcf->alias; - if (clcf->alias - && clcf->alias != NGX_MAX_SIZE_T_VALUE - && duri.len < clcf->alias) - { - ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, - "client sent invalid \"Destination\" header: \"%V\"", - &dest->value); - return NGX_HTTP_BAD_REQUEST; + if (alias && alias != NGX_MAX_SIZE_T_VALUE && r->valid_location) { + + if (alias > duri.len + || ngx_filename_cmp(duri.data, r->uri.data, alias) != 0) + { + ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, + "\"Destination\" URI \"%V\" must be " + "within location prefix when using \"alias\"", + &dest->value); + return NGX_HTTP_BAD_REQUEST; + } } depth = ngx_http_dav_depth(r, NGX_HTTP_DAV_INFINITY_DEPTH); diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c index 504e49eb2..7aa96206f 100644 --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1994,6 +1994,12 @@ ngx_http_map_uri_to_path(ngx_http_request_t *r, ngx_str_t *path, return NULL; } + if (alias > r->uri.len && alias != NGX_MAX_SIZE_T_VALUE) { + ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0, + "URI shorter than aliased URI part"); + return NULL; + } + if (clcf->root_lengths == NULL) { *root_length = clcf->root.len;