Skip to content

Commit 3331ebc

Browse files
committed
fix(TaskProcessing): Harden task scheduling with webhooks
Signed-off-by: Marcel Klehr <mklehr@gmx.net>
1 parent 1c88b39 commit 3331ebc

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

core/Controller/TaskProcessingApiController.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use OCP\IL10N;
2929
use OCP\IRequest;
3030
use OCP\Lock\LockedException;
31+
use OCP\Security\IRemoteHostValidator;
3132
use OCP\TaskProcessing\Exception\Exception;
3233
use OCP\TaskProcessing\Exception\NotFoundException;
3334
use OCP\TaskProcessing\Exception\PreConditionNotMetException;
@@ -53,6 +54,7 @@ public function __construct(
5354
private IRootFolder $rootFolder,
5455
private IAppData $appData,
5556
private IMimeTypeDetector $mimeTypeDetector,
57+
private IRemoteHostValidator $remoteHostValidator,
5658
) {
5759
parent::__construct($appName, $request);
5860
}
@@ -167,6 +169,18 @@ private function handleScheduleTaskInternal(
167169
bool $preferStreaming = false,
168170
): DataResponse {
169171
$task = new Task($type, $input, $appId, $this->userId, $customId);
172+
if ($webhookUri !== null && $webhookUri !== ''
173+
&& str_starts_with((string)$webhookMethod, 'HTTP:')) {
174+
$parsed = parse_url($webhookUri);
175+
$host = $parsed['host'] ?? null;
176+
$scheme = strtolower($parsed['scheme'] ?? '');
177+
if (!is_string($host) || $host === ''
178+
|| !in_array($scheme, ['http', 'https'], true)
179+
|| !$this->remoteHostValidator->isValid($host)) {
180+
return new DataResponse(['message' => 'Bad webhook URI'],
181+
Http::STATUS_BAD_REQUEST);
182+
}
183+
}
170184
$task->setWebhookUri($webhookUri);
171185
$task->setWebhookMethod($webhookMethod);
172186
$task->setIncludeWatermark($includeWatermark);

0 commit comments

Comments
 (0)