Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add new forbidden filename options to Capabilities #46414

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions apps/files/lib/Capabilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,31 @@
*/
namespace OCA\Files;

use OC\Files\FilenameValidator;
susnux marked this conversation as resolved.
Show resolved Hide resolved
use OCP\Capabilities\ICapability;
use OCP\IConfig;

class Capabilities implements ICapability {

protected IConfig $config;

public function __construct(IConfig $config) {
$this->config = $config;
public function __construct(
protected FilenameValidator $filenameValidator,
) {
}

/**
* Return this classes capabilities
*
* @return array{files: array{bigfilechunking: bool, blacklisted_files: array<mixed>, forbidden_filename_characters: array<string>}}
* @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>}}
*/
public function getCapabilities() {
public function getCapabilities(): array {
return [
'files' => [
'$comment' => '"blacklisted_files" is deprecated as of Nextcloud 30, use "forbidden_filenames" instead',
'blacklisted_files' => $this->filenameValidator->getForbiddenFilenames(),
'forbidden_filenames' => $this->filenameValidator->getForbiddenFilenames(),
'forbidden_filename_characters' => $this->filenameValidator->getForbiddenCharacters(),
'forbidden_filename_extensions' => $this->filenameValidator->getForbiddenExtensions(),

'bigfilechunking' => true,
'blacklisted_files' => (array)$this->config->getSystemValue('blacklisted_files', ['.htaccess']),
'forbidden_filename_characters' => \OCP\Util::getForbiddenFileNameChars(),
],
];
}
Expand Down
19 changes: 19 additions & 0 deletions apps/files/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,19 @@
"files": {
"type": "object",
"required": [
"$comment",
"bigfilechunking",
"blacklisted_files",
"forbidden_filenames",
"forbidden_filename_characters",
"forbidden_filename_extensions",
"directEditing"
],
"properties": {
"$comment": {
"type": "string",
"nullable": true
},
"bigfilechunking": {
"type": "boolean"
},
Expand All @@ -44,12 +51,24 @@
"type": "object"
}
},
"forbidden_filenames": {
"type": "array",
"items": {
"type": "string"
}
},
"forbidden_filename_characters": {
"type": "array",
"items": {
"type": "string"
}
},
"forbidden_filename_extensions": {
"type": "array",
"items": {
"type": "string"
}
},
"directEditing": {
"type": "object",
"required": [
Expand Down
4 changes: 3 additions & 1 deletion build/integration/features/bootstrap/CapabilitiesContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class CapabilitiesContext implements Context, SnippetAcceptingContext {
* @param \Behat\Gherkin\Node\TableNode|null $formData
*/
public function checkCapabilitiesResponse(\Behat\Gherkin\Node\TableNode $formData) {
$capabilitiesXML = simplexml_load_string($this->response->getBody())->data->capabilities;
$capabilitiesXML = simplexml_load_string($this->response->getBody());
Assert::assertNotFalse($capabilitiesXML, 'Failed to fetch capabilities');
$capabilitiesXML = $capabilitiesXML->data->capabilities;

foreach ($formData->getHash() as $row) {
$path_to_element = explode('@@@', $row['path_to_element']);
Expand Down
5 changes: 4 additions & 1 deletion core/Controller/OCJSController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use bantu\IniGetWrapper\IniGetWrapper;
use OC\Authentication\Token\IProvider;
use OC\CapabilitiesManager;
use OC\Files\FilenameValidator;
use OC\Template\JSConfigHelper;
use OCP\App\IAppManager;
use OCP\AppFramework\Controller;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function __construct(
CapabilitiesManager $capabilitiesManager,
IInitialStateService $initialStateService,
IProvider $tokenProvider,
FilenameValidator $filenameValidator,
) {
parent::__construct($appName, $request);

Expand All @@ -59,7 +61,8 @@ public function __construct(
$urlGenerator,
$capabilitiesManager,
$initialStateService,
$tokenProvider
$tokenProvider,
$filenameValidator,
);
}

Expand Down
4 changes: 3 additions & 1 deletion lib/private/AppFramework/OCS/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ protected function toXML(array $array, \XMLWriter $writer): void {
$v = [];
}

if (\is_array($v)) {
if ($k === '$comment') {
$writer->writeComment($v);
} elseif (\is_array($v)) {
$writer->startElement($k);
$this->toXML($v, $writer);
$writer->endElement();
Expand Down
9 changes: 7 additions & 2 deletions lib/private/Template/JSConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use bantu\IniGetWrapper\IniGetWrapper;
use OC\Authentication\Token\IProvider;
use OC\CapabilitiesManager;
use OC\Files\FilenameValidator;
use OC\Share\Share;
use OCP\App\AppPathNotFoundException;
use OCP\App\IAppManager;
Expand Down Expand Up @@ -51,6 +52,7 @@ public function __construct(
protected CapabilitiesManager $capabilitiesManager,
protected IInitialStateService $initialStateService,
protected IProvider $tokenProvider,
protected FilenameValidator $filenameValidator,
) {
}

Expand Down Expand Up @@ -132,9 +134,12 @@ public function getConfig(): string {
$capabilities = $this->capabilitiesManager->getCapabilities(false, true);

$config = [
'auto_logout' => $this->config->getSystemValue('auto_logout', false),
/** @deprecated 30.0.0 - use files capabilities instead */
'blacklist_files_regex' => FileInfo::BLACKLIST_FILES_REGEX,
'forbidden_filename_characters' => Util::getForbiddenFileNameChars(),
/** @deprecated 30.0.0 - use files capabilities instead */
'forbidden_filename_characters' => $this->filenameValidator->getForbiddenCharacters(),

'auto_logout' => $this->config->getSystemValue('auto_logout', false),
'loglevel' => $this->config->getSystemValue('loglevel_frontend',
$this->config->getSystemValue('loglevel', ILogger::WARN)
),
Expand Down
2 changes: 2 additions & 0 deletions lib/private/TemplateLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

use bantu\IniGetWrapper\IniGetWrapper;
use OC\Authentication\Token\IProvider;
use OC\Files\FilenameValidator;
use OC\Search\SearchQuery;
use OC\Template\CSSResourceLocator;
use OC\Template\JSConfigHelper;
Expand Down Expand Up @@ -228,6 +229,7 @@ public function __construct($renderAs, $appId = '') {
\OC::$server->get(CapabilitiesManager::class),
\OCP\Server::get(IInitialStateService::class),
\OCP\Server::get(IProvider::class),
\OCP\Server::get(FilenameValidator::class),
);
$config = $jsConfigHelper->getConfig();
if (\OC::$server->getContentSecurityPolicyNonceManager()->browserSupportsCspV3()) {
Expand Down
Loading