zendframework / zend-diactoros

PSR-7 HTTP Message implementation
BSD 3-Clause "New" or "Revised" License
1.55k stars 152 forks source link

BUG: marshalHeadersFromSapi assume all SERVER keys are strings #369

Closed tinproject closed 5 years ago

tinproject commented 5 years ago

For some estrange reason $_SERVER super-global could be populated with an integer key, making marshalHeadersFromSapi function to crash.

According to php manual integer keys are valid keys:

The key can either be an integer or a string. The value can be of any type.

Code to reproduce the issue

This happened on a Systemd + Nginx + php-pfm, trying to use sentry-symfony 3.2

To reproduce, add this line to the php-fpm pool config:

env[42] = testing

Expected results

To deal graciously with integer keys and not crash the request.

Actual results

Fatal error: Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: strpos() expects parameter 1 to be string, int given in /opt/app/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php:28 Stack trace: 
#0 /opt/app/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php(28): strpos(92, 'REDIRECT_') 
#1 /opt/app/vendor/zendframework/zend-diactoros/src/ServerRequestFactory.php(64): Zend\Diactoros\marshalHeadersFromSapi(Array) 
#2 /opt/app/vendor/sentry/sentry/src/Integration/RequestIntegration.php(101): Zend\Diactoros\ServerRequestFactory::fromGlobals() 
#3 /opt/app/vendor/sentry/sentry/src/Integration/RequestIntegration.php(74): Sentry\Integration\RequestIntegration->processEvent(Object(Sentry\Event), Object(Sentry\Options)) 
#4 /opt/app/vendor/ in /opt/app/vendor/zendframework/zend-diactoros/src/functions/marshal_headers_from_sapi.php on line 28
Jean85 commented 5 years ago

This is actually something related to the fact that Diactoros uses strict_types=1. A simple cast (or the removal of the type) should be enough.