diff --git a/README.md b/README.md index b08f5a9..f52ffe2 100644 --- a/README.md +++ b/README.md @@ -141,7 +141,7 @@ session | Optional. Will send the request from and existing browser instance. If maxTimeout | Optional, default value 60000. Max timeout to solve the challenge in milliseconds. cookies | Optional. Will be used by the headless browser. Follow [this](https://github.com/puppeteer/puppeteer/blob/v3.3.0/docs/api.md#pagesetcookiecookies) format. returnOnlyCookies | Optional, default false. Only returns the cookies. Response data, headers and other parts of the response are removed. -proxy | Optional, default disabled. Eg: `"proxy": {"url": "http://127.0.0.1:8888"}`. Authorization (username/password) is not supported. +proxy | Optional, default disabled. Eg: `"proxy": {"url": "http://127.0.0.1:8888"}`. You must include the proxy schema in the URL: `http://`, `socks4://` or `socks5://`. Authorization (username/password) is not supported. :warning: If you want to use Cloudflare clearance cookie in your scripts, make sure you use the FlareSolverr User-Agent too. If they don't match you will see the challenge. diff --git a/src/services/sessions.ts b/src/services/sessions.ts index de8a8d1..190d802 100644 --- a/src/services/sessions.ts +++ b/src/services/sessions.ts @@ -60,18 +60,35 @@ function buildExtraPrefsFirefox(proxy: Proxy): object { const port = parseInt(portStr); const proxyPrefs = { - // Proxy configuration - "network.proxy.ftp": host, - "network.proxy.ftp_port": port, - "network.proxy.http": host, - "network.proxy.http_port": port, - "network.proxy.share_proxy_settings": true, - "network.proxy.socks": host, - "network.proxy.socks_port": port, - "network.proxy.socks_remote_dns": true, - "network.proxy.ssl": host, - "network.proxy.ssl_port": port, - "network.proxy.type": 1 + "network.proxy.type": 1, + "network.proxy.share_proxy_settings": true + } + if (proxy.url.indexOf("socks") != -1) { + // SOCKSv4 & SOCKSv5 + Object.assign(proxyPrefs, { + "network.proxy.socks": host, + "network.proxy.socks_port": port, + "network.proxy.socks_remote_dns": true + }); + if (proxy.url.indexOf("socks4") != -1) { + Object.assign(proxyPrefs, { + "network.proxy.socks_version": 4 + }); + } else { + Object.assign(proxyPrefs, { + "network.proxy.socks_version": 5 + }); + } + } else { + // HTTP + Object.assign(proxyPrefs, { + "network.proxy.ftp": host, + "network.proxy.ftp_port": port, + "network.proxy.http": host, + "network.proxy.http_port": port, + "network.proxy.ssl": host, + "network.proxy.ssl_port": port + }); } // merge objects diff --git a/src/tests/app.test.ts b/src/tests/app.test.ts index a186b57..5dab3a5 100644 --- a/src/tests/app.test.ts +++ b/src/tests/app.test.ts @@ -9,6 +9,7 @@ const sessions = require('../services/sessions'); const version: string = 'v' + require('../../package.json').version const proxyUrl = "http://127.0.0.1:8888" +const proxySocksUrl = "socks5://127.0.0.1:1080" const googleUrl = "https://www.google.com"; const postUrl = "https://ptsv2.com/t/qv4j3-1634496523"; const cfUrl = "https://pirateiro.com/torrents/?search=harry"; @@ -221,7 +222,7 @@ describe("Test '/v1' path", () => { expect(solution.userAgent).toBe(null) }); - test("Cmd 'request.get' should return OK with 'proxy' param", async () => { + test("Cmd 'request.get' should return OK with HTTP 'proxy' param", async () => { /* To configure TinyProxy in local: * sudo vim /etc/tinyproxy/tinyproxy.conf @@ -249,7 +250,7 @@ describe("Test '/v1' path", () => { }); // todo: credentials are not working - test.skip("Cmd 'request.get' should return OK with 'proxy' param with credentials", async () => { + test.skip("Cmd 'request.get' should return OK with HTTP 'proxy' param with credentials", async () => { /* To configure TinyProxy in local: * sudo vim /etc/tinyproxy/tinyproxy.conf @@ -279,6 +280,32 @@ describe("Test '/v1' path", () => { expect(solution.status).toContain(200) }); + test("Cmd 'request.get' should return OK with SOCKSv5 'proxy' param", async () => { + /* + To configure Dante in local: + * https://linuxhint.com/set-up-a-socks5-proxy-on-ubuntu-with-dante/ + * sudo vim /etc/sockd.conf + * sudo systemctl restart sockd.service + * curl --socks5 socks5://127.0.0.1:1080 https://www.google.com + */ + const payload = { + "cmd": "request.get", + "url": googleUrl, + "proxy": { + "url": proxySocksUrl + } + } + const response: Response = await request(app).post("/v1").send(payload); + expect(response.statusCode).toBe(200); + + const apiResponse: V1ResponseSolution = response.body; + expect(apiResponse.status).toBe("ok"); + + const solution = apiResponse.solution; + expect(solution.url).toContain(googleUrl) + expect(solution.status).toBe(200); + }); + test("Cmd 'request.get' should fail with wrong 'proxy' param", async () => { const payload = { "cmd": "request.get",