devef
devef

Reputation: 41

SocketIO throws net::ERR_CERT_AUTHORITY_INVALID on self signed certificate

I am using socket io on client:

const socket = require('socket.io-client')('https://localhost:4200', {secure: true, rejectUnauthorized: false})

And on server:

let https = require('https')
let fs = require('fs')

let options = {
    key: fs.readFileSync('cert/my.net.key'),
    cert: fs.readFileSync('cert/my.net.cert'),
    requestCert: false,
    rejectUnauthorized: false,
};

const server = https.createServer(options, require('express')())
const io = require('socket.io')(server)

All services are started normally, but on client I am getting polling-xhr.js:263 GET https://localhost:4200/socket.io/?EIO=3&transport=polling&t=MPa6ZuL net::ERR_CERT_AUTHORITY_INVALID

Why? Whats is wrong?

Upvotes: 4

Views: 8610

Answers (1)

Edu Müller
Edu Müller

Reputation: 495

Browsers don't like self-signed certificates for security reasons.

To get around this in your development environment, I see three options:

  1. Use a certificate issued by a certification unit.

  2. Create your server dynamically, based on the development environment, not to include certificates and work directly with HTTP and WS (and not HTTPS and WSS).

  3. Change the configuration of your browser used in development so that it accepts self-signed certificates.

    • For Chrome, for example, just enable the Allow invalid certificates for resources loaded from localhost. (chrome://flags/#allow-insecure-localhost) setting.

But remember that you will not be able to use self-signed certificates in production environments.

Upvotes: 2

Related Questions