AddContentSecurityPolicyEvent.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCP\Security\CSP;
  8. use OC\Security\CSP\ContentSecurityPolicyManager;
  9. use OCP\AppFramework\Http\EmptyContentSecurityPolicy;
  10. use OCP\EventDispatcher\Event;
  11. /**
  12. * Allows to inject something into the default content policy. This is for
  13. * example useful when you're injecting Javascript code into a view belonging
  14. * to another controller and cannot modify its Content-Security-Policy itself.
  15. * Note that the adjustment is only applied to applications that use AppFramework
  16. * controllers.
  17. *
  18. * WARNING: Using this API incorrectly may make the instance more insecure.
  19. * Do think twice before adding whitelisting resources. Please do also note
  20. * that it is not possible to use the `disallowXYZ` functions.
  21. *
  22. * @since 17.0.0
  23. */
  24. class AddContentSecurityPolicyEvent extends Event {
  25. /** @var ContentSecurityPolicyManager */
  26. private $policyManager;
  27. /**
  28. * @since 17.0.0
  29. */
  30. public function __construct(ContentSecurityPolicyManager $policyManager) {
  31. parent::__construct();
  32. $this->policyManager = $policyManager;
  33. }
  34. /**
  35. * @since 17.0.0
  36. */
  37. public function addPolicy(EmptyContentSecurityPolicy $csp): void {
  38. $this->policyManager->addDefaultPolicy($csp);
  39. }
  40. }