From 19dfbf7f2bc78ab4a5dba908ddb3ee64ab29b578 Mon Sep 17 00:00:00 2001 From: Joker_ Date: Sun, 12 Jul 2020 23:39:03 +0800 Subject: [PATCH] URI-encode secret before appending to websocket URL --- src/api/connections.js | 2 +- src/api/logs.js | 14 +++++++------- src/api/traffic.js | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/api/connections.js b/src/api/connections.js index 50bd4fe..f540c74 100644 --- a/src/api/connections.js +++ b/src/api/connections.js @@ -47,7 +47,7 @@ function getWsUrl(apiConfig) { const { hostname, port, secret } = apiConfig; let qs = ''; if (typeof secret === 'string' && secret !== '') { - qs += '?token=' + secret; + qs += '?token=' + encodeURIComponent(secret); } return `ws://${hostname}:${port}${endpoint}${qs}`; } diff --git a/src/api/logs.js b/src/api/logs.js index 61aae7e..caabd04 100644 --- a/src/api/logs.js +++ b/src/api/logs.js @@ -63,7 +63,7 @@ function getWsUrl(apiConfig) { const { hostname, port, secret, logLevel } = apiConfig; let qs = '?level=' + logLevel; if (typeof secret === 'string' && secret !== '') { - qs += '&token=' + secret; + qs += '&token=' + encodeURIComponent(secret); } return `ws://${hostname}:${port}${endpoint}${qs}`; } @@ -78,14 +78,14 @@ function fetchLogs(apiConfig, appendLog) { wsState = 1; const url = getWsUrl(apiConfig); const ws = new WebSocket(url); - ws.addEventListener('error', function(_ev) { + ws.addEventListener('error', function (_ev) { wsState = 3; }); - ws.addEventListener('close', function(_ev) { + ws.addEventListener('close', function (_ev) { wsState = 3; fetchLogsWithFetch(apiConfig, appendLog); }); - ws.addEventListener('message', function(event) { + ws.addEventListener('message', function (event) { appendData(event.data, appendLog); }); } @@ -116,13 +116,13 @@ function fetchLogsWithFetch(apiConfig, appendLog) { const { url, init } = getURLAndInit(apiConfig); fetch(url + endpoint + '?level=' + apiConfig.logLevel, { ...init, - signal + signal, }).then( - response => { + (response) => { const reader = response.body.getReader(); pump(reader, appendLog); }, - err => { + (err) => { fetched = false; if (signal.aborted) return; diff --git a/src/api/traffic.js b/src/api/traffic.js index 4aa8ff6..f3f33ca 100644 --- a/src/api/traffic.js +++ b/src/api/traffic.js @@ -73,7 +73,7 @@ function getWsUrl(apiConfig) { const { hostname, port, secret } = apiConfig; let qs = ''; if (typeof secret === 'string' && secret !== '') { - qs += '?token=' + secret; + qs += '?token=' + encodeURIComponent(secret); } return `ws://${hostname}:${port}${endpoint}${qs}`; }