Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change minimal port number to 0 (unix socket) #2452

Merged
merged 1 commit into from Jun 11, 2019
Merged

Change minimal port number to 0 (unix socket) #2452

merged 1 commit into from Jun 11, 2019

Conversation

Tracerneo
Copy link
Contributor

Listening on an unix socket reports port number 0, which is interpreted as an invalid argument.

Same issue exists in vendor libraries used by Grav.
guzzle/psr7#270
Nyholm/psr7#115

One of them caused whole website to crash with HTTP 503 error, after updating from 1.5.8 to 1.6.3.

2019/04/15 12:06:33 [error] 22644#0: *15185375 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught InvalidArgumentException: Invalid port: 0. Must be between 1 and 65535 in /var/www/grav/html/vendor/nyholm/psr7/src/Uri.php:282
Stack trace:
#0 /var/www/grav/html/vendor/nyholm/psr7/src/Uri.php(178): Nyholm\Psr7\Uri->filterPort(0)
#1 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(252): Nyholm\Psr7\Uri->withPort('')
#2 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(141): Nyholm\Psr7Server\ServerRequestCreator->createUriFromArray(Array)
#3 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(63): Nyholm\Psr7Server\ServerRequestCreator->getUriFromEnvWithHTTP(Array)
#4 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(54): Nyholm\Psr7Server\ServerRequestCreator->fromArrays(Array, Array, Array, Array, Array, Array, Resource id #5)
#5 /var/www/grav/html/system/src/Grav/Common/Service/RequestServiceProvider.php(31): Nyholm\" while reading response header from upstream, client: unix:, server: , request: "HEAD / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/grav.sock:"

@rhukster
Copy link
Member

Can I ask why you are listening on port 0 (ie socket) ??? Aren't you just inviting trouble? This port is mostly blocked because of the security implications as it's intended for system level stuff?

@Tracerneo
Copy link
Contributor Author

Tracerneo commented Apr 16, 2019

Unix(7) sockets have no concept of port, so the function which checks for port returns 0 (or null, nothing). It's not the same as TCP or UDP port 0 (it's not using TCP/IP at all actually).

Aren't you just inviting trouble? This port is mostly blocked because of the security implications as it's intended for system level stuff?

It's safer, addressed by file path, not exposed to the network, access is controlled by filesystem permissions (user/group); and it's faster, as it has no TCP/IP overhead. I expose it to the internet through a load balancer forwarding traffic to this unix socket.

Relevant lines from Grav's Configuration - Info page in admin panel:

$_SERVER['SERVER_NAME'] | no value
$_SERVER['SERVER_PORT'] | no value
$_SERVER['SERVER_ADDR'] | unix:/var/run/nginx/grav.sock
$_SERVER['REMOTE_PORT'] | no value
$_SERVER['REMOTE_ADDR'] | unix:

@Tracerneo
Copy link
Contributor Author

Issue is still present in Grav 1.6.7.

2019/04/23 08:46:18 [error] 22644#0: *16207498 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught InvalidArgumentException: Invalid port: 0. Must be between 1 and 65535 in /var/www/grav/html/vendor/nyholm/psr7/src/Uri.php:282
Stack trace:
#0 /var/www/grav/html/vendor/nyholm/psr7/src/Uri.php(178): Nyholm\Psr7\Uri->filterPort(0)
#1 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(252): Nyholm\Psr7\Uri->withPort('')
#2 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(141): Nyholm\Psr7Server\ServerRequestCreator->createUriFromArray(Array)
#3 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(63): Nyholm\Psr7Server\ServerRequestCreator->getUriFromEnvWithHTTP(Array)
#4 /var/www/grav/html/vendor/kodus/psr7-server/src/ServerRequestCreator.php(54): Nyholm\Psr7Server\ServerRequestCreator->fromArrays(Array, Array, Array, Array, Array, Array, Resource id #5)
#5 /var/www/grav/html/system/src/Grav/Common/Service/RequestServiceProvider.php(31): Nyholm\" while reading response header from upstream, client: unix:, server: , request: "HEAD / HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/grav.sock:"

@Goutte
Copy link
Contributor

Goutte commented May 7, 2019

Thanks for the clarification ! What you're doing is badass. 🚀

Perhaps a compromise would be to somehow skip the Uri port filter altogether somewhere upstream like here, when the scheme is unix.

@rhukster
Copy link
Member

rhukster commented May 8, 2019

I'm ok merging this when/if the upstream repos merge it (which will be required for this to work correctly in Grav anyway).

@Tracerneo
Copy link
Contributor Author

The upstream merged fixes.

@rhukster
Copy link
Member

Great we’ll get this merged too.

@rhukster rhukster merged commit 30cfe3b into getgrav:develop Jun 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants