Skip to content

Commit 472e430

Browse files
come-ncbackportbot[bot]
authored andcommitted
fix(dav): Allow arrays (of scalars) in property values
Signed-off-by: Côme Chilliet <[email protected]>
1 parent 385f3a5 commit 472e430

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
@@ -426,7 +426,16 @@ private function encodeValueForDatabase($value): array {
426426
$valueType = self::PROPERTY_TYPE_XML;
427427
$value = $value->getXml();
428428
} else {
429-
if (!is_object($value)) {
429+
if (is_array($value)) {
430+
// For array only allow scalar values
431+
foreach ($value as $item) {
432+
if (!is_scalar($item)) {
433+
throw new DavException(
434+
"Property \"$name\" has an invalid value of array containing " . gettype($value),
435+
);
436+
}
437+
}
438+
} elseif (!is_object($value)) {
430439
throw new DavException(
431440
"Property \"$name\" has an invalid value of type " . gettype($value),
432441
);
@@ -453,6 +462,10 @@ private function decodeValueFromDatabase(string $value, int $valueType): mixed {
453462
case self::PROPERTY_TYPE_XML:
454463
return new Complex($value);
455464
case self::PROPERTY_TYPE_OBJECT:
465+
if (preg_match('/^a:/', $value)) {
466+
// Array, unserialize only scalar values
467+
return unserialize(str_replace('\x00', chr(0), $value), ['allowed_classes' => false]);
468+
}
456469
if (!preg_match('/^O\:\d+\:\"(OCA\\\\DAV\\\\|Sabre\\\\(Cal|Card)?DAV\\\\Xml\\\\Property\\\\)/', $value)) {
457470
throw new \LogicException('Found an object class serialized in DB that is not allowed');
458471
}

0 commit comments

Comments
 (0)