Skip to content

Commit

Permalink
Deprecate implicit TLS rejectUnauthorized: false (#2075)
Browse files Browse the repository at this point in the history
Yes, it treats `undefined` as `false`. Discussion in #2009. Introduced unintentionally in pg 0.8.7.
  • Loading branch information
charmander authored and brianc committed Jan 15, 2020
1 parent d456f1c commit ee8d32f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/pg/lib/compat/warn-deprecation.js
Expand Up @@ -5,7 +5,7 @@ const util = require('util')
const dummyFunctions = new Map()

// Node 4 doesn’t support process.emitWarning(message, 'DeprecationWarning', code).
const emitDeprecationWarning = (message, code) => {
const warnDeprecation = (message, code) => {
let dummy = dummyFunctions.get(code)

if (dummy === undefined) {
Expand All @@ -16,4 +16,4 @@ const emitDeprecationWarning = (message, code) => {
dummy()
}

module.exports = emitDeprecationWarning
module.exports = warnDeprecation
5 changes: 5 additions & 0 deletions packages/pg/lib/connection-fast.js
Expand Up @@ -15,6 +15,8 @@ var Writer = require('buffer-writer')
// eslint-disable-next-line
var PacketStream = require('pg-packet-stream')

var warnDeprecation = require('./compat/warn-deprecation')

var TEXT_MODE = 0

// TODO(bmc) support binary mode here
Expand Down Expand Up @@ -105,6 +107,9 @@ Connection.prototype.connect = function (port, host) {
secureOptions: self.ssl.secureOptions,
NPNProtocols: self.ssl.NPNProtocols
}
if (typeof self.ssl.rejectUnauthorized !== 'boolean') {
warnDeprecation('Implicit disabling of certificate verification is deprecated and will be removed in pg 8. Specify `rejectUnauthorized: true` to require a valid CA or `rejectUnauthorized: false` to explicitly opt out of MITM protection.', 'PG-SSL-VERIFY')
}
if (net.isIP(host) === 0) {
options.servername = host
}
Expand Down
5 changes: 5 additions & 0 deletions packages/pg/lib/connection.js
Expand Up @@ -14,6 +14,8 @@ var util = require('util')
var Writer = require('buffer-writer')
var Reader = require('packet-reader')

var warnDeprecation = require('./compat/warn-deprecation')

var TEXT_MODE = 0
var BINARY_MODE = 1
var Connection = function (config) {
Expand Down Expand Up @@ -103,6 +105,9 @@ Connection.prototype.connect = function (port, host) {
secureOptions: self.ssl.secureOptions,
NPNProtocols: self.ssl.NPNProtocols
}
if (typeof self.ssl.rejectUnauthorized !== 'boolean') {
warnDeprecation('Implicit disabling of certificate verification is deprecated and will be removed in pg 8. Specify `rejectUnauthorized: true` to require a valid CA or `rejectUnauthorized: false` to explicitly opt out of MITM protection.', 'PG-SSL-VERIFY')
}
if (net.isIP(host) === 0) {
options.servername = host
}
Expand Down

0 comments on commit ee8d32f

Please sign in to comment.