From 993eb2687d18a91130b0e5695e9bf32adfb010dd Mon Sep 17 00:00:00 2001 From: Micooz Date: Sat, 4 Aug 2018 16:35:35 +0800 Subject: [PATCH] proxies(http): fix parsing error and 401 status code --- .travis.yml | 2 +- src/proxies/http.js | 12 ++++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5f933b2..9083148 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,7 @@ before_install: - curl --version before_deploy: - - export NEXT_VERSION=3.3.6 + - export NEXT_VERSION=3.4.0 - export COMMIT_HASH=$(git log --format=%h -1) - export DIST_PATH=build - export PUBLISH_REPO=blinksocks/blinksocks-nightly-releases diff --git a/src/proxies/http.js b/src/proxies/http.js index 3cba8c8..3720627 100644 --- a/src/proxies/http.js +++ b/src/proxies/http.js @@ -28,7 +28,14 @@ export function createServer({ secure, https_key, https_cert, username, password // Simple HTTP Proxy server.on('request', (req, res) => { - const { hostname, port, pathname } = new URL(req.url); + let parseResult; + try { + parseResult = new URL(req.url); + } catch (err) { + res.writeHead(400); + return res.end(); + } + const { hostname, port, pathname } = parseResult; const { socket, method, httpVersion, headers } = req; const appAddress = `${socket.remoteAddress}:${socket.remotePort}`; @@ -46,7 +53,8 @@ export function createServer({ secure, https_key, https_cert, username, password const [type, credentials] = proxyAuth.split(' '); if (type !== 'Basic' || !checkBasicAuthorization(credentials, { username, password })) { logger.error(`[${name}] [${appAddress}] authorization failed, type=${type} credentials=${credentials}`); - return res.end('HTTP/1.1 401 Unauthorized\r\n\r\n'); + res.writeHead(401); + return res.end(); } }