This commit is contained in:
@@ -12,9 +12,14 @@ $isRetoolPath = ($uriPath === 'retool' || str_starts_with($uriPath, 'retool/'));
|
||||
if (defined('APP_ENV') && APP_ENV === 'staging' && !$isRetoolPath) {
|
||||
$authUser = getenv('STAGING_AUTH_USER') ?: 'staging';
|
||||
$authPass = getenv('STAGING_AUTH_PASS') ?: 'staging123';
|
||||
$remoteUser = $_SERVER['REMOTE_USER'] ?? null;
|
||||
$user = $_SERVER['PHP_AUTH_USER'] ?? null;
|
||||
$pass = $_SERVER['PHP_AUTH_PW'] ?? null;
|
||||
if ($user !== $authUser || $pass !== $authPass) {
|
||||
|
||||
// If Apache already authenticated the request via .htaccess, trust that layer.
|
||||
$hasUpstreamBasicAuth = is_string($remoteUser) && $remoteUser !== '';
|
||||
|
||||
if (!$hasUpstreamBasicAuth && ($user !== $authUser || $pass !== $authPass)) {
|
||||
header('WWW-Authenticate: Basic realm="Staging"');
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
echo 'Unauthorized';
|
||||
|
||||
Reference in New Issue
Block a user