Skip to content

Commit 9b63106

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix(dav): Restrict properties allowed object classes
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 4b05eb1 commit 9b63106

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

apps/dav/lib/DAV/CustomPropertiesBackend.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,19 @@ private function encodeValueForDatabase($value): array {
426426
$valueType = self::PROPERTY_TYPE_XML;
427427
$value = $value->getXml();
428428
} else {
429+
if (!is_object($value)) {
430+
throw new DavException(
431+
"Property \"$name\" has an invalid value of type " . gettype($value),
432+
);
433+
}
434+
if (!str_starts_with($value::class, 'Sabre\\DAV\\Xml\\Property\\')
435+
&& !str_starts_with($value::class, 'Sabre\\CalDAV\\Xml\\Property\\')
436+
&& !str_starts_with($value::class, 'Sabre\\CardDAV\\Xml\\Property\\')
437+
&& !str_starts_with($value::class, 'OCA\\DAV\\')) {
438+
throw new DavException(
439+
"Property \"$name\" has an invalid value of class " . $value::class,
440+
);
441+
}
429442
$valueType = self::PROPERTY_TYPE_OBJECT;
430443
$value = serialize($value);
431444
}
@@ -435,16 +448,18 @@ private function encodeValueForDatabase($value): array {
435448
/**
436449
* @return mixed|Complex|string
437450
*/
438-
private function decodeValueFromDatabase(string $value, int $valueType) {
451+
private function decodeValueFromDatabase(string $value, int $valueType): mixed {
439452
switch ($valueType) {
440453
case self::PROPERTY_TYPE_XML:
441454
return new Complex($value);
442455
case self::PROPERTY_TYPE_OBJECT:
456+
if (!preg_match('/^O\:\d+\:\"(OCA\\\\DAV\\\\|Sabre\\\\(Cal|Card)?DAV\\\\Xml\\\\Property\\\\)/', $value)) {
457+
throw new \LogicException('Found an object class serialized in DB that is not allowed');
458+
}
443459
return unserialize($value);
444-
case self::PROPERTY_TYPE_STRING:
445460
default:
446461
return $value;
447-
}
462+
};
448463
}
449464

450465
private function createDeleteQuery(): IQueryBuilder {

0 commit comments

Comments
 (0)