https connection doesn't work behind a socks5 proxy
See original GitHub issue🐛 Bug Report
The feature added to replace createNodeAgent doesnt work as expected https://github.com/elastic/elasticsearch-js/pull/810
When proxying the requests over socks5 through an ssh tunnel the library fails to find the host
After some debugging I found where the issue is but I don’t have enough understanding of the library to apply it.
On the connection pool urlToHost
new URL will transform https://myelastic:443 and remove the port, since it is the https protocol
When running the request the host is:
host:
[ 'Host',
'myelastic:80' ] } }
If I do the following the request is done successfully:
const requestParams = this.buildRequestObject(params)
requestParams.port = undefined
If requestParams.port = ''
, https.request host port will default to 80
To Reproduce
Version 6.X
const { Client } = require('@elastic/elasticsearch')
const SocksProxyAgent = require('socks-proxy-agent')
const client = new Client({
node: 'https://myelasticsearch:443',
agent: () => new SocksProxyAgent('socks5://127.0.0.1:7766')
})
client.search().then(response => {
console.log(response)
})
Expected behavior
Version 16.X
const { Client } = require('elasticsearch')
const SocksProxyAgent = require('socks-proxy-agent')
const client = new Client({
host: 'https://myelasticsearch:443',
createNodeAgent: () => new SocksProxyAgent('socks5://127.0.0.1:7766')
});
client.search().then(response => {
console.log(response)
})
or the same as in the reproduce with:
requestParams.port = undefined
Your Environment
- node version: v10.14.0
@elastic/elasticsearch
version: >=6.4.3- os: Mac
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
HTTPS connections over proxy servers - Stack Overflow
Normally, you use CONNECT to open up a TCP connection through the proxy. In this case, the proxy will not be able to...
Read more >Cannot connect to HTTPS sites using a SOCKS proxy (4 or 5)
tried to use socks4 or socks5 proxy inside firefox using 127.0.0.1 port 1080 - cannot connect to any HTTPS site via socks. Plain...
Read more >5 Reasons to Choose HTTPS Proxies Over SOCKS5 Proxy
This article will help you understand both HTTPS proxies and SOCKS5 and their differences ... SOCKS proxies can work with most connections or...
Read more >How do I connect to a server behind an socks5 proxy through ...
-D creates a SOCKS proxy. If you want to connect via a SOCKS proxy instead then you'll have to use connect as a...
Read more >How to Securely Bypass Blocks, Safe Torrenting, Free Proxy ...
As well as SOCKS, users can utilize the HTTP/HTTPS proxy method. HTTP proxies work similarly to SOCKS5, but utilize the HTTP protocol instead....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
https://github.com/hensansi/testing-socks
Hello! Thank you for investigating! The bug is due to how we build the request params object internally, and more specifically how we handle the port. We are using the URL constructor to parse the url of the node, in the legacy client we were using
url.parse
, which now is deprecated. The new URL parser defaults the port to an empty string for some protocols (https
is one of them), and thehttp/s.request
function in case of empty string defaults to 80.You can see how Node.js core is handling the URL here. I’ll open a pr to fix the issue.
Thank you again for reporting and investigating!