JoshGlazebrook/socks

Passing port as string crashes connection with non-specific error

Closed this issue · 2 comments

I was getting stuck while trying to follow the documentation for FixieSocks, which references this module:

https://devcenter.heroku.com/articles/fixie-socks#using-with-node-js

In their example, they parse the port number out of an environment variable using regex, and then pass that on to socks.

Following the example code broke the socket with a stack trace that looks like this:

SocksClientError: Invalid SOCKS proxy details were provided.
    at Object.validateSocksClientOptions (/Users/13protons/github/herl-os/node_modules/socks/build/common/helpers.js:27:15)
    at /Users/13protons/github/herl-os/node_modules/socks/build/client/socksclient.js:43:27
    at new Promise (<anonymous>)
    at Function.createConnection (/Users/13protons/github/herl-os/node_modules/socks/build/client/socksclient.js:40:16)
    at Object.<anonymous> (/Users/13protons/github/herl-os/sockstest.js:93:13)

I noticed by process of elimination that reverting the extracted port number back to a numeric 1080 fixed my connection, as did casting the matched port to a number, like this:

port: Number(fixieValues[3]),

I've fixed my own problem here, but it may be appropriate to either mention the invalid port type in the error message or just do that casting for the user.

Cheers

I looked at that heroku documentation and its actually for a different npm module. This repo is socks while those docs are using socksjs.

But I agree the error messaging here should have more details.

And if that wasn't already confusing enough, the example for connecting to mysql uses socksjs, ssl uses socksv5, and http/s uses socks

Screen Shot 2021-04-21 at 7 28 29 PM

Screen Shot 2021-04-21 at 7 28 40 PM

Screen Shot 2021-04-21 at 7 28 50 PM

Perhaps FixieSocks needs an issue filed on their docs 😅