SecurityUtils.php 571 B

1234567891011121314151617181920212223
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Service\Utils;
  4. class SecurityUtils
  5. {
  6. /**
  7. * Lève une exception si la méthode a été appelée dans le cadre d'un appel API originaire d'un hôte
  8. * différent de localhost.
  9. */
  10. public static function preventIfNotLocalhost(): void
  11. {
  12. if (
  13. $_SERVER
  14. && $_SERVER['APP_ENV'] !== 'docker'
  15. && $_SERVER['SERVER_ADDR'] !== $_SERVER['REMOTE_ADDR']
  16. ) {
  17. throw new \RuntimeException('This operation is restricted to localhost');
  18. }
  19. }
  20. }