Skip to content

Commit 66bbd40

Browse files
ChristophWurstkesselb
authored andcommitted
fix(dav): handle HTML in CalDAV invitations
Signed-off-by: Christoph Wurst <[email protected]>
1 parent 75edec9 commit 66bbd40

File tree

2 files changed

+32
-19
lines changed

2 files changed

+32
-19
lines changed

apps/dav/lib/CalDAV/Reminder/NotificationProvider/EmailProvider.php

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,31 @@ private function addBulletList(IEMailTemplate $template,
144144
IL10N $l10n,
145145
string $calendarDisplayName,
146146
VEvent $vevent):void {
147-
$template->addBodyListItem($calendarDisplayName, $l10n->t('Calendar:'),
148-
$this->getAbsoluteImagePath('actions/info.png'));
147+
$template->addBodyListItem(
148+
htmlspecialchars($calendarDisplayName),
149+
$l10n->t('Calendar:'),
150+
$this->getAbsoluteImagePath('actions/info.png'),
151+
htmlspecialchars($calendarDisplayName),
152+
);
149153

150154
$template->addBodyListItem($this->generateDateString($l10n, $vevent), $l10n->t('Date:'),
151155
$this->getAbsoluteImagePath('places/calendar.png'));
152156

153157
if (isset($vevent->LOCATION)) {
154-
$template->addBodyListItem((string)$vevent->LOCATION, $l10n->t('Where:'),
155-
$this->getAbsoluteImagePath('actions/address.png'));
158+
$template->addBodyListItem(
159+
htmlspecialchars((string)$vevent->LOCATION),
160+
$l10n->t('Where:'),
161+
$this->getAbsoluteImagePath('actions/address.png'),
162+
htmlspecialchars((string)$vevent->LOCATION),
163+
);
156164
}
157165
if (isset($vevent->DESCRIPTION)) {
158-
$template->addBodyListItem((string)$vevent->DESCRIPTION, $l10n->t('Description:'),
159-
$this->getAbsoluteImagePath('actions/more.png'));
166+
$template->addBodyListItem(
167+
htmlspecialchars((string)$vevent->DESCRIPTION),
168+
$l10n->t('Description:'),
169+
$this->getAbsoluteImagePath('actions/more.png'),
170+
htmlspecialchars((string)$vevent->DESCRIPTION),
171+
);
160172
}
161173
}
162174

apps/dav/lib/CalDAV/Schedule/IMipService.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use Sabre\VObject\Parameter;
2626
use Sabre\VObject\Property;
2727
use Sabre\VObject\Recur\EventIterator;
28+
use function htmlspecialchars;
2829

2930
class IMipService {
3031

@@ -80,10 +81,10 @@ private function generateDiffString(VEvent $vevent, VEvent $oldVEvent, string $p
8081
if (!isset($vevent->$property)) {
8182
return $default;
8283
}
83-
$newstring = $vevent->$property->getValue();
84+
$newstring = htmlspecialchars($vevent->$property->getValue());
8485
if (isset($oldVEvent->$property) && $oldVEvent->$property->getValue() !== $newstring) {
8586
$oldstring = $oldVEvent->$property->getValue();
86-
return sprintf($strikethrough, $oldstring, $newstring);
87+
return sprintf($strikethrough, htmlspecialchars($oldstring), $newstring);
8788
}
8889
return $newstring;
8990
}
@@ -96,8 +97,8 @@ private function generateLinkifiedDiffString(VEvent $vevent, VEvent $oldVEvent,
9697
return $default;
9798
}
9899
/** @var string|null $newString */
99-
$newString = $vevent->$property->getValue();
100-
$oldString = isset($oldVEvent->$property) ? $oldVEvent->$property->getValue() : null;
100+
$newString = htmlspecialchars($vevent->$property->getValue());
101+
$oldString = isset($oldVEvent->$property) ? htmlspecialchars($oldVEvent->$property->getValue()) : null;
101102
if ($oldString !== $newString) {
102103
return sprintf(
103104
"<span style='text-decoration: line-through'>%s</span><br />%s",
@@ -797,10 +798,10 @@ public function buildCancelledBodyData(VEvent $vEvent): array {
797798
$strikethrough = "<span style='text-decoration: line-through'>%s</span>";
798799

799800
$newMeetingWhen = $this->generateWhenString($eventReaderCurrent);
800-
$newSummary = isset($vEvent->SUMMARY) && (string)$vEvent->SUMMARY !== '' ? (string)$vEvent->SUMMARY : $this->l10n->t('Untitled event');
801-
$newDescription = isset($vEvent->DESCRIPTION) && (string)$vEvent->DESCRIPTION !== '' ? (string)$vEvent->DESCRIPTION : $defaultVal;
801+
$newSummary = htmlspecialchars(isset($vEvent->SUMMARY) && (string)$vEvent->SUMMARY !== '' ? (string)$vEvent->SUMMARY : $this->l10n->t('Untitled event'));
802+
$newDescription = htmlspecialchars(isset($vEvent->DESCRIPTION) && (string)$vEvent->DESCRIPTION !== '' ? (string)$vEvent->DESCRIPTION : $defaultVal);
802803
$newUrl = isset($vEvent->URL) && (string)$vEvent->URL !== '' ? sprintf('<a href="%1$s">%1$s</a>', $vEvent->URL) : $defaultVal;
803-
$newLocation = isset($vEvent->LOCATION) && (string)$vEvent->LOCATION !== '' ? (string)$vEvent->LOCATION : $defaultVal;
804+
$newLocation = htmlspecialchars(isset($vEvent->LOCATION) && (string)$vEvent->LOCATION !== '' ? (string)$vEvent->LOCATION : $defaultVal);
804805
$newLocationHtml = $this->linkify($newLocation) ?? $newLocation;
805806

806807
$data = [];
@@ -1067,30 +1068,30 @@ public function addAttendees(IEMailTemplate $template, VEvent $vevent) {
10671068
*/
10681069
public function addBulletList(IEMailTemplate $template, VEvent $vevent, $data) {
10691070
$template->addBodyListItem(
1070-
$data['meeting_title_html'] ?? $data['meeting_title'], $this->l10n->t('Title:'),
1071+
$data['meeting_title_html'] ?? htmlspecialchars($data['meeting_title']), $this->l10n->t('Title:'),
10711072
$this->getAbsoluteImagePath('caldav/title.png'), $data['meeting_title'], '', IMipPlugin::IMIP_INDENT);
10721073
if ($data['meeting_when'] !== '') {
1073-
$template->addBodyListItem($data['meeting_when_html'] ?? $data['meeting_when'], $this->l10n->t('When:'),
1074+
$template->addBodyListItem($data['meeting_when_html'] ?? htmlspecialchars($data['meeting_when']), $this->l10n->t('When:'),
10741075
$this->getAbsoluteImagePath('caldav/time.png'), $data['meeting_when'], '', IMipPlugin::IMIP_INDENT);
10751076
}
10761077
if ($data['meeting_location'] !== '') {
1077-
$template->addBodyListItem($data['meeting_location_html'] ?? $data['meeting_location'], $this->l10n->t('Location:'),
1078+
$template->addBodyListItem($data['meeting_location_html'] ?? htmlspecialchars($data['meeting_location']), $this->l10n->t('Location:'),
10781079
$this->getAbsoluteImagePath('caldav/location.png'), $data['meeting_location'], '', IMipPlugin::IMIP_INDENT);
10791080
}
10801081
if ($data['meeting_url'] !== '') {
1081-
$template->addBodyListItem($data['meeting_url_html'] ?? $data['meeting_url'], $this->l10n->t('Link:'),
1082+
$template->addBodyListItem($data['meeting_url_html'] ?? htmlspecialchars($data['meeting_url']), $this->l10n->t('Link:'),
10821083
$this->getAbsoluteImagePath('caldav/link.png'), $data['meeting_url'], '', IMipPlugin::IMIP_INDENT);
10831084
}
10841085
if (isset($data['meeting_occurring'])) {
1085-
$template->addBodyListItem($data['meeting_occurring_html'] ?? $data['meeting_occurring'], $this->l10n->t('Occurring:'),
1086+
$template->addBodyListItem($data['meeting_occurring_html'] ?? htmlspecialchars($data['meeting_occurring']), $this->l10n->t('Occurring:'),
10861087
$this->getAbsoluteImagePath('caldav/time.png'), $data['meeting_occurring'], '', IMipPlugin::IMIP_INDENT);
10871088
}
10881089

10891090
$this->addAttendees($template, $vevent);
10901091

10911092
/* Put description last, like an email body, since it can be arbitrarily long */
10921093
if ($data['meeting_description']) {
1093-
$template->addBodyListItem($data['meeting_description_html'] ?? $data['meeting_description'], $this->l10n->t('Description:'),
1094+
$template->addBodyListItem($data['meeting_description_html'] ?? htmlspecialchars($data['meeting_description']), $this->l10n->t('Description:'),
10941095
$this->getAbsoluteImagePath('caldav/description.png'), $data['meeting_description'], '', IMipPlugin::IMIP_INDENT);
10951096
}
10961097
}

0 commit comments

Comments
 (0)