tuupola / cors-middleware

PSR-7 and PSR-15 CORS middleware
MIT License
132 stars 16 forks source link

AssertionError in neomerx/cors-psr7/src/Strategies/Settings.php line 267 assert(empty($host) === false) #77

Closed marc-mabe closed 1 year ago

marc-mabe commented 1 year ago

I'm getting an AssertionError since 1.4 on running integration tests:

POST http://localhost:8080/oauth2/token

 AssertionError raised in file /app/vendor/neomerx/cors-psr7/src/Strategies/Settings.php line 267:
  Message: assert(empty($host) === false)
  Stack Trace:
  #0 /app/vendor/neomerx/cors-psr7/src/Strategies/Settings.php(267): assert(false, 'assert(empty($h...')
  #1 /app/vendor/neomerx/cors-psr7/src/Strategies/Settings.php(154): Neomerx\Cors\Strategies\Settings->setServerOrigin('https', '', 443)
  #2 /app/vendor/tuupola/cors-middleware/src/CorsMiddleware.php(230): Neomerx\Cors\Strategies\Settings->init('https', '', 443)
  #3 /app/vendor/tuupola/cors-middleware/src/CorsMiddleware.php(133): Tuupola\Middleware\CorsMiddleware->buildSettings(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Diactoros\Response))
  #4 /app/vendor/tuupola/callable-handler/src/DoublePassTrait.php(47): Tuupola\Middleware\CorsMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Tuupola\Middleware\CallableHandler))
  #5 /app/vendor/laminas/laminas-stratigility/src/Middleware/DoublePassMiddlewareDecorator.php(67): Tuupola\Middleware\CorsMiddleware->__invoke(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Diactoros\Response), Object(Closure))
  #6 /app/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(37): Laminas\Stratigility\Middleware\DoublePassMiddlewareDecorator->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #7 /app/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #8 /app/vendor/mezzio/mezzio-router/src/Middleware/RouteMiddleware.php(50): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
  #9 /app/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(37): Mezzio\Router\Middleware\RouteMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #10 /app/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #11 /app/vendor/mezzio/mezzio-helpers/src/ServerUrlMiddleware.php(30): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
  #12 /app/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(37): Mezzio\Helper\ServerUrlMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #13 /app/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #14 /app/vendor/laminas/laminas-stratigility/src/Middleware/ErrorHandler.php(129): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
  #15 /app/vendor/mezzio/mezzio/src/Middleware/LazyLoadingMiddleware.php(37): Laminas\Stratigility\Middleware\ErrorHandler->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #16 /app/vendor/laminas/laminas-stratigility/src/Next.php(49): Mezzio\Middleware\LazyLoadingMiddleware->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\Next))
  #17 /app/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(75): Laminas\Stratigility\Next->handle(Object(Laminas\Diactoros\ServerRequest))
  #18 /app/vendor/laminas/laminas-stratigility/src/MiddlewarePipe.php(64): Laminas\Stratigility\MiddlewarePipe->process(Object(Laminas\Diactoros\ServerRequest), Object(Laminas\Stratigility\EmptyPipelineHandler))
  #19 /app/vendor/mezzio/mezzio-swoole/src/Event/RequestHandlerRequestListener.php(116): Laminas\Stratigility\MiddlewarePipe->handle(Object(Laminas\Diactoros\ServerRequest))
  #20 /app/vendor/mezzio/mezzio-swoole/src/Event/EventDispatcher.php(39): Mezzio\Swoole\Event\RequestHandlerRequestListener->__invoke(Object(Mezzio\Swoole\Event\RequestEvent))
  #21 /app/vendor/mezzio/mezzio-swoole/src/SwooleRequestHandlerRunner.php(135): Mezzio\Swoole\Event\EventDispatcher->dispatch(Object(Mezzio\Swoole\Event\RequestEvent))
  #22 [internal function]: Mezzio\Swoole\SwooleRequestHandlerRunner->onRequest(Object(Swoole\Http\Request), Object(Swoole\Http\Response))
  #23 /app/vendor/mezzio/mezzio-swoole/src/SwooleRequestHandlerRunner.php(79): Swoole\Server->start()
  #24 /app/vendor/mezzio/mezzio/src/Application.php(68): Mezzio\Swoole\SwooleRequestHandlerRunner->run()
  #25 /app/bin/server.php(28): Mezzio\Application->run()
  #26 /app/bin/server.php(29): {closure}()
  #27 {main}

It's a laminas/mezzio API using Swoole with the following config:

return [
    'cors' => [
        'options' => [
            'origin'        => '*',
            'headers.allow' => [
                // "simple headers" are always allowed
                'Accept',
                'Accept-Language',
                'Content-Language',

                // Content-Type is a "simple header",
                // but only with a MIME type of its parsed value (ignoring parameters)
                // of either application/x-www-form-urlencoded, multipart/form-data, or text/plain
                'Content-Type',

                // allow additional headers
                'Authorization',
            ],
            'headers.expose' => ['Content-Length', 'Date'],
            'cache'          => 60 * 5,
        ],
    ],
];
tuupola commented 1 year ago

Same as https://github.com/tuupola/cors-middleware/issues/75. Will tag a release soon.

tuupola commented 1 year ago

Released 1.4.2 which should fix the problem.