From a644530551d408cfc035d99c67264872ec4e08d4 Mon Sep 17 00:00:00 2001 From: Steven Nguyen Date: Fri, 6 Oct 2023 15:58:39 -0700 Subject: [PATCH] Update how the node SDK handles self signed requests The NODE_TLS_REJECT_UNAUTHORIZED env variable will disable SSL checks for all requests. This PR changes the node SDK to only disable SSL checks for Appwrite related requests by passing an option to axios. --- templates/node/lib/client.js.twig | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/node/lib/client.js.twig b/templates/node/lib/client.js.twig index b2538e8e8..c3b8130e5 100644 --- a/templates/node/lib/client.js.twig +++ b/templates/node/lib/client.js.twig @@ -1,5 +1,6 @@ const os = require('os'); const URL = require('url').URL; +const https = require("https"); const axios = require('axios'); const FormData = require('form-data'); const {{spec.title | caseUcfirst}}Exception = require('./exception.js'); @@ -81,11 +82,6 @@ class Client { } async call(method, path = '', headers = {}, params = {}, responseType = 'json') { - if(this.selfSigned) { // Allow self signed requests - process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0; - } - - headers = Object.assign({}, this.headers, headers); let contentType = headers['content-type'].toLowerCase(); @@ -125,6 +121,10 @@ class Client { json: (contentType.startsWith('application/json')), responseType: responseType }; + if (this.selfSigned) { + // Allow self signed requests + options.httpsAgent = new https.Agent({ rejectUnauthorized: false }); + } try { let response = await axios(options); return response.data;