Skip to content

Commit 45d3722

Browse files
icewind1991backportbot[bot]
authored andcommitted
perf: ignore any customer property in the nc/oc namespace that isn't explicitly allowed
Signed-off-by: Robin Appelman <[email protected]>
1 parent e5c2be1 commit 45d3722

File tree

1 file changed

+21
-39
lines changed

1 file changed

+21
-39
lines changed

apps/dav/lib/DAV/CustomPropertiesBackend.php

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
use OCA\DAV\CalDAV\Calendar;
1212
use OCA\DAV\CalDAV\DefaultCalendarValidator;
1313
use OCA\DAV\Connector\Sabre\Directory;
14-
use OCA\DAV\Connector\Sabre\FilesPlugin;
1514
use OCP\DB\QueryBuilder\IQueryBuilder;
1615
use OCP\IDBConnection;
1716
use OCP\IUser;
@@ -65,38 +64,16 @@ class CustomPropertiesBackend implements BackendInterface {
6564
'{DAV:}getetag',
6665
'{DAV:}quota-used-bytes',
6766
'{DAV:}quota-available-bytes',
68-
'{http://owncloud.org/ns}permissions',
69-
'{http://owncloud.org/ns}downloadURL',
70-
'{http://owncloud.org/ns}dDC',
71-
'{http://owncloud.org/ns}size',
72-
'{http://nextcloud.org/ns}is-encrypted',
73-
74-
// Currently, returning null from any propfind handler would still trigger the backend,
75-
// so we add all known Nextcloud custom properties in here to avoid that
76-
77-
// text app
78-
'{http://nextcloud.org/ns}rich-workspace',
79-
'{http://nextcloud.org/ns}rich-workspace-file',
80-
// groupfolders
81-
'{http://nextcloud.org/ns}acl-enabled',
82-
'{http://nextcloud.org/ns}acl-can-manage',
83-
'{http://nextcloud.org/ns}acl-list',
84-
'{http://nextcloud.org/ns}inherited-acl-list',
85-
'{http://nextcloud.org/ns}group-folder-id',
86-
// files_lock
87-
'{http://nextcloud.org/ns}lock',
88-
'{http://nextcloud.org/ns}lock-owner-type',
89-
'{http://nextcloud.org/ns}lock-owner',
90-
'{http://nextcloud.org/ns}lock-owner-displayname',
91-
'{http://nextcloud.org/ns}lock-owner-editor',
92-
'{http://nextcloud.org/ns}lock-time',
93-
'{http://nextcloud.org/ns}lock-timeout',
94-
'{http://nextcloud.org/ns}lock-token',
95-
// photos
96-
'{http://nextcloud.org/ns}realpath',
97-
'{http://nextcloud.org/ns}nbItems',
98-
'{http://nextcloud.org/ns}face-detections',
99-
'{http://nextcloud.org/ns}face-preview-image',
67+
];
68+
69+
/**
70+
* Allowed properties for the oc/nc namespace, all other properties in the namespace are ignored
71+
*
72+
* @var string[]
73+
*/
74+
private const ALLOWED_NC_PROPERTIES = [
75+
'{http://owncloud.org/ns}calendar-enabled',
76+
'{http://owncloud.org/ns}enabled',
10077
];
10178

10279
/**
@@ -154,14 +131,9 @@ public function __construct(
154131
public function propFind($path, PropFind $propFind) {
155132
$requestedProps = $propFind->get404Properties();
156133

157-
// these might appear
158-
$requestedProps = array_diff(
159-
$requestedProps,
160-
self::IGNORED_PROPERTIES,
161-
);
162134
$requestedProps = array_filter(
163135
$requestedProps,
164-
fn ($prop) => !str_starts_with($prop, FilesPlugin::FILE_METADATA_PREFIX),
136+
$this->isPropertyAllowed(...),
165137
);
166138

167139
// substr of calendars/ => path is inside the CalDAV component
@@ -243,6 +215,16 @@ public function propFind($path, PropFind $propFind) {
243215
}
244216
}
245217

218+
private function isPropertyAllowed(string $property): bool {
219+
if (in_array($property, self::IGNORED_PROPERTIES)) {
220+
return false;
221+
}
222+
if (str_starts_with($property, '{http://owncloud.org/ns}') || str_starts_with($property, '{http://nextcloud.org/ns}')) {
223+
return in_array($property, self::ALLOWED_NC_PROPERTIES);
224+
}
225+
return true;
226+
}
227+
246228
/**
247229
* Updates properties for a path
248230
*

0 commit comments

Comments
 (0)