Skip to content

Commit a8df5c5

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix(dav): Allow arrays (of scalars) in property values
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
1 parent abbc2f4 commit a8df5c5

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

apps/dav/lib/DAV/CustomPropertiesBackend.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,16 @@ private function encodeValueForDatabase(string $path, string $name, mixed $value
565565
$valueType = self::PROPERTY_TYPE_HREF;
566566
$value = $value->getHref();
567567
} else {
568-
if (!is_object($value)) {
568+
if (is_array($value)) {
569+
// For array only allow scalar values
570+
foreach ($value as $item) {
571+
if (!is_scalar($item)) {
572+
throw new DavException(
573+
"Property \"$name\" has an invalid value of array containing " . gettype($value),
574+
);
575+
}
576+
}
577+
} elseif (!is_object($value)) {
569578
throw new DavException(
570579
"Property \"$name\" has an invalid value of type " . gettype($value),
571580
);
@@ -596,6 +605,10 @@ private function decodeValueFromDatabase(string $value, int $valueType): mixed {
596605
case self::PROPERTY_TYPE_HREF:
597606
return new Href($value);
598607
case self::PROPERTY_TYPE_OBJECT:
608+
if (preg_match('/^a:/', $value)) {
609+
// Array, unserialize only scalar values
610+
return unserialize(str_replace('\x00', chr(0), $value), ['allowed_classes' => false]);
611+
}
599612
if (!preg_match('/^O\:\d+\:\"(OCA\\\\DAV\\\\|Sabre\\\\(Cal|Card)?DAV\\\\Xml\\\\Property\\\\)/', $value)) {
600613
throw new \LogicException('Found an object class serialized in DB that is not allowed');
601614
}

0 commit comments

Comments
 (0)