Server option --redirect-http-from doesn't redirect correctly
I'm using
/opt/solid $ solid -V
5.3.1
from the nodesolidserver/node-solid-server image on docker hub.
The documentation for solid start says:
--redirect-http-from [value] HTTP port or ','-separated ports to redirect to the solid server port (e.g. "80,8080").
If I start the server like this (using the default listen port for https on 8443)
solid start --redirect-http-from 8000
then I get a log message:
nss_1 | Thu, 16 Jul 2020 13:10:25 GMT solid:settings will redirect from port 8000 to port 8443
However, if I make a request to this port over HTTP, I get this:
$ curl -v http://localhost:8000
* Rebuilt URL to: http://localhost:8000/
* Trying ::1...
* TCP_NODELAY set
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8000 (#0)
> GET / HTTP/1.1
> Host: localhost:8000
> User-Agent: curl/7.54.0
> Accept: */*
>
< HTTP/1.1 302 Found
< X-Powered-By: Express
< Location: https://localhost,8000:8443/
< Vary: Accept
< Content-Type: text/plain; charset=utf-8
< Content-Length: 50
< Date: Thu, 16 Jul 2020 13:10:34 GMT
< Connection: keep-alive
<
* Connection #0 to host localhost left intact
Found. Redirecting to https://localhost,8000:8443/
It seems like this has incorrectly read the parameter when creating the redirect server.
Additionally, from the usage text and the code, it seems like you should be able to add multiple http listen ports:
solid start --redirect-http-from 8000,8080,8888
But I get this as an output:
nss_1 | Thu, 16 Jul 2020 13:15:55 GMT solid:settings will redirect from port 8000,8080,8888 to port 8443
In this case I would expect to get this message 3 times, once for each port.
As you have found it does redirect correctly the port (for http or https), and not http:// to https://
I propose to close
This doesn't redirect correctly. If you look at the Location header, it is redirecting from http://localhost:8000 to https://localhost,8000:8443/. This is incorrect, it should redirect to https://localhost:8443/.
For the case of multiple parameters, the code seems to indicate that you can redirect from multiple ports to https, for example http://localhost:8000 -> https://localhost:8443/, http://localhost:8080 -> https://localhost:8443/, and http://localhost:888 -> https://localhost:8443/. However, the log message is only printed once, which seems to indicate that it's not creating the 3 http servers properly. In fact, after creating the server I cannot access http://localhost:8000, which makes me think that it's trying to bind to a non-existent port 8000,8080,8888
Can confirm this is still broken on version 5.4.4. Output from the server:
Nov 15 13:52:01 tim-pod solid[2049]: 2020-11-15T13:52:01.459Z solid:settings will redirect from port 80,8080 to port 8443
Nov 15 13:52:02 tim-pod solid[2049]: events.js:291
Nov 15 13:52:02 tim-pod solid[2049]: throw er; // Unhandled 'error' event
Nov 15 13:52:02 tim-pod solid[2049]: ^
Nov 15 13:52:02 tim-pod solid[2049]: Error: listen EADDRINUSE: address already in use 80,8080
Nov 15 13:52:02 tim-pod solid[2049]: at Server.setupListenHandle [as _listen2] (net.js:1300:21)
Nov 15 13:52:02 tim-pod solid[2049]: at listenInCluster (net.js:1365:12)
Nov 15 13:52:02 tim-pod solid[2049]: at Server.listen (net.js:1462:5)
Nov 15 13:52:02 tim-pod solid[2049]: at Function.listen (/usr/local/lib/node_modules/solid-server/node_modules/express/lib/application.js:618:24)
Nov 15 13:52:02 tim-pod solid[2049]: at /usr/local/lib/node_modules/solid-server/lib/create-server.js:96:25
Nov 15 13:52:02 tim-pod solid[2049]: at Array.forEach (<anonymous>)
Nov 15 13:52:02 tim-pod solid[2049]: at Function.createServer (/usr/local/lib/node_modules/solid-server/lib/create-server.js:88:23)
Nov 15 13:52:02 tim-pod solid[2049]: at bin (/usr/local/lib/node_modules/solid-server/bin/lib/start.js:127:17)
Nov 15 13:52:02 tim-pod solid[2049]: at Command.<anonymous> (/usr/local/lib/node_modules/solid-server/bin/lib/start.js:40:5)
Nov 15 13:52:02 tim-pod solid[2049]: at Command.listener [as _actionHandler] (/usr/local/lib/node_modules/solid-server/node_modules/commander/index.js:426:31)
Nov 15 13:52:02 tim-pod solid[2049]: Emitted 'error' event on Server instance at:
Nov 15 13:52:02 tim-pod solid[2049]: at emitErrorNT (net.js:1344:8)
Nov 15 13:52:02 tim-pod solid[2049]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
Nov 15 13:52:02 tim-pod solid[2049]: code: 'EADDRINUSE',
Nov 15 13:52:02 tim-pod solid[2049]: errno: 'EADDRINUSE',
Nov 15 13:52:02 tim-pod solid[2049]: syscall: 'listen',
Nov 15 13:52:02 tim-pod solid[2049]: address: '80,8080',
Nov 15 13:52:02 tim-pod solid[2049]: port: -1
Nov 15 13:52:02 tim-pod solid[2049]: }
Nov 15 13:52:02 tim-pod systemd[1]: solid.service: Main process exited, code=exited, status=1/FAILURE
Nov 15 13:52:02 tim-pod systemd[1]: solid.service: Failed with result 'exit-code'.
Also note, when using a single port, I get another failure (presumably because I'm not running the server as root, so it can't use port 80):
Nov 15 14:01:28 tim-pod solid[2285]: 2020-11-15T14:01:28.026Z solid:settings will redirect from port 80 to port 8443
Nov 15 14:01:28 tim-pod solid[2285]: events.js:291
Nov 15 14:01:28 tim-pod solid[2285]: throw er; // Unhandled 'error' event
Nov 15 14:01:28 tim-pod solid[2285]: ^
Nov 15 14:01:28 tim-pod solid[2285]: Error: listen EACCES: permission denied 0.0.0.0:80
Nov 15 14:01:28 tim-pod solid[2285]: at Server.setupListenHandle [as _listen2] (net.js:1300:21)
Nov 15 14:01:28 tim-pod solid[2285]: at listenInCluster (net.js:1365:12)
Nov 15 14:01:28 tim-pod solid[2285]: at Server.listen (net.js:1451:7)
Nov 15 14:01:28 tim-pod solid[2285]: at Function.listen (/usr/local/lib/node_modules/solid-server/node_modules/express/lib/application.js:618:24)
Nov 15 14:01:28 tim-pod solid[2285]: at /usr/local/lib/node_modules/solid-server/lib/create-server.js:96:25
Nov 15 14:01:28 tim-pod solid[2285]: at Array.forEach (<anonymous>)
Nov 15 14:01:28 tim-pod solid[2285]: at Function.createServer (/usr/local/lib/node_modules/solid-server/lib/create-server.js:88:23)
Nov 15 14:01:28 tim-pod solid[2285]: at bin (/usr/local/lib/node_modules/solid-server/bin/lib/start.js:127:17)
Nov 15 14:01:28 tim-pod solid[2285]: at Command.<anonymous> (/usr/local/lib/node_modules/solid-server/bin/lib/start.js:40:5)
Nov 15 14:01:28 tim-pod solid[2285]: at Command.listener [as _actionHandler] (/usr/local/lib/node_modules/solid-server/node_modules/commander/index.js:426:31)
Nov 15 14:01:28 tim-pod solid[2285]: Emitted 'error' event on Server instance at:
Nov 15 14:01:28 tim-pod solid[2285]: at emitErrorNT (net.js:1344:8)
Nov 15 14:01:28 tim-pod solid[2285]: at processTicksAndRejections (internal/process/task_queues.js:84:21) {
Nov 15 14:01:28 tim-pod solid[2285]: code: 'EACCES',
Nov 15 14:01:28 tim-pod solid[2285]: errno: 'EACCES',
Nov 15 14:01:28 tim-pod solid[2285]: syscall: 'listen',
Nov 15 14:01:28 tim-pod solid[2285]: address: '0.0.0.0',
Nov 15 14:01:28 tim-pod solid[2285]: port: 80
Nov 15 14:01:28 tim-pod solid[2285]: }