2828use OCP \IL10N ;
2929use OCP \IRequest ;
3030use OCP \Lock \LockedException ;
31+ use OCP \Security \IRemoteHostValidator ;
3132use OCP \TaskProcessing \Exception \Exception ;
3233use OCP \TaskProcessing \Exception \NotFoundException ;
3334use 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