Skip to content

Commit a211af9

Browse files
authored
Merge pull request #54425 from nextcloud/backport/54411/stable31
[stable31] perf: ignore any custom property in the nc/oc namespace that isn't explicitly allowed
2 parents c9f404a + 45d3722 commit a211af9

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

10380
/**
@@ -155,14 +132,9 @@ public function __construct(
155132
public function propFind($path, PropFind $propFind) {
156133
$requestedProps = $propFind->get404Properties();
157134

158-
// these might appear
159-
$requestedProps = array_diff(
160-
$requestedProps,
161-
self::IGNORED_PROPERTIES,
162-
);
163135
$requestedProps = array_filter(
164136
$requestedProps,
165-
fn ($prop) => !str_starts_with($prop, FilesPlugin::FILE_METADATA_PREFIX),
137+
$this->isPropertyAllowed(...),
166138
);
167139

168140
// substr of calendars/ => path is inside the CalDAV component
@@ -249,6 +221,16 @@ public function propFind($path, PropFind $propFind) {
249221
}
250222
}
251223

224+
private function isPropertyAllowed(string $property): bool {
225+
if (in_array($property, self::IGNORED_PROPERTIES)) {
226+
return false;
227+
}
228+
if (str_starts_with($property, '{http://owncloud.org/ns}') || str_starts_with($property, '{http://nextcloud.org/ns}')) {
229+
return in_array($property, self::ALLOWED_NC_PROPERTIES);
230+
}
231+
return true;
232+
}
233+
252234
/**
253235
* Updates properties for a path
254236
*

0 commit comments

Comments
 (0)