vendor/wns/security-compliance-suite/src/Hardening/Subscriber/ApiRequestSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace WnsSecurityComplianceSuite\Hardening\Subscriber;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. use WnsSecurityComplianceSuite\Util\Provider\PluginConfigProvider;
  9. final class ApiRequestSubscriber implements EventSubscriberInterface
  10. {
  11. private const PLUGIN_API_PREFIX = '/api/wscs';
  12. private PluginConfigProvider $pluginConfigProvider;
  13. public function __construct(
  14. PluginConfigProvider $pluginConfigProvider
  15. ) {
  16. $this->pluginConfigProvider = $pluginConfigProvider;
  17. }
  18. public static function getSubscribedEvents(): array
  19. {
  20. return [
  21. KernelEvents::REQUEST => 'onKernelRequest',
  22. ];
  23. }
  24. public function onKernelRequest(RequestEvent $event): void
  25. {
  26. $request = $event->getRequest();
  27. $path = $request->getPathInfo();
  28. if ($this->pluginConfigProvider->isPluginApiDisabled() === false) {
  29. return;
  30. }
  31. if (
  32. strpos($path, self::PLUGIN_API_PREFIX) === 0
  33. && strpos($path, 'two-factor') === false
  34. ) {
  35. $event->setResponse(new JsonResponse(['error' => 'The plugin API is disabled'], 403));
  36. }
  37. }
  38. }