From 5f573a4993177a1050ffc1eb0554d0fc93019320 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:44:18 +0000 Subject: [PATCH 1/9] fix(api): reject ambiguous file input combinations (#9435) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> From 2f543f5e716a9a947443bef37db10d2c77c6159f Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:45:02 +0000 Subject: [PATCH 2/9] test(api): cover mutually exclusive file input formats (#9435) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- .../FileControllerInputSourceTest.php | 144 ++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 tests/php/Unit/Controller/FileControllerInputSourceTest.php diff --git a/tests/php/Unit/Controller/FileControllerInputSourceTest.php b/tests/php/Unit/Controller/FileControllerInputSourceTest.php new file mode 100644 index 0000000000..d5a65ea478 --- /dev/null +++ b/tests/php/Unit/Controller/FileControllerInputSourceTest.php @@ -0,0 +1,144 @@ + $name, + 'tmp_name' => '/tmp/upload-placeholder', + 'type' => 'application/pdf', + 'size' => 3, + 'error' => UPLOAD_ERR_OK, + ]; + } + + private static function batch(): array { + return [ + 'name' => ['first.pdf', 'second.pdf'], + 'tmp_name' => ['/tmp/first', '/tmp/second'], + 'type' => ['application/pdf', 'application/pdf'], + 'size' => [3, 4], + 'error' => [UPLOAD_ERR_OK, UPLOAD_ERR_OK], + ]; + } + + public static function acceptedInputs(): array { + return [ + 'JSON single reference' => [['nodeId' => 1], [], null, null, [['nodeId' => 1]]], + 'JSON reference list' => [[], [['nodeId' => 1], ['nodeId' => 2]], null, null, [['nodeId' => 1], ['nodeId' => 2]]], + 'single multipart file' => [[], [], self::upload('one.pdf'), null, [ + ['uploadedFile' => self::upload('one.pdf'), 'name' => 'one'], + ]], + 'multipart list under files' => [[], [], null, self::batch(), [ + ['uploadedFile' => self::uploadFromBatch(0), 'name' => 'first'], + ['uploadedFile' => self::uploadFromBatch(1), 'name' => 'second'], + ]], + 'legacy multipart list under file' => [[], [], self::batch(), null, [ + ['uploadedFile' => self::uploadFromBatch(0), 'name' => 'first'], + ['uploadedFile' => self::uploadFromBatch(1), 'name' => 'second'], + ]], + ]; + } + + private static function uploadFromBatch(int $index): array { + $batch = self::batch(); + return array_map(static fn (array $column): mixed => $column[$index], $batch); + } + + public static function conflictingInputs(): array { + return [ + 'both JSON forms' => [['nodeId' => 1], [['nodeId' => 2]], null, null], + 'both multipart fields' => [[], [], self::upload('one.pdf'), self::batch()], + 'JSON file plus multipart file' => [['nodeId' => 1], [], self::upload('one.pdf'), null], + 'JSON files plus multipart files' => [[], [['nodeId' => 1]], null, self::batch()], + ]; + } + + private function controller(): FileController { + $reflection = new ReflectionClass(FileController::class); + /** @var FileController $controller */ + $controller = $reflection->newInstanceWithoutConstructor(); + + $l10n = $this->createMock(IL10N::class); + $l10n->method('t')->willReturnCallback(static fn (string $message): string => $message); + $reflection->getProperty('l10n')->setValue($controller, $l10n); + + $fileService = $this->createMock(FileService::class); + $reflection->getProperty('fileService')->setValue($controller, $fileService); + + $validator = $this->createMock(FileInputValidator::class); + $validator->method('normalizeNodeId')->willReturnCallback(static fn (array $file): array => $file); + $reflection->getProperty('fileInputValidator')->setValue($controller, $validator); + return $controller; + } + + #[DataProvider('acceptedInputs')] + public function testAcceptsOneFileInputSource(array $file, array $files, ?array $singleUpload, ?array $batchUpload, array $expected): void { + $controller = $this->controller(); + $result = (new ReflectionMethod(FileController::class, 'prepareFilesForSaving')) + ->invoke($controller, $file, $files, [], $singleUpload, $batchUpload); + self::assertSame($expected, $result); + } + + #[DataProvider('conflictingInputs')] + public function testRejectsAmbiguousFileInputs(array $file, array $files, ?array $singleUpload, ?array $batchUpload): void { + $controller = $this->controller(); + $this->expectException(LibresignException::class); + $this->expectExceptionMessage('Use only one file input format per request'); + (new ReflectionMethod(FileController::class, 'prepareFilesForSaving')) + ->invoke($controller, $file, $files, [], $singleUpload, $batchUpload); + } + + public function testConflictingMultipartInputReturns422WithoutSaving(): void { + $controller = $this->controller(); + $reflection = new ReflectionClass(FileController::class); + + $request = $this->createMock(IRequest::class); + $request->method('getUploadedFile')->willReturnMap([ + ['file', self::upload('one.pdf')], + ['files', self::batch()], + ]); + $reflection->getProperty('request')->setValue($controller, $request); + + $user = $this->createMock(IUser::class); + $userSession = $this->createMock(IUserSession::class); + $userSession->method('getUser')->willReturn($user); + $reflection->getProperty('userSession')->setValue($controller, $userSession); + + $signingValidator = $this->createMock(SigningRequestValidator::class); + $signingValidator->expects($this->once())->method('canRequestSign')->with($user); + $reflection->getProperty('signingRequestValidator')->setValue($controller, $signingValidator); + + $requestSignatureService = $this->createMock(RequestSignatureService::class); + $requestSignatureService->expects($this->never())->method('saveFiles'); + $reflection->getProperty('requestSignatureService')->setValue($controller, $requestSignatureService); + + $response = $controller->save(); + self::assertSame(Http::STATUS_UNPROCESSABLE_ENTITY, $response->getStatus()); + self::assertSame('Use only one file input format per request', $response->getData()['message']); + } +} From 6eb6ced17132348cc20a18d0bc2a36ebbe6045a1 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:48:12 +0000 Subject: [PATCH 3/9] chore(openapi): regenerate file-save descriptions (#9435) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> From d22ff768862acdc2140273471e0f817d9e1abb0f Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:51:32 +0000 Subject: [PATCH 4/9] test(api): compare multipart metadata independently of key insertion order (#9435) test(api): compare multipart metadata independently of key insertion order (#9435) Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> [skip ci] --- .../Unit/Controller/FileControllerInputSourceTest.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/php/Unit/Controller/FileControllerInputSourceTest.php b/tests/php/Unit/Controller/FileControllerInputSourceTest.php index d5a65ea478..b18d9da4fc 100644 --- a/tests/php/Unit/Controller/FileControllerInputSourceTest.php +++ b/tests/php/Unit/Controller/FileControllerInputSourceTest.php @@ -101,7 +101,14 @@ public function testAcceptsOneFileInputSource(array $file, array $files, ?array $controller = $this->controller(); $result = (new ReflectionMethod(FileController::class, 'prepareFilesForSaving')) ->invoke($controller, $file, $files, [], $singleUpload, $batchUpload); - self::assertSame($expected, $result); + // PHP file entries are associative maps: key insertion order is not contractual. + $sortUploadKeys = static function (array $entry): array { + if (isset($entry['uploadedFile'])) { + ksort($entry['uploadedFile']); + } + return $entry; + }; + self::assertSame(array_map($sortUploadKeys, $expected), array_map($sortUploadKeys, $result)); } #[DataProvider('conflictingInputs')] From fb3f6e83a19bde951f0e499a5c1790b8156c97fb Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:18:00 +0000 Subject: [PATCH 5/9] fix(api): adapt exclusive input validation to stable33 controller Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- lib/Controller/FileController.php | 19 +++++++++++++++---- .../FileControllerInputSourceTest.php | 11 ++++------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/Controller/FileController.php b/lib/Controller/FileController.php index 97d25327c5..4cf1dd73d1 100644 --- a/lib/Controller/FileController.php +++ b/lib/Controller/FileController.php @@ -534,7 +534,9 @@ private function getMimeFallbackResponse(string $mimeType): ?\OCP\AppFramework\H * Send a file * * Send a new file to Nextcloud and return the fileId to request signature. - * Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. + * File references can be sent as JSON using 'file' (single) or 'files' (list). + * Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; + * the legacy 'file[]' field is also accepted. Do not combine these input forms. * * **Note on multiple file uploads:** * PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). @@ -563,7 +565,9 @@ public function save( try { $this->validateHelper->canRequestSign($this->userSession->getUser()); - $normalizedFiles = $this->prepareFilesForSaving($file, $files, $settings); + $singleUploadedFile = $this->request->getUploadedFile('file'); + $multipleUploadedFiles = $this->request->getUploadedFile('files'); + $normalizedFiles = $this->prepareFilesForSaving($file, $files, $settings, $singleUploadedFile, $multipleUploadedFiles); return $this->saveFiles($normalizedFiles, $name, $settings); } catch (LibresignException $e) { @@ -705,8 +709,15 @@ private function prepareFileForSaving(array $fileData, string $name, array $sett /** * @return list Normalized files array */ - private function prepareFilesForSaving(array $file, array $files, array $settings): array { - $uploadedFiles = $this->request->getUploadedFile('files') ?: $this->request->getUploadedFile('file'); + private function prepareFilesForSaving(array $file, array $files, array $settings, ?array $singleUploadedFile, ?array $multipleUploadedFiles): array { + if (($file && $files) + || ($singleUploadedFile && $multipleUploadedFiles) + || (($file || $files) && ($singleUploadedFile || $multipleUploadedFiles))) { + // TRANSLATORS Error shown when a file upload mixes mutually exclusive input formats. + throw new LibresignException($this->l10n->t('Use only one file input format per request')); + } + + $uploadedFiles = $multipleUploadedFiles ?: $singleUploadedFile; if ($uploadedFiles) { return $this->processUploadedFiles($uploadedFiles); diff --git a/tests/php/Unit/Controller/FileControllerInputSourceTest.php b/tests/php/Unit/Controller/FileControllerInputSourceTest.php index b18d9da4fc..76a16e817a 100644 --- a/tests/php/Unit/Controller/FileControllerInputSourceTest.php +++ b/tests/php/Unit/Controller/FileControllerInputSourceTest.php @@ -13,8 +13,7 @@ use OCA\Libresign\Exception\LibresignException; use OCA\Libresign\Service\FileService; use OCA\Libresign\Service\RequestSignatureService; -use OCA\Libresign\Service\Validation\FileInputValidator; -use OCA\Libresign\Service\Validation\SigningRequestValidator; +use OCA\Libresign\Helper\ValidateHelper; use OCP\AppFramework\Http; use OCP\IL10N; use OCP\IRequest; @@ -90,9 +89,7 @@ private function controller(): FileController { $fileService = $this->createMock(FileService::class); $reflection->getProperty('fileService')->setValue($controller, $fileService); - $validator = $this->createMock(FileInputValidator::class); - $validator->method('normalizeNodeId')->willReturnCallback(static fn (array $file): array => $file); - $reflection->getProperty('fileInputValidator')->setValue($controller, $validator); + $reflection->getProperty('validateHelper')->setValue($controller, $this->createMock(ValidateHelper::class)); return $controller; } @@ -136,9 +133,9 @@ public function testConflictingMultipartInputReturns422WithoutSaving(): void { $userSession->method('getUser')->willReturn($user); $reflection->getProperty('userSession')->setValue($controller, $userSession); - $signingValidator = $this->createMock(SigningRequestValidator::class); + $signingValidator = $this->createMock(ValidateHelper::class); $signingValidator->expects($this->once())->method('canRequestSign')->with($user); - $reflection->getProperty('signingRequestValidator')->setValue($controller, $signingValidator); + $reflection->getProperty('validateHelper')->setValue($controller, $signingValidator); $requestSignatureService = $this->createMock(RequestSignatureService::class); $requestSignatureService->expects($this->never())->method('saveFiles'); From 9278f9599466a1ee4daaa0a41cf1f82ef76a1f71 Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:20:08 +0000 Subject: [PATCH 6/9] chore(openapi): synchronize generated file input descriptions on stable33 Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- openapi-full.json | 2 +- openapi.json | 2 +- src/types/openapi/openapi-full.ts | 2 +- src/types/openapi/openapi.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/openapi-full.json b/openapi-full.json index 2d0f10eea5..e8722ae53d 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -6016,7 +6016,7 @@ "post": { "operationId": "file-save", "summary": "Send a file", - "description": "Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", + "description": "Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", "tags": [ "file" ], diff --git a/openapi.json b/openapi.json index ea3e85080a..bae71d7258 100644 --- a/openapi.json +++ b/openapi.json @@ -5392,7 +5392,7 @@ "post": { "operationId": "file-save", "summary": "Send a file", - "description": "Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", + "description": "Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", "tags": [ "file" ], diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 0528459922..891ca9bcde 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -598,7 +598,7 @@ export type paths = { put?: never; /** * Send a file - * @description Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. + * @description Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms. * **Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does. */ post: operations["file-save"]; diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 379ec0dd42..351bf85ae5 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -598,7 +598,7 @@ export type paths = { put?: never; /** * Send a file - * @description Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. + * @description Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms. * **Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does. */ post: operations["file-save"]; From c63787c891683b9109eb03c1ccf083cd1b9bfd4b Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:21:50 +0000 Subject: [PATCH 7/9] style(test): order stable33 validation imports Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- tests/php/Unit/Controller/FileControllerInputSourceTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/php/Unit/Controller/FileControllerInputSourceTest.php b/tests/php/Unit/Controller/FileControllerInputSourceTest.php index 76a16e817a..aeb160b11e 100644 --- a/tests/php/Unit/Controller/FileControllerInputSourceTest.php +++ b/tests/php/Unit/Controller/FileControllerInputSourceTest.php @@ -11,9 +11,9 @@ use OCA\Libresign\Controller\FileController; use OCA\Libresign\Exception\LibresignException; +use OCA\Libresign\Helper\ValidateHelper; use OCA\Libresign\Service\FileService; use OCA\Libresign\Service\RequestSignatureService; -use OCA\Libresign\Helper\ValidateHelper; use OCP\AppFramework\Http; use OCP\IL10N; use OCP\IRequest; From 6378c026fe7babe326303538c31252b7a5fba42d Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:07:17 +0000 Subject: [PATCH 8/9] fix(api): reconcile exclusive file-source checks with stable33 upload handling Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- lib/Controller/FileController.php | 57 +++++++++++++------ .../FileControllerInputSourceTest.php | 8 ++- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/lib/Controller/FileController.php b/lib/Controller/FileController.php index 4cf1dd73d1..2d6de86d83 100644 --- a/lib/Controller/FileController.php +++ b/lib/Controller/FileController.php @@ -534,9 +534,8 @@ private function getMimeFallbackResponse(string $mimeType): ?\OCP\AppFramework\H * Send a file * * Send a new file to Nextcloud and return the fileId to request signature. - * File references can be sent as JSON using 'file' (single) or 'files' (list). - * Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; - * the legacy 'file[]' field is also accepted. Do not combine these input forms. + * Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. + * Multipart clients can send optional expectedFilesCount to reject incomplete batches. * * **Note on multiple file uploads:** * PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). @@ -564,10 +563,13 @@ public function save( ): DataResponse { try { $this->validateHelper->canRequestSign($this->userSession->getUser()); + $this->assertExclusiveFileInputSources($file, $files, $this->request->getUploadedFile('file'), $this->request->getUploadedFile('files')); - $singleUploadedFile = $this->request->getUploadedFile('file'); - $multipleUploadedFiles = $this->request->getUploadedFile('files'); - $normalizedFiles = $this->prepareFilesForSaving($file, $files, $settings, $singleUploadedFile, $multipleUploadedFiles); + $uploadedFiles = $this->request->getUploadedFile('files') ?: $this->request->getUploadedFile('file'); + $normalizedFiles = $this->prepareFilesForSaving($file, $files, $settings, $uploadedFiles); + if ($uploadedFiles) { + $this->assertExpectedUploadedFileCount(count($normalizedFiles)); + } return $this->saveFiles($normalizedFiles, $name, $settings); } catch (LibresignException $e) { @@ -585,6 +587,7 @@ public function save( * * Add one or more files to an existing envelope that is in DRAFT status. * Files must be uploaded as multipart/form-data with field name 'files[]'. + * Multipart clients can send optional expectedFilesCount to reject incomplete batches. * * @param string $uuid The UUID of the envelope * @return DataResponse|DataResponse @@ -621,6 +624,7 @@ public function addFileToEnvelope(string $uuid): DataResponse { } $normalizedFiles = $this->processUploadedFiles($uploadedFiles); + $this->assertExpectedUploadedFileCount(count($normalizedFiles)); $addedFiles = []; foreach ($normalizedFiles as $fileData) { @@ -709,16 +713,7 @@ private function prepareFileForSaving(array $fileData, string $name, array $sett /** * @return list Normalized files array */ - private function prepareFilesForSaving(array $file, array $files, array $settings, ?array $singleUploadedFile, ?array $multipleUploadedFiles): array { - if (($file && $files) - || ($singleUploadedFile && $multipleUploadedFiles) - || (($file || $files) && ($singleUploadedFile || $multipleUploadedFiles))) { - // TRANSLATORS Error shown when a file upload mixes mutually exclusive input formats. - throw new LibresignException($this->l10n->t('Use only one file input format per request')); - } - - $uploadedFiles = $multipleUploadedFiles ?: $singleUploadedFile; - + private function prepareFilesForSaving(array $file, array $files, array $settings, ?array $uploadedFiles): array { if ($uploadedFiles) { return $this->processUploadedFiles($uploadedFiles); } @@ -735,6 +730,24 @@ private function prepareFilesForSaving(array $file, array $files, array $setting throw new LibresignException($this->l10n->t('File or files parameter is required')); } + /** + * Detect uploads silently truncated by PHP's max_file_uploads limit. + * Clients may omit the count for backwards compatibility. + */ + private function assertExpectedUploadedFileCount(int $receivedCount): void { + $declaredCount = $this->request->getParam('expectedFilesCount'); + if ($declaredCount === null) { + return; + } + if ((!is_string($declaredCount) && !is_int($declaredCount)) + || !ctype_digit((string)$declaredCount) + || (string)(int)$declaredCount !== (string)$declaredCount + || (int)$declaredCount !== $receivedCount) { + // TRANSLATORS Error shown when the number of uploaded documents differs from the count declared by the client. + throw new LibresignException($this->l10n->t('The number of uploaded files does not match the expected count')); + } + } + /** * @return list */ @@ -774,6 +787,18 @@ private function processUploadedFiles(array $uploadedFiles): array { return $filesArray; } + /** + * Reject ambiguous request payloads before processing the uploaded files. + */ + private function assertExclusiveFileInputSources(array $file, array $files, ?array $singleUploadedFile, ?array $multipleUploadedFiles): void { + if (($file && $files) + || ($singleUploadedFile && $multipleUploadedFiles) + || (($file || $files) && ($singleUploadedFile || $multipleUploadedFiles))) { + // TRANSLATORS Error shown when a file upload mixes mutually exclusive input formats. + throw new LibresignException($this->l10n->t('Use only one file input format per request')); + } + } + /** * @return DataResponse */ diff --git a/tests/php/Unit/Controller/FileControllerInputSourceTest.php b/tests/php/Unit/Controller/FileControllerInputSourceTest.php index aeb160b11e..cdab19b4d9 100644 --- a/tests/php/Unit/Controller/FileControllerInputSourceTest.php +++ b/tests/php/Unit/Controller/FileControllerInputSourceTest.php @@ -96,8 +96,10 @@ private function controller(): FileController { #[DataProvider('acceptedInputs')] public function testAcceptsOneFileInputSource(array $file, array $files, ?array $singleUpload, ?array $batchUpload, array $expected): void { $controller = $this->controller(); + (new ReflectionMethod(FileController::class, 'assertExclusiveFileInputSources')) + ->invoke($controller, $file, $files, $singleUpload, $batchUpload); $result = (new ReflectionMethod(FileController::class, 'prepareFilesForSaving')) - ->invoke($controller, $file, $files, [], $singleUpload, $batchUpload); + ->invoke($controller, $file, $files, [], $batchUpload ?: $singleUpload); // PHP file entries are associative maps: key insertion order is not contractual. $sortUploadKeys = static function (array $entry): array { if (isset($entry['uploadedFile'])) { @@ -113,8 +115,8 @@ public function testRejectsAmbiguousFileInputs(array $file, array $files, ?array $controller = $this->controller(); $this->expectException(LibresignException::class); $this->expectExceptionMessage('Use only one file input format per request'); - (new ReflectionMethod(FileController::class, 'prepareFilesForSaving')) - ->invoke($controller, $file, $files, [], $singleUpload, $batchUpload); + (new ReflectionMethod(FileController::class, 'assertExclusiveFileInputSources')) + ->invoke($controller, $file, $files, $singleUpload, $batchUpload); } public function testConflictingMultipartInputReturns422WithoutSaving(): void { From 8600c7d77b85f4ebb4c2936fd8a09a60c3c81eda Mon Sep 17 00:00:00 2001 From: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:07:30 +0000 Subject: [PATCH 9/9] chore(openapi): align stable33 generated upload contracts after conflict resolution Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com> --- openapi-full.json | 6 +++--- openapi.json | 6 +++--- src/types/openapi/openapi-full.ts | 4 ++-- src/types/openapi/openapi.ts | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/openapi-full.json b/openapi-full.json index e8722ae53d..22f7171c8c 100644 --- a/openapi-full.json +++ b/openapi-full.json @@ -3,7 +3,7 @@ "info": { "title": "libresign-full", "version": "0.0.1", - "description": "Control document signing workflows inside Nextcloud", + "description": "Sign documents and manage signing workflows", "license": { "name": "agpl" } @@ -6016,7 +6016,7 @@ "post": { "operationId": "file-save", "summary": "Send a file", - "description": "Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", + "description": "Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", "tags": [ "file" ], @@ -6155,7 +6155,7 @@ "post": { "operationId": "file-add-file-to-envelope", "summary": "Add file to envelope", - "description": "Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'.", + "description": "Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches.", "tags": [ "file" ], diff --git a/openapi.json b/openapi.json index bae71d7258..a4eb62d615 100644 --- a/openapi.json +++ b/openapi.json @@ -3,7 +3,7 @@ "info": { "title": "libresign", "version": "0.0.1", - "description": "Control document signing workflows inside Nextcloud", + "description": "Sign documents and manage signing workflows", "license": { "name": "agpl" } @@ -5392,7 +5392,7 @@ "post": { "operationId": "file-save", "summary": "Send a file", - "description": "Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", + "description": "Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches.\n**Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does.", "tags": [ "file" ], @@ -5531,7 +5531,7 @@ "post": { "operationId": "file-add-file-to-envelope", "summary": "Add file to envelope", - "description": "Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'.", + "description": "Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches.", "tags": [ "file" ], diff --git a/src/types/openapi/openapi-full.ts b/src/types/openapi/openapi-full.ts index 891ca9bcde..276f679bb1 100644 --- a/src/types/openapi/openapi-full.ts +++ b/src/types/openapi/openapi-full.ts @@ -598,7 +598,7 @@ export type paths = { put?: never; /** * Send a file - * @description Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms. + * @description Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches. * **Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does. */ post: operations["file-save"]; @@ -619,7 +619,7 @@ export type paths = { put?: never; /** * Add file to envelope - * @description Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'. + * @description Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches. */ post: operations["file-add-file-to-envelope"]; delete?: never; diff --git a/src/types/openapi/openapi.ts b/src/types/openapi/openapi.ts index 351bf85ae5..e29584d229 100644 --- a/src/types/openapi/openapi.ts +++ b/src/types/openapi/openapi.ts @@ -598,7 +598,7 @@ export type paths = { put?: never; /** * Send a file - * @description Send a new file to Nextcloud and return the fileId to request signature. File references can be sent as JSON using 'file' (single) or 'files' (list). Binary files use multipart/form-data: 'file' for one file, 'files[]' for several; the legacy 'file[]' field is also accepted. Do not combine these input forms. + * @description Send a new file to Nextcloud and return the fileId to request signature. Files must be uploaded as multipart/form-data with field name 'file[]' or 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches. * **Note on multiple file uploads:** PHP has a limit on the number of files that can be uploaded in a single request (max_file_uploads directive, default 20). When uploading many files (more than 20), consider uploading them sequentially in multiple requests or use individual file uploads like the Files app does. */ post: operations["file-save"]; @@ -619,7 +619,7 @@ export type paths = { put?: never; /** * Add file to envelope - * @description Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'. + * @description Add one or more files to an existing envelope that is in DRAFT status. Files must be uploaded as multipart/form-data with field name 'files[]'. Multipart clients can send optional expectedFilesCount to reject incomplete batches. */ post: operations["file-add-file-to-envelope"]; delete?: never;