Check if variable is set, more accurate error description

This commit is contained in:
Marc Ole Bulling 2022-01-14 15:55:57 +01:00 committed by GitHub
parent d82fafe722
commit af24c402ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,12 +24,19 @@ class ReverseProxyAuthMiddleware extends AuthMiddleware
if (GROCY_REVERSE_PROXY_AUTH_USE_ENV) if (GROCY_REVERSE_PROXY_AUTH_USE_ENV)
{ {
if (!isset($_SERVER[GROCY_REVERSE_PROXY_AUTH_HEADER]))
{
// Variable is not set
throw new \Exception('ReverseProxyAuthMiddleware: ' . GROCY_REVERSE_PROXY_AUTH_HEADER . ' env variable is missing, could not be found in $_SERVER array.');
}
$username = $_SERVER[GROCY_REVERSE_PROXY_AUTH_HEADER]; $username = $_SERVER[GROCY_REVERSE_PROXY_AUTH_HEADER];
if (strlen($username) === 0) if (strlen($username) === 0)
{ {
// Invalid configuration of Proxy // Variable is empty
throw new \Exception('ReverseProxyAuthMiddleware: ' . GROCY_REVERSE_PROXY_AUTH_HEADER . ' header is missing or invalid'); throw new \Exception('ReverseProxyAuthMiddleware: ' . GROCY_REVERSE_PROXY_AUTH_HEADER . ' env variable is invalid');
} }
} else { } else {
$username = $request->getHeader(GROCY_REVERSE_PROXY_AUTH_HEADER); $username = $request->getHeader(GROCY_REVERSE_PROXY_AUTH_HEADER);
if (count($username) !== 1) if (count($username) !== 1)