From f9cdf8c58375a52bbb7993e7f754d085b0f4aeae Mon Sep 17 00:00:00 2001 From: ncou Date: Sun, 13 Jun 2021 17:25:51 +0200 Subject: [PATCH] update --- src/Bootloader/PublishCsrfBootloader.php | 2 +- .../CsrfOriginProtectionMiddleware.php | 29 ++----------------- 2 files changed, 4 insertions(+), 27 deletions(-) diff --git a/src/Bootloader/PublishCsrfBootloader.php b/src/Bootloader/PublishCsrfBootloader.php index 8226b48..e4c344a 100644 --- a/src/Bootloader/PublishCsrfBootloader.php +++ b/src/Bootloader/PublishCsrfBootloader.php @@ -6,7 +6,7 @@ use Chiron\Core\Container\Bootloader\AbstractBootloader; use Chiron\Core\Directories; -use Chiron\Core\Publisher; +use Chiron\Publisher\Publisher; final class PublishCsrfBootloader extends AbstractBootloader { diff --git a/src/Middleware/CsrfOriginProtectionMiddleware.php b/src/Middleware/CsrfOriginProtectionMiddleware.php index fae1caf..385c236 100644 --- a/src/Middleware/CsrfOriginProtectionMiddleware.php +++ b/src/Middleware/CsrfOriginProtectionMiddleware.php @@ -44,8 +44,7 @@ final class CsrfOriginProtectionMiddleware implements MiddlewareInterface private $csrfConfig; /** - * @param HttpConfig $httpConfig - * @param SettingsConfig $settingsConfig + * @param CsrfConfig $csrfConfig */ public function __construct(CsrfConfig $csrfConfig) { @@ -148,8 +147,8 @@ private function getTrustedOrigins(ServerRequestInterface $request): array { $trustedOrigins = $this->csrfConfig->getTrustedOrigins(); - // Method getHost() includes the port. - $host = $this->getHost($request); + // Method getHost() includes the port (if it's non standard). + $host = $request->getUri()->getHost(); // TODO : vérifier l'utilité de ce if $host === '' car je ne sais pas si ce cas peut arriver, et comment ca fonctionne si on ajoute d'officie le host vide dans le tableau comment va se comporter la méthode isSameDomain ???? if ($host !== '') { @@ -159,28 +158,6 @@ private function getTrustedOrigins(ServerRequestInterface $request): array return $trustedOrigins; } - /** - * Returns the HTTP host + port (if it's non-standard). - * - * @param ServerRequestInterface $request - * - * @return string - */ - private function getHost(ServerRequestInterface $request): string - { - $host = $request->getUri()->getHost(); - if ($host === '') { - return ''; - } - // Standard ports are null (80, 443) - $port = $request->getUri()->getPort(); - if ($port !== null) { - $host .= ':' . $port; - } - - return $host; - } - private function isTrustedOrigin(string $origin, array $trustedOrigins): bool { // Check if the request's origin matches any of our trusted origins.