- make url validation more robust
This commit is contained in:
1 parent
fa398f5b36
commit
830b53054c
1 file changed
+42
-3
@@ -36,6 +36,16 @@ class CalendarController extends Controller
|
|||||||
*/
|
*/
|
||||||
private const DATETIME_LOCAL = 'Y-m-d\TH:i';
|
private const DATETIME_LOCAL = 'Y-m-d\TH:i';
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Maximum length of the URL-like fields "location" and "url".
|
||||||
|
*/
|
||||||
|
private const MAX_URL_LENGTH = 2000;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Maximum length of a valid email address (RFC 5321).
|
||||||
|
*/
|
||||||
|
private const MAX_EMAIL_LENGTH = 254;
|
||||||
|
|
||||||
private IManager $calendarManager;
|
private IManager $calendarManager;
|
||||||
private IUserSession $userSession;
|
private IUserSession $userSession;
|
||||||
private IURLGenerator $urlGenerator;
|
private IURLGenerator $urlGenerator;
|
||||||
@@ -378,14 +388,31 @@ class CalendarController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($location !== '') {
|
if ($location !== '') {
|
||||||
|
$this->assertBoundedLength(
|
||||||
|
$location,
|
||||||
|
self::MAX_URL_LENGTH,
|
||||||
|
'Location is too long.'
|
||||||
|
);
|
||||||
$this->assertHttpsUrl($location, 'Location must be an HTTPS URL.');
|
$this->assertHttpsUrl($location, 'Location must be an HTTPS URL.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($url !== '') {
|
if ($url !== '') {
|
||||||
|
$this->assertBoundedLength(
|
||||||
|
$url,
|
||||||
|
self::MAX_URL_LENGTH,
|
||||||
|
'Meeting URL is too long.'
|
||||||
|
);
|
||||||
$this->assertHttpsUrl($url, 'Meeting URL must be an HTTPS URL.');
|
$this->assertHttpsUrl($url, 'Meeting URL must be an HTTPS URL.');
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($organizer !== '' && !filter_var(
|
if ($organizer !== '') {
|
||||||
|
$this->assertBoundedLength(
|
||||||
|
$organizer,
|
||||||
|
self::MAX_EMAIL_LENGTH,
|
||||||
|
'Organizer email address is too long.'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!filter_var(
|
||||||
$organizer,
|
$organizer,
|
||||||
FILTER_VALIDATE_EMAIL
|
FILTER_VALIDATE_EMAIL
|
||||||
)) {
|
)) {
|
||||||
@@ -393,6 +420,7 @@ class CalendarController extends Controller
|
|||||||
'Invalid organizer email address.'
|
'Invalid organizer email address.'
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'summary' => $summary,
|
'summary' => $summary,
|
||||||
@@ -410,14 +438,25 @@ class CalendarController extends Controller
|
|||||||
$parts = parse_url($value);
|
$parts = parse_url($value);
|
||||||
|
|
||||||
$valid = $parts !== false
|
$valid = $parts !== false
|
||||||
&& isset($parts['scheme'])
|
&& isset($parts['scheme'], $parts['host'])
|
||||||
&& strtolower($parts['scheme']) === 'https';
|
&& strtolower($parts['scheme']) === 'https'
|
||||||
|
&& $parts['host'] !== '';
|
||||||
|
|
||||||
if (!$valid) {
|
if (!$valid) {
|
||||||
throw new \InvalidArgumentException($message);
|
throw new \InvalidArgumentException($message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enforce a maximum length, counted in characters.
|
||||||
|
*/
|
||||||
|
private function assertBoundedLength(string $value, int $maxLength, string $message): void
|
||||||
|
{
|
||||||
|
if (mb_strlen($value) > $maxLength) {
|
||||||
|
throw new \InvalidArgumentException($message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parse datetime-local values.
|
* Parse datetime-local values.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in new issue
Block a user