Files
Wallos/includes/ical_helper.php
Miguel Ribeiro 800241a265 Fix GHSA-q2r8-m9wm-5547: escape iCal property values to prevent CRLF injection
Raw CRLF in subscription name/notes/url passes through validate()
untouched (it only escapes HTML metacharacters) and was interpolated
directly into .ics VEVENT properties, letting an unescaped newline
terminate the current property and inject arbitrary calendar events.

Adds includes/ical_helper.php::icalEscape() (RFC 5545 value escaping)
and applies it to every user-controlled value embedded in both
iCal export endpoints, rather than stripping newlines in the shared
validate() sanitizer (which would break legitimate multi-line notes
used elsewhere in the app).
2026-07-11 23:27:59 +02:00

24 lines
829 B
PHP

<?php
/**
* Escapes a value for safe embedding in an iCalendar (RFC 5545) property value.
*
* Backslash must be escaped first, before the other substitutions introduce
* new backslashes. Raw CRLF/LF are converted to a literal two-character
* "\n" escape sequence — never leave a real newline in the output, since
* iCalendar treats CRLF as a property delimiter: an unescaped newline lets
* user-supplied text (e.g. a subscription name or notes) terminate the
* current property and inject arbitrary calendar content (CWE-93).
*/
function icalEscape($value)
{
$value = (string) $value;
$value = str_replace('\\', '\\\\', $value);
$value = str_replace(["\r\n", "\r", "\n"], '\\n', $value);
$value = str_replace(',', '\\,', $value);
$value = str_replace(';', '\\;', $value);
return $value;
}
?>