Skip to content

Commit 63ac4fa

Browse files
committed
Add explicit handling for empty auth/whitelist arrays
When no auths or whitelists exist for a site, explicitly remove all related htpasswd/whitelist files (including wildcards and aliases) and return early. This makes the cleanup behavior more explicit rather than silently iterating over an empty array. Signed-off-by: Riddhesh Sanghvi <riddhesh237@gmail.com>
1 parent 3e7027c commit 63ac4fa

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

src/Auth_Command.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,15 @@ private function generate_site_auth_files( string $site_url, $site_data = null )
340340
// Remove duplicates (e.g., *.example.com alias + subdomain multisite both create _wildcard.example.com)
341341
$domains = array_unique( $domains );
342342

343+
// If no auths exist, remove all htpasswd files for this site and its domains
344+
if ( empty( $auths ) ) {
345+
foreach ( $domains as $domain ) {
346+
$domain_auth_file = EE_ROOT_DIR . '/services/nginx-proxy/htpasswd/' . $domain;
347+
$this->fs->remove( $domain_auth_file );
348+
}
349+
return;
350+
}
351+
343352
// Generate htpasswd files for all collected domains
344353
foreach ( $domains as $domain ) {
345354
$domain_auth_file = EE_ROOT_DIR . '/services/nginx-proxy/htpasswd/' . $domain;
@@ -436,6 +445,15 @@ private function generate_site_whitelist( string $site_url, $site_data = null )
436445
'ip'
437446
);
438447

448+
// If no whitelists exist, remove all whitelist files for this site and its domains
449+
if ( empty( $whitelists ) ) {
450+
foreach ( $domains as $domain ) {
451+
$domain_whitelist_file = EE_ROOT_DIR . '/services/nginx-proxy/vhost.d/' . $domain . '_acl';
452+
$this->fs->remove( $domain_whitelist_file );
453+
}
454+
return;
455+
}
456+
439457
// Generate whitelist files for all collected domains
440458
foreach ( $domains as $domain ) {
441459
$domain_whitelist_file = EE_ROOT_DIR . '/services/nginx-proxy/vhost.d/' . $domain . '_acl';

0 commit comments

Comments
 (0)