From 82736dbad9f66d8179394790589cf9a4f967ffe4 Mon Sep 17 00:00:00 2001 From: Hayden Zhou Date: Wed, 21 May 2025 15:56:47 +0800 Subject: [PATCH] Auth basic: check if file of auth_basic_user_file can be open. Fixed #557 by check if the file can be open, this fix only check if file path that do not contain nginx variable. --- src/http/modules/ngx_http_auth_basic_module.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/http/modules/ngx_http_auth_basic_module.c b/src/http/modules/ngx_http_auth_basic_module.c index 02d41e88a..4bd437059 100644 --- a/src/http/modules/ngx_http_auth_basic_module.c +++ b/src/http/modules/ngx_http_auth_basic_module.c @@ -404,6 +404,7 @@ ngx_http_auth_basic_user_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) ngx_str_t *value; ngx_http_compile_complex_value_t ccv; + ngx_file_info_t fi; if (alcf->user_file != NGX_CONF_UNSET_PTR) { return "is duplicate"; @@ -428,5 +429,13 @@ ngx_http_auth_basic_user_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf) return NGX_CONF_ERROR; } + if (alcf->user_file->lengths == NULL && + ngx_file_info(alcf->user_file->value.data, &fi) + == NGX_FILE_ERROR) { + ngx_conf_log_error(NGX_LOG_WARN, cf, ngx_errno, + ngx_file_info_n " \"%s\" failed", + alcf->user_file->value.data); + } + return NGX_CONF_OK; }