]> source.dussan.org Git - nextcloud-server.git/commitdiff
chore(dav): Make json_encode and json_decode throw on error 36254/head
authorChristoph Wurst <christoph@winzerhof-wurst.at>
Thu, 19 Jan 2023 18:19:22 +0000 (19:19 +0100)
committerChristoph Wurst <christoph@winzerhof-wurst.at>
Thu, 19 Jan 2023 18:19:22 +0000 (19:19 +0100)
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
apps/dav/lib/BackgroundJob/UpdateCalendarResourcesRoomsBackgroundJob.php
apps/dav/lib/BulkUpload/BulkUploadPlugin.php
apps/dav/lib/CalDAV/ResourceBooking/AbstractPrincipalBackend.php
apps/dav/lib/Comments/CommentsPlugin.php
apps/dav/lib/Connector/Sabre/FilesPlugin.php
apps/dav/lib/SystemTag/SystemTagPlugin.php
apps/dav/lib/UserMigration/ContactsMigrator.php

index f7addd58248c7d21d415b7e0eab7f51058a7dfb4..f0ff16d3f2fb93f0b4cd44f6e5938eb205cdc7f2 100644 (file)
@@ -339,7 +339,7 @@ class UpdateCalendarResourcesRoomsBackgroundJob extends TimedJob {
         * @return string
         */
        private function serializeGroupRestrictions(array $groups): string {
-               return \json_encode($groups);
+               return \json_encode($groups, JSON_THROW_ON_ERROR);
        }
 
        /**
index 0d5cce88d0df76799e551ebf6cab94384fa8ebc9..dab4bbffc6e8d3f8399484d189a9d3c2564a4938 100644 (file)
@@ -75,7 +75,7 @@ class BulkUploadPlugin extends ServerPlugin {
                                // Return early if an error occurs during parsing.
                                $this->logger->error($e->getMessage());
                                $response->setStatus(Http::STATUS_BAD_REQUEST);
-                               $response->setBody(json_encode($writtenFiles));
+                               $response->setBody(json_encode($writtenFiles, JSON_THROW_ON_ERROR));
                                return false;
                        }
 
@@ -109,7 +109,7 @@ class BulkUploadPlugin extends ServerPlugin {
                }
 
                $response->setStatus(Http::STATUS_OK);
-               $response->setBody(json_encode($writtenFiles));
+               $response->setBody(json_encode($writtenFiles, JSON_THROW_ON_ERROR));
 
                return false;
        }
index 6fd69b7e3dfa13d75cf32ce0dc6ca6a358eca1a1..d2ad4cafb981cfa45890fb0ea20d7a5b25a990fe 100644 (file)
@@ -522,7 +522,7 @@ abstract class AbstractPrincipalBackend implements BackendInterface {
                }
 
                // group restrictions contains something, but not parsable, deny access and log warning
-               $json = json_decode($row['group_restrictions']);
+               $json = json_decode($row['group_restrictions'], null, 512, JSON_THROW_ON_ERROR);
                if (!\is_array($json)) {
                        $this->logger->info('group_restrictions field could not be parsed for ' . $this->dbTableName . '::' . $row['id'] . ', denying access to resource');
                        return false;
index a49327518979c8aef9220160dc71b1d41d7cac37..f31e479c2120a44c7421fb2e82622ca68956de97 100644 (file)
@@ -220,7 +220,7 @@ class CommentsPlugin extends ServerPlugin {
         */
        private function createComment($objectType, $objectId, $data, $contentType = 'application/json') {
                if (explode(';', $contentType)[0] === 'application/json') {
-                       $data = json_decode($data, true);
+                       $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
                } else {
                        throw new UnsupportedMediaType();
                }
index 54919824864a7cad0c8102457b15249cc1053bfc..f53c62afba27e5ffcdbf11f480f68386bbc4d8db 100644 (file)
@@ -321,11 +321,11 @@ class FilesPlugin extends ServerPlugin {
                                        $user->getUID()
                                );
                                $ocmPermissions = $this->ncPermissions2ocmPermissions($ncPermissions);
-                               return json_encode($ocmPermissions);
+                               return json_encode($ocmPermissions, JSON_THROW_ON_ERROR);
                        });
 
                        $propFind->handle(self::SHARE_ATTRIBUTES_PROPERTYNAME, function () use ($node, $httpRequest) {
-                               return json_encode($node->getShareAttributes());
+                               return json_encode($node->getShareAttributes(), JSON_THROW_ON_ERROR);
                        });
 
                        $propFind->handle(self::GETETAG_PROPERTYNAME, function () use ($node): string {
@@ -350,7 +350,7 @@ class FilesPlugin extends ServerPlugin {
                        });
 
                        $propFind->handle(self::HAS_PREVIEW_PROPERTYNAME, function () use ($node) {
-                               return json_encode($this->previewManager->isAvailable($node->getFileInfo()));
+                               return json_encode($this->previewManager->isAvailable($node->getFileInfo()), JSON_THROW_ON_ERROR);
                        });
                        $propFind->handle(self::SIZE_PROPERTYNAME, function () use ($node): ?int {
                                return $node->getSize();
@@ -422,7 +422,7 @@ class FilesPlugin extends ServerPlugin {
                        if ($this->config->getSystemValueBool('enable_file_metadata', true)) {
                                $propFind->handle(self::FILE_METADATA_SIZE, function () use ($node) {
                                        if (!str_starts_with($node->getFileInfo()->getMimetype(), 'image')) {
-                                               return json_encode((object)[]);
+                                               return json_encode((object)[], JSON_THROW_ON_ERROR);
                                        }
 
                                        if ($node->hasMetadata('size')) {
@@ -438,7 +438,7 @@ class FilesPlugin extends ServerPlugin {
                                                \OC::$server->get(LoggerInterface::class)->debug('Inefficient fetching of metadata');
                                        }
 
-                                       return json_encode((object)$sizeMetadata->getMetadata());
+                                       return json_encode((object)$sizeMetadata->getMetadata(), JSON_THROW_ON_ERROR);
                                });
                        }
                }
index b6bd7d3b7cdb9c5325a992d44a838d6639eeb27a..c21935edfdc3a2d121383c672f66a6812a2b2fc6 100644 (file)
@@ -163,7 +163,7 @@ class SystemTagPlugin extends \Sabre\DAV\ServerPlugin {
         */
        private function createTag($data, $contentType = 'application/json') {
                if (explode(';', $contentType)[0] === 'application/json') {
-                       $data = json_decode($data, true);
+                       $data = json_decode($data, true, 512, JSON_THROW_ON_ERROR);
                } else {
                        throw new UnsupportedMediaType();
                }
index d2ba82eb2e5e3e8cf19efa1368ed1bc36b06d918..196d0a6110a8f8854ade1a0fc048d0680c04cee8 100644 (file)
@@ -248,7 +248,7 @@ class ContactsMigrator implements IMigrator, ISizeEstimationMigrator {
                                $exportDestination->addFileContents($exportPath, $this->serializeCards($vCards));
 
                                $metadata = array_filter(['displayName' => $displayName, 'description' => $description]);
-                               $exportDestination->addFileContents($metadataExportPath, json_encode($metadata));
+                               $exportDestination->addFileContents($metadataExportPath, json_encode($metadata, JSON_THROW_ON_ERROR));
                        }
                } catch (Throwable $e) {
                        throw new CalendarMigratorException('Could not export address book', 0, $e);