GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — self signed certificate error · Issue #2009 · brianc/node-postgres

self signed certificate error #2009

New issue
Copy link
New issue
Copy link
Closed
Closed
self signed certificate error#2009
Copy link
Milestone
[email protected]

Description

@eric-elsholz
eric-elsholz
opened on Nov 19, 2019
Issue body actions

Hi. Sorry ahead of time, I don't have a lot of detail here. We updated our packages today and afterwards started seeing a connection error from Sequelize ORM: "self signed certificate". We do in fact use a self signed certificate but this has never been a problem for us in the past. We downgraded from [email protected] to [email protected] and then we were able to connect again.

Reacted by Ian Remmel, Cameron Perry, Clay Murray, Dimos Botsaris, Brandon Zacharie, Tao Peng, Ján Káčer, Luke Hedin, Roman Leventov, Diego Rodríguez Baquero and 13 more

Activity

Next
  1. ianwremmel commented on Nov 19, 2019

    @ianwremmel
    ianwremmel
    on Nov 19, 2019
    More actions

    If I’m reading bf029c8 correctly, I think there may have been a bunch of options (including rejectUnauthorized) being inadvertently set to falsy values. They are now not set at all unless you pass them in. The last release was a breaking change, but it’s probably easiest to fix by passing rejectUnauthorized: false to pg.

    Reacted by Vaibhav Dwivedi and Paul Ojo
  2. ianwremmel commented on Nov 19, 2019

    @ianwremmel
    ianwremmel
    on Nov 19, 2019
    More actions

    Sorry, I think I actually meant checkServerIdentity.

  3. charmander commented on Nov 20, 2019

    @charmander
    charmander
    on Nov 20, 2019
    Collaborator
    More actions

    I think there may have been a bunch of options (including rejectUnauthorized) being inadvertently set to falsy values

    tls.connect treats rejectUnauthorized: undefined as rejectUnauthorized: false? … It does. Oh no. :(

    Well, it’s a good thing that was fixed. We should probably add a test for it. It might also be worth a security announcement (@brianc).

  4. powerc9000 commented on Nov 20, 2019

    @powerc9000
    powerc9000
    on Nov 20, 2019 · Hidden as duplicate
    show commentMore actions
  5. eldimious commented on Nov 20, 2019

    @eldimious
    eldimious
    on Nov 20, 2019 · Hidden as duplicate
    show commentMore actions
  6. znarf commented on Nov 20, 2019

    @znarf
    znarf
    on Nov 20, 2019 · Hidden as duplicate
    show commentMore actions
  7. BrandonZacharie commented on Nov 20, 2019

    @BrandonZacharie
    BrandonZacharie
    on Nov 20, 2019 · Hidden as duplicate
    show commentMore actions
  8. Kinetic-Pulse commented on Nov 20, 2019

    @Kinetic-Pulse
    Kinetic-Pulse
    on Nov 20, 2019 · Hidden as duplicate
    show commentMore actions
  9. ptpt commented on Nov 20, 2019

    @ptpt
    ptpt
    on Nov 20, 2019 · Hidden as duplicate
    show commentMore actions
  10. jsanta commented on Nov 20, 2019

    @jsanta
    jsanta
    on Nov 20, 2019
    More actions

    If it may help someone else, we just added the rejectUnauthorized: false, to our sequelize connection configuration:

    sequelize: {
        uri:
          'postgres://postgres_user:postgres_user_password@postgres_server:5432/postgres_database',
        options: {
          database: 'postgres_database',
          dialect: 'postgres',
          host: 'postgres_server',
          port: 5432,
          username: 'your_postgres_user',
          password: 'your_postgres_user_password',
          pool: {
            max: 3,
            min: 1,
            idle: 10000,
          },
          dialectOptions: {
            ssl: {
              require: true,
              // Ref.: https://github.com/brianc/node-postgres/issues/2009
              rejectUnauthorized: false,
            },
            keepAlive: true,        
          },      
          ssl: true,
          define: {
            timestamps: false,
          },
        },
      },
    

    lets say the error is still there, but we are not being notified, and the backend is not crashing anymore. Just adjust the configuration according to your own needs.
    Best regards from Chile.

    Reacted by Sergey Chernetsky, Kane Wang, Oscar Yañez, Matt Ramotar, Vilhelm Tamm, Hans, vothikimhieu18600091, Alex Chugaev, aparecida-gui, Louis Lepper and 5 more
    Reacted by Segers Ian, Alexander Kovalyov, Vance Lucas, フアン・カマーチョ, Dominik and Paul Ojo
    Reacted by Dimos Botsaris, Ján Káčer, Iván Roldán Lusich, Alejandro Corredor, dulyts, Himanshu Mishra, Christopher Taylor, alpha1336, saurabh, Aliaksei Kislou and 19 more
    Reacted by Sajeel Ahmad
    Reacted by Jayampathi Adhikari, Iván Roldán Lusich, Alejandro Corredor, Himanshu Mishra, Nadir A. Soza Solis, Christopher Taylor, Sebastián Gutiérrez, CaioValentim, Mathieu, alpha1336 and 11 more
  11. brianc commented on Nov 20, 2019

    @brianc
    brianc
    on Nov 20, 2019
    Owner
    More actions

    Gah, I apologize for this! There aren't enough tests around self-signed cert connecting with node-postgres in travis so it was missed. Totally accidental on my part! I'm going to roll out a backwards-compatible (to the 7.x line) semver patch on top of this one to make sure it behaves exactly as it should.

    @charmander what do you mean about security announcement? This makes things more secure now right? By forcing unauthorized cert rejection, where as before it was ignoring it? We should probably make the defaults be the same as the node.js defaults in v8.0. Do you mean announcing the current behavior is insecure in that it allows unauthorized certs unless you specifically set rejectUnauthorized to something to true? I agree that's worth calling out. We should also re-introduce this breaking change in 8.0 (w/ a deprecation notice in the 7.x line) so we can get folks to migrate to better ssl configurations.

    Reacted by eric-elsholz, François Hodierne, Dimos Botsaris, Euan Caskie, Dirk Heniges and Paul Ojo
  12. brianc commented on Nov 20, 2019

    @brianc
    brianc
    on Nov 20, 2019
    Owner
    More actions

    Okay - released [email protected] which reverts [email protected] 🤕 sorry about that!

    I'd like to get self-signed and "proper" ssl connections tested in travis. Anyone have a docker file handy that sets both of those things up? Then we can be covered on this behavior going forward.

    Reacted by Vipul Joshi and Paul Ojo
    Reacted by François Hodierne, Ian Reynolds, Dimos Botsaris, Vipul Joshi and Paul Ojo
  13. charmander commented on Nov 20, 2019

    @charmander
    charmander
    on Nov 20, 2019
    Collaborator
    More actions

    @charmander what do you mean about security announcement? This makes things more secure now right? By forcing unauthorized cert rejection, where as before it was ignoring it?

    @brianc Yep, it does! I meant an announcement that pg 0.8.7 through 7.12.0 don’t check certificates.

    (edit)

    Do you mean announcing the current behavior is insecure in that it allows unauthorized certs unless you specifically set rejectUnauthorized to something to true? I agree that's worth calling out. We should also re-introduce this breaking change in 8.0 (w/ a deprecation notice in the 7.x line) so we can get folks to migrate to better ssl configurations.

    Yes, exactly that.

  14. sehrope commented on Nov 20, 2019

    @sehrope
    sehrope
    on Nov 20, 2019
    Contributor
    More actions

    +1 to having the default in a new major being to validate so that it's an explicit action to disable things.

    FYI, the default for libpq (ex: via psql) is not to validate either so the default behavior of this module till now is not totally crazy either. May be worth calling that out in any security announcement: https://www.postgresql.org/docs/current/libpq-ssl.html (Still a +1 to making a security note calling out the behavior)

    Reacted by Charmander and Paul Ojo
  15. sehrope commented on Nov 20, 2019

    @sehrope
    sehrope
    on Nov 20, 2019
    Contributor
    More actions

    @brianc RE: a test setup, the defaults for a Debian / Ubuntu postgresql server install configures it to use a self signed "snake oil" cert. Setting it up in Docker container should be similar.

    The PGJDBC driver has a whole bunch of SSL related configs and tests for running things on Travis. Includes overwriting the certs, setting up specific users, installing the sslinfo extension for verifying things. May be worth a peek: https://github.com/pgjdbc/pgjdbc

  16. 61 remaining items

  17. charmander commented on Jul 12, 2021

    @charmander
    charmander
    on Jul 12, 2021 · Hidden as resolved
    show commentMore actions
  18. simon1tan commented on Aug 21, 2021

    @simon1tan
    simon1tan
    on Aug 21, 2021 · Hidden as spam
    show commentMore actions
  19. RodrigoBeiraoCardoso commented on Sep 3, 2021

    @RodrigoBeiraoCardoso
    RodrigoBeiraoCardoso
    on Sep 3, 2021 · Hidden as off-topic
    show commentMore actions
  20. jsanta commented on Sep 3, 2021

    @jsanta
    jsanta
    on Sep 3, 2021 · Hidden as resolved
    show commentMore actions
  21. RodrigoBeiraoCardoso commented on Sep 3, 2021

    @RodrigoBeiraoCardoso
    RodrigoBeiraoCardoso
    on Sep 3, 2021 · Hidden as off-topic
    show commentMore actions
  22. em-cd
    added a commit that references this issue on Dec 16, 2021

    Fix self-signed certificate error when connecting to PG

    db4194e
  23. nielssj
    added a commit that references this issue on Jan 18, 2022

    Include SSL configuration to work around issue with self-signed certs (…

    fdc90a9
  24. Tosinkoa commented on Sep 19, 2022

    @Tosinkoa
    Tosinkoa
    on Sep 19, 2022 · Hidden as resolved
    show commentMore actions
  25. charmander commented on Sep 22, 2022

    @charmander
    charmander
    on Sep 22, 2022 · Hidden as resolved
    show commentMore actions
  26. Tosinkoa commented on Sep 30, 2022

    @Tosinkoa
    Tosinkoa
    on Sep 30, 2022 · Hidden as resolved
    show commentMore actions
  27. pantelis-karamolegkos commented on Feb 21, 2024

    @pantelis-karamolegkos
    pantelis-karamolegkos
    on Feb 21, 2024
    More actions

    I have the following node script

    const { Pool } = require('pg');
    const { parse } = require('pg-connection-string');
    
    const config = parse(process.env.DATABASE_URL);
    config.ssl = { rejectUnauthorized: true };
    
    const pool = new Pool(config);
    
    pool.connect((err, client, done) => {
      if (err) {
        console.error('Error acquiring client', err.stack);
        return;
      }
    
      const testQuery = 'SELECT * FROM information_schema.tables';
      client.query(testQuery, (err, result) => {
        done();
        if (err) {
          console.error('Error executing query', err.stack);
          return;
        }
        console.log('Query result:', result.rows);
        pool.end();
      });
    });

    Before running the script I am exporting the NODE_EXTRA_CA_CERTS=../aws-global-bundle.pem where the .pem file is this one.

    My question is how can I enforce the verify-full option as described in the official postgresql documentation and what is the practical difference with setting the rejectUnauthorized to true ?

    I have tried the following

    config.ssl = { 
      rejectUnauthorized: true,
      sslmode: 'verify-full',
      ca: fs.readFileSync('./global-bundle.pem').toString(),
    };

    However it is as if the sslmode: 'verify-full', is not actually being taken into account because when I use sslmode: 'foobar', it does not complain at all (and connects as expected.

  28. charmander commented on Feb 22, 2024

    @charmander
    charmander
    on Feb 22, 2024
    Collaborator
    More actions

    @pantelis-karamolegkos sslmode is a connection string parameter (and has a corresponding environment variable named PGSSLMODE). It’s translated to the ssl: … property of the pg configuration object when you use a connection string. There is no ssl.sslmode. rejectUnauthorized: true/verify-full is the default behavior of Node’s tls module that pg passes the ssl object to directly, so all you need is

    config.ssl = {
      ca: fs.readFileSync('./global-bundle.pem'),
    };
  29. iNerdStack
    added 2 commits that reference this issue on Nov 9, 2025

    fix: Exclude PostgreSQL-blocked tests from test suite

    89287d8

    Claude/fix pnpm test (#47)

    80ec292
  30. Repository owner locked as resolved and limited conversation to collaborators on Feb 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • [email protected]

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402792 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.