billchurch / webssh2

Web SSH Client using ssh2, socket.io, xterm.js, and express. webssh webssh2
MIT License
2.36k stars 536 forks source link

[Bug]: Port increment concatenates 1 instead of adding 1 #330

Open JonLoesch opened 1 year ago

JonLoesch commented 1 year ago

What happened?

I am pretty sure this is unintended behavior. I encountered the following very surprising log output:

kudu_ssh_user@45b8a1549992:/$ node /opt/webssh/index.js
WebSSH2 service reading config from: /opt/webssh/config.json
WebSSH2 service listening on 0.0.0.0:3000
WebSSH2 Address in use, retrying on port 30001

I assume the 3000 -> 30001 bump is because of javascript string / number typing nonsense. Not sure how big of an impact this is for anyone else. To behonest it's not an impact for me, I just though it was worth mentioning and bringing up

Node Version

14.19.2

NPM Version

6.14.17

Server OS Version

kudu_ssh_user@45b8a1549992:/$ uname -a Linux 45b8a1549992 5.10.164.1-1.cm1 #1 SMP Tue Jan 24 21:45:24 UTC 2023 x86_64 GNU/Linux kudu_ssh_user@45b8a1549992:/$ cat /etc/os-release PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" NAME="Debian GNU/Linux" VERSION_ID="11" VERSION="11 (bullseye)" VERSION_CODENAME=bullseye ID=debian HOME_URL="https://www.debian.org/" SUPPORT_URL="https://www.debian.org/support" BUG_REPORT_URL="https://bugs.debian.org/"

WebSSH2 release version

0.4.4

OS and Version of SSH server

No response

Browser Version

No response

Relevant log output

No response

billchurch commented 1 year ago

The issue most likely (was able to replicate) is that you're putting your port number in quotes which does, in fact, turn it into a string. Although this is wrong 😉 I should be checking for this behavior and not allowing it to happen in the first place.

Good Config

  "listen": {
    "ip": "0.0.0.0",
    "port": 3000
  },

results:

WebSSH2 service reading config from: /Users/bc/Documents/GitHub/webssh2/webssh2/app/config.json
WebSSH2 service listening on 0.0.0.0:3000
WebSSH2 Address in use, retrying on port 3001

Bad Config

  "listen": {
    "ip": "0.0.0.0",
    "port": "3000"
  },

results:

WebSSH2 service reading config from: /Users/bc/Documents/GitHub/webssh2/webssh2/app/config.json
WebSSH2 service listening on 0.0.0.0:3000
WebSSH2 Address in use, retrying on port 30001
vomaksh commented 1 year ago

This issue also occurs when one passes port via env.

In my case I ran PORT=4000 npm start.

image