Skip to content

Commit 994dc7b

Browse files
committed
feat: Add new forbidden filename options to JS config for frontend validation
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent d33f34b commit 994dc7b

2 files changed

Lines changed: 19 additions & 9 deletions

File tree

apps/files/lib/Capabilities.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,31 @@
77
*/
88
namespace OCA\Files;
99

10+
use OC\Files\FilenameValidator;
1011
use OCP\Capabilities\ICapability;
11-
use OCP\IConfig;
1212

1313
class Capabilities implements ICapability {
1414

15-
protected IConfig $config;
16-
17-
public function __construct(IConfig $config) {
18-
$this->config = $config;
15+
public function __construct(
16+
protected FilenameValidator $filenameValidator,
17+
) {
1918
}
2019

2120
/**
2221
* Return this classes capabilities
2322
*
24-
* @return array{files: array{bigfilechunking: bool, blacklisted_files: array<mixed>, forbidden_filename_characters: array<string>}}
23+
* @return array{files: array{$comment: string, bigfilechunking: bool, blacklisted_files: array<mixed>, forbidden_filenames: list<string>, forbidden_filename_characters: list<string>, forbidden_filename_extensions: list<string>}}
2524
*/
2625
public function getCapabilities() {
2726
return [
2827
'files' => [
28+
'$comment' => '"blacklisted_files" is deprecacted as of Nextcloud 30, use "forbidden_filenames" instead',
29+
'blacklisted_files' => $this->filenameValidator->getForbiddenFilenames(),
30+
'forbidden_filenames' => $this->filenameValidator->getForbiddenFilenames(),
31+
'forbidden_filename_characters' => $this->filenameValidator->getForbiddenCharacters(),
32+
'forbidden_filename_extensions' => $this->filenameValidator->getForbiddenExtensions(),
33+
2934
'bigfilechunking' => true,
30-
'blacklisted_files' => (array)$this->config->getSystemValue('blacklisted_files', ['.htaccess']),
31-
'forbidden_filename_characters' => \OCP\Util::getForbiddenFileNameChars(),
3235
],
3336
];
3437
}

lib/private/Template/JSConfigHelper.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use bantu\IniGetWrapper\IniGetWrapper;
1111
use OC\Authentication\Token\IProvider;
1212
use OC\CapabilitiesManager;
13+
use OC\Files\FilenameValidator;
1314
use OC\Share\Share;
1415
use OCP\App\AppPathNotFoundException;
1516
use OCP\App\IAppManager;
@@ -51,6 +52,7 @@ public function __construct(
5152
protected CapabilitiesManager $capabilitiesManager,
5253
protected IInitialStateService $initialStateService,
5354
protected IProvider $tokenProvider,
55+
protected FilenameValidator $filenameValidator,
5456
) {
5557
}
5658

@@ -133,8 +135,13 @@ public function getConfig(): string {
133135

134136
$config = [
135137
'auto_logout' => $this->config->getSystemValue('auto_logout', false),
138+
/** @deprecated 30.0.0 */
136139
'blacklist_files_regex' => FileInfo::BLACKLIST_FILES_REGEX,
137-
'forbidden_filename_characters' => Util::getForbiddenFileNameChars(),
140+
141+
'forbidden_filenames' => $this->filenameValidator->getForbiddenFilenames(),
142+
'forbidden_filename_characters' => $this->filenameValidator->getForbiddenCharacters(),
143+
'forbidden_filename_extensions' => $this->filenameValidator->getForbiddenExtensions(),
144+
138145
'loglevel' => $this->config->getSystemValue('loglevel_frontend',
139146
$this->config->getSystemValue('loglevel', ILogger::WARN)
140147
),

0 commit comments

Comments
 (0)