Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 685
devef Avatar asked Oct 20 '25 15:10

devef


1 Answers

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.

    • It could be something free, like https://letsencrypt.org/.
  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.

like image 170
Edu Müller Avatar answered Oct 23 '25 04:10

Edu Müller



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!