aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorFerdinand Thiessen <opensource@fthiessen.de>2024-08-27 14:06:23 +0200
committerFerdinand Thiessen <opensource@fthiessen.de>2024-08-28 20:23:54 +0200
commitef3bd0384918022458e57d593a8292549194074c (patch)
treedd641776f5a831e234fba248306267511a863b32 /lib/private
parent183fcef39b40608e931f6470ef48182c657bd918 (diff)
downloadnextcloud-server-ef3bd0384918022458e57d593a8292549194074c.tar.gz
nextcloud-server-ef3bd0384918022458e57d593a8292549194074c.zip
fix: Allow read-only filename validation to allow reading files
Needed to read files with the "Windows compatibility" feature. Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/Files/View.php13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/private/Files/View.php b/lib/private/Files/View.php
index 0e5e433ccb6..d8b240d5b11 100644
--- a/lib/private/Files/View.php
+++ b/lib/private/Files/View.php
@@ -1826,15 +1826,26 @@ class View {
/**
* @param string $path
* @param string $fileName
+ * @param bool $readonly Check only if the path is allowed for read-only access
* @throws InvalidPathException
*/
- public function verifyPath($path, $fileName): void {
+ public function verifyPath($path, $fileName, $readonly = false): void {
// All of the view's functions disallow '..' in the path so we can short cut if the path is invalid
if (!Filesystem::isValidPath($path ?: '/')) {
$l = \OCP\Util::getL10N('lib');
throw new InvalidPathException($l->t('Path contains invalid segments'));
}
+ // Short cut for read-only validation
+ if ($readonly) {
+ $validator = \OCP\Server::get(FilenameValidator::class);
+ if ($validator->isForbidden($fileName)) {
+ $l = \OCP\Util::getL10N('lib');
+ throw new InvalidPathException($l->t('Filename is a reserved word'));
+ }
+ return;
+ }
+
try {
/** @type \OCP\Files\Storage $storage */
[$storage, $internalPath] = $this->resolvePath($path);