Skip to content

Commit c891bde

Browse files
fix(dav): Handle long absence status earlier
Validate the request early. Don't let this cause a database error. Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent a4760ef commit c891bde

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

apps/dav/lib/Controller/OutOfOfficeController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use OCP\IUserManager;
2222
use OCP\IUserSession;
2323
use OCP\User\IAvailabilityCoordinator;
24+
use function mb_strlen;
2425

2526
/**
2627
* @psalm-import-type DAVOutOfOfficeData from ResponseDefinitions
@@ -107,10 +108,10 @@ public function getOutOfOffice(string $userId): DataResponse {
107108
* @param string $message Longer multiline message that is shown to others during the absence
108109
* @param ?string $replacementUserId User id of the replacement user
109110
* @param ?string $replacementUserDisplayName Display name of the replacement user
110-
* @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'firstDay'}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, null, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
111+
* @return DataResponse<Http::STATUS_OK, DAVOutOfOfficeData, array{}>|DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'firstDay'|'statusLength'}, array{}>|DataResponse<Http::STATUS_UNAUTHORIZED, null, array{}>|DataResponse<Http::STATUS_NOT_FOUND, null, array{}>
111112
*
112113
* 200: Absence data
113-
* 400: When the first day is not before the last day
114+
* 400: When validation fails, e.g. data range error or the first day is not before the last day
114115
* 401: When the user is not logged in
115116
* 404: When the replacementUserId was provided but replacement user was not found
116117
*/
@@ -128,6 +129,9 @@ public function setOutOfOffice(
128129
if ($user === null) {
129130
return new DataResponse(null, Http::STATUS_UNAUTHORIZED);
130131
}
132+
if (mb_strlen($status) > 100) {
133+
return new DataResponse(['error' => 'statusLength'] , Http::STATUS_BAD_REQUEST);
134+
}
131135

132136
if ($replacementUserId !== null) {
133137
$replacementUser = $this->userManager->get($replacementUserId);

apps/dav/openapi.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@
793793
}
794794
},
795795
"400": {
796-
"description": "When the first day is not before the last day",
796+
"description": "When validation fails, e.g. data range error or the first day is not before the last day",
797797
"content": {
798798
"application/json": {
799799
"schema": {
@@ -821,7 +821,8 @@
821821
"error": {
822822
"type": "string",
823823
"enum": [
824-
"firstDay"
824+
"firstDay",
825+
"statusLength"
825826
]
826827
}
827828
}

0 commit comments

Comments
 (0)