Skip to content

Commit b08de20

Browse files
committed
bugfix: handle unhandled InvalidOriginValueException
For origins resulting in `InvalidOriginValueException`, we can assume that these are actual CORS requests. If these are made from unsupported origins, we should treat these as unauthorized requests. Signed-off-by: Maximilian Bösing <2189546+boesing@users.noreply.github.com>
1 parent b7b50db commit b08de20

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Middleware/CorsMiddleware.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Mezzio\Cors\Middleware;
66

7+
use Mezzio\Cors\Exception\InvalidOriginValueException;
78
use Mezzio\Cors\Middleware\Exception\InvalidConfigurationException;
89
use Mezzio\Cors\Service\ConfigurationLocatorInterface;
910
use Mezzio\Cors\Service\CorsInterface;
@@ -46,11 +47,18 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
4647
throw InvalidConfigurationException::fromInvalidPipelineConfiguration();
4748
}
4849

49-
if (! $this->cors->isCorsRequest($request)) {
50+
try {
51+
$isCorsRequest = $this->cors->isCorsRequest($request);
52+
} catch (InvalidOriginValueException $exception) {
53+
return $this->responseFactory->unauthorized($exception->origin);
54+
}
55+
56+
if (! $isCorsRequest) {
5057
return $this->vary($handler->handle($request));
5158
}
5259

5360
$metadata = $this->cors->metadata($request);
61+
5462
if ($this->cors->isPreflightRequest($request)) {
5563
return $this->preflight($metadata) ?? $handler->handle($request);
5664
}

0 commit comments

Comments
 (0)