1
0

CalDavValidatePlugin.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\DAV\CalDAV\Validation;
  8. use OCA\DAV\AppInfo\Application;
  9. use OCP\IAppConfig;
  10. use Sabre\DAV\Exception\Forbidden;
  11. use Sabre\DAV\Server;
  12. use Sabre\DAV\ServerPlugin;
  13. use Sabre\HTTP\RequestInterface;
  14. use Sabre\HTTP\ResponseInterface;
  15. class CalDavValidatePlugin extends ServerPlugin {
  16. public function __construct(
  17. private IAppConfig $config,
  18. ) {
  19. }
  20. public function initialize(Server $server): void {
  21. $server->on('beforeMethod:PUT', [$this, 'beforePut']);
  22. }
  23. public function beforePut(RequestInterface $request, ResponseInterface $response): bool {
  24. // evaluate if card size exceeds defined limit
  25. $eventSizeLimit = $this->config->getValueInt(Application::APP_ID, 'event_size_limit', 10485760);
  26. if ((int)$request->getRawServerValue('CONTENT_LENGTH') > $eventSizeLimit) {
  27. throw new Forbidden("VEvent or VTodo object exceeds $eventSizeLimit bytes");
  28. }
  29. // all tests passed return true
  30. return true;
  31. }
  32. }