From 4c870d4b741945b33c35ad5d920348b4ece3c799 Mon Sep 17 00:00:00 2001 From: Ryan Tharp Date: Mon, 30 Mar 2020 23:29:31 -0700 Subject: [PATCH] improve loki tld host checking, fix proxyFetch calling sendToProxy so tokens can be fetched --- js/modules/loki_app_dot_net_api.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/js/modules/loki_app_dot_net_api.js b/js/modules/loki_app_dot_net_api.js index ef56f8c1b..ecc8e9d3c 100644 --- a/js/modules/loki_app_dot_net_api.js +++ b/js/modules/loki_app_dot_net_api.js @@ -269,7 +269,7 @@ const serverRequest = async (endpoint, options = {}) => { )); } else { // disable check for .loki - process.env.NODE_TLS_REJECT_UNAUTHORIZED = url.host.match(/\.loki$/i) + process.env.NODE_TLS_REJECT_UNAUTHORIZED = host.match(/\.loki$/i) ? '0' : '1'; result = await nodeFetch(url, fetchOptions); @@ -298,7 +298,7 @@ const serverRequest = async (endpoint, options = {}) => { url ); } - if (mode === '_sendToProxy') { + if (mode === 'sendToProxy') { // if we can detect, certain types of failures, we can retry... if (e.code === 'ECONNRESET') { // retry with counter? @@ -658,7 +658,7 @@ class LokiAppDotNetServerAPI { try { const res = await this.proxyFetch( - `${this.baseServerUrl}/loki/v1/submit_challenge`, + new URL(`${this.baseServerUrl}/loki/v1/submit_challenge`), fetchOptions, { textResponse: true } ); @@ -683,7 +683,8 @@ class LokiAppDotNetServerAPI { } const urlStr = urlObj.toString(); const endpoint = urlStr.replace(`${this.baseServerUrl}/`, ''); - const { response, result } = await this._sendToProxy( + const { response, result } = await sendToProxy( + this.pubKey, endpoint, finalOptions, options @@ -694,8 +695,8 @@ class LokiAppDotNetServerAPI { json: () => response, }; } - const urlStr = urlObj.toString(); - if (urlStr.match(/\.loki\//)) { + const host = urlObj.host.toLowerCase(); + if (host.match(/\.loki$/)) { process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; } const result = nodeFetch(urlObj, fetchOptions, options);