Skip to content

Commit 7774538

Browse files
committed
fix(notifications): Require absolute links for support of desktop and mobile clients
To align with the stricter validation introduced in nextcloud/server#59606. AI-Assisted-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Anna Larch <anna@nextcloud.com>
1 parent b4a754d commit 7774538

1 file changed

Lines changed: 14 additions & 4 deletions

File tree

lib/NotificationGenerator.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ public function __construct(
3131
) {
3232
}
3333

34+
private function sanitizeUrl(string $url): string {
35+
if (str_starts_with($url, 'http://') || str_starts_with($url, 'https://')) {
36+
return $url;
37+
}
38+
39+
return '';
40+
}
41+
3442
public function deferNotifications(): bool {
3543
return $this->notificationManager->defer();
3644
}
@@ -68,8 +76,9 @@ private function getNotificationForEvent(IEvent $event, int $activityId): INotif
6876
$notification->setMessage($event->getMessage(), $event->getMessageParameters());
6977
}
7078

71-
if ($event->getLink()) {
72-
$notification->setLink($event->getLink());
79+
$link = $event->getLink() ? $this->sanitizeUrl($event->getLink()) : '';
80+
if ($link !== '') {
81+
$notification->setLink($link);
7382
}
7483

7584
return $notification;
@@ -127,8 +136,9 @@ private function getDisplayNotificationForEvent(IEvent $event, int $activityId):
127136
$notification->setRichSubject($event->getRichSubject(), $event->getRichSubjectParameters());
128137
$notification->setParsedSubject($event->getParsedSubject());
129138

130-
if ($event->getIcon()) {
131-
$notification->setIcon($event->getIcon());
139+
$icon = $event->getIcon() ? $this->sanitizeUrl($event->getIcon()) : '';
140+
if ($icon !== '') {
141+
$notification->setIcon($icon);
132142
}
133143

134144
if ($event->getRichMessage()) {

0 commit comments

Comments
 (0)