Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Bug Report: Enabling self signed certificates for Node SDK doesn't work #6832

Closed
2 tasks done
stnguyen90 opened this issue Oct 6, 2023 · 1 comment 路 Fixed by appwrite/sdk-generator#722
Closed
2 tasks done
Assignees
Labels
bug Something isn't working

Comments

@stnguyen90
Copy link
Contributor

馃憻 Reproduction steps

Run the following code with the correct endpoint, project, and API key.

const sdk = require('node-appwrite');

let client = new sdk.Client();

client
    .setEndpoint('https://[HOSTNAME_OR_IP]/v1') // Your API Endpoint
    .setProject('5df5acd0d48c2') // Your project ID
    .setKey('919c2d18fb5d4...a2ae413da83346ad2') // Your secret API key
    .setSelfSigned() // Use only on dev mode with a self-signed SSL cert
;

let users = new sdk.Users(client);

let promise = users.list();

promise.then(function (response) {
    console.log(response);
}, function (error) {
    console.log(error);
});

馃憤 Expected behavior

Assuming your Appwrite instance has a self signed certificate, the API call should work.

馃憥 Actual Behavior

The API call will fail with an error like:

AppwriteException [Error]: self-signed certificate

The way we're handing self-signed certificates is:

process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = 0;

However, Node does a strict check:

const allowUnauthorized = process.env.NODE_TLS_REJECT_UNAUTHORIZED === '0';

As such, the check fails.

Furthermore, we shouldn't be using this NODE_TLS_REJECT_UNAUTHORIZED environment variable because it disables TLS for all network requests, but we should only allow self-signed certificates for the Appwrite API calls. Instead of setting NODE_TLS_REJECT_UNAUTHORIZED, we should be passing an option to axios like we do in the CLI:

options.httpsAgent = new https.Agent({ rejectUnauthorized: false });

馃幉 Appwrite version

Appwrite Cloud

馃捇 Operating system

Linux

馃П Your Environment

This was seen in node-appwrite version 11.0.0

馃憖 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

馃彚 Have you read the Code of Conduct?

@nick2432
Copy link

nick2432 commented Nov 2, 2023

can i work on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants