From 15ef262863532d9fbe4d35f5b97c21f0b533c346 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 16 Jul 2025 18:49:36 -0400 Subject: [PATCH 1/3] feat(settings): Check for unused data directory Closes #3610 Signed-off-by: Josh --- .../SetupChecks/DataDirectoryProtected.php | 39 +++++++++++++++---- 1 file changed, 32 insertions(+), 7 deletions(-) diff --git a/apps/settings/lib/SetupChecks/DataDirectoryProtected.php b/apps/settings/lib/SetupChecks/DataDirectoryProtected.php index e572c345079..2966e1a2077 100644 --- a/apps/settings/lib/SetupChecks/DataDirectoryProtected.php +++ b/apps/settings/lib/SetupChecks/DataDirectoryProtected.php @@ -33,16 +33,17 @@ class DataDirectoryProtected implements ISetupCheck { } public function getCategory(): string { - return 'network'; + return 'security'; } public function getName(): string { - return $this->l10n->t('Data directory protected'); + return $this->l10n->t('Data directory status'); } public function run(): SetupResult { - $dataDir = str_replace(\OC::$SERVERROOT . '/', '', $this->config->getSystemValueString('datadirectory', '')); - $dataUrl = $this->urlGenerator->linkTo('', $dataDir . '/.ncdata'); + $dataDirActual = $this->config->getSystemValueString('datadirectory', ''); + $dataDirUriPath = str_replace(\OC::$SERVERROOT . '/', '', $dataDirActual); + $dataUrl = $this->urlGenerator->linkTo('', $dataDirUriPath . '/.ncdata'); $noResponse = true; foreach ($this->runRequest('GET', $dataUrl, [ 'httpErrors' => false ]) as $response) { @@ -55,7 +56,11 @@ class DataDirectoryProtected implements ISetupCheck { } if (str_contains($body, '# Nextcloud data directory')) { - return SetupResult::error($this->l10n->t('Your data directory and files are probably accessible from the internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.')); + return SetupResult::error( + $this->l10n->t( + 'Your data directory and files are probably accessible from the Internet. The .htaccess file is not working. It is strongly recommended that you configure your web server so that the data directory is no longer accessible, or move the data directory outside the web server document root.' + ) + ); } } else { $this->logger->debug('[expected] Could not access data directory from outside.', ['url' => $dataUrl]); @@ -63,9 +68,29 @@ class DataDirectoryProtected implements ISetupCheck { } if ($noResponse) { - return SetupResult::warning($this->l10n->t('Could not check that the data directory is protected. Please check manually that your server does not allow access to the data directory.') . "\n" . $this->serverConfigHelp()); + return SetupResult::warning( + $this->l10n->t( + 'Could not check that the data directory is protected. Please check manually that your server does not allow access to the data directory.' + ) + . "\n" + . $this->serverConfigHelp() + ); } - return SetupResult::success(); + + // check for unused /data folder + $dataDirDefault = \OC::$SERVERROOT . '/data'; + if ( $dataDirActual !== $dataDirDefault + && file_exists($dataDirDefault) + ) { + return SetupResult::info( + $this->l10n->t( + 'Dormant data directory found at "%s". You may want to remove this unused directory (to avoid confusion with the in-use one and to free up storage space).', + $dataDirDefault + ) + ); + } + + return SetupResult::success('Protected'); } } From efeac5ddb8d7d2b1dcfe5cb3e95e0315a24b373f Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 16 Jul 2025 19:11:34 -0400 Subject: [PATCH 2/3] fix: add translation to success message Signed-off-by: Josh --- apps/settings/lib/SetupChecks/DataDirectoryProtected.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/apps/settings/lib/SetupChecks/DataDirectoryProtected.php b/apps/settings/lib/SetupChecks/DataDirectoryProtected.php index 2966e1a2077..35f125eea7a 100644 --- a/apps/settings/lib/SetupChecks/DataDirectoryProtected.php +++ b/apps/settings/lib/SetupChecks/DataDirectoryProtected.php @@ -90,7 +90,6 @@ class DataDirectoryProtected implements ISetupCheck { ); } - return SetupResult::success('Protected'); - + return SetupResult::success($this->l10n->t('Protected')); } } From b6cc51437636c52fbab191c99677be6ab2b353b7 Mon Sep 17 00:00:00 2001 From: Josh Date: Wed, 16 Jul 2025 19:15:55 -0400 Subject: [PATCH 3/3] fixup: lint Signed-off-by: Josh --- apps/settings/lib/SetupChecks/DataDirectoryProtected.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/settings/lib/SetupChecks/DataDirectoryProtected.php b/apps/settings/lib/SetupChecks/DataDirectoryProtected.php index 35f125eea7a..9a814afd853 100644 --- a/apps/settings/lib/SetupChecks/DataDirectoryProtected.php +++ b/apps/settings/lib/SetupChecks/DataDirectoryProtected.php @@ -79,7 +79,7 @@ class DataDirectoryProtected implements ISetupCheck { // check for unused /data folder $dataDirDefault = \OC::$SERVERROOT . '/data'; - if ( $dataDirActual !== $dataDirDefault + if ($dataDirActual !== $dataDirDefault && file_exists($dataDirDefault) ) { return SetupResult::info(