Skip to content

Commit ee8d32f

Browse files
charmanderbrianc
authored andcommitted
Deprecate implicit TLS rejectUnauthorized: false (#2075)
Yes, it treats `undefined` as `false`. Discussion in #2009. Introduced unintentionally in pg 0.8.7.
1 parent d456f1c commit ee8d32f

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

packages/pg/lib/compat/warn-deprecation.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const util = require('util')
55
const dummyFunctions = new Map()
66

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

1111
if (dummy === undefined) {
@@ -16,4 +16,4 @@ const emitDeprecationWarning = (message, code) => {
1616
dummy()
1717
}
1818

19-
module.exports = emitDeprecationWarning
19+
module.exports = warnDeprecation

packages/pg/lib/connection-fast.js

+5
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var Writer = require('buffer-writer')
1515
// eslint-disable-next-line
1616
var PacketStream = require('pg-packet-stream')
1717

18+
var warnDeprecation = require('./compat/warn-deprecation')
19+
1820
var TEXT_MODE = 0
1921

2022
// TODO(bmc) support binary mode here
@@ -105,6 +107,9 @@ Connection.prototype.connect = function (port, host) {
105107
secureOptions: self.ssl.secureOptions,
106108
NPNProtocols: self.ssl.NPNProtocols
107109
}
110+
if (typeof self.ssl.rejectUnauthorized !== 'boolean') {
111+
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')
112+
}
108113
if (net.isIP(host) === 0) {
109114
options.servername = host
110115
}

packages/pg/lib/connection.js

+5
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ var util = require('util')
1414
var Writer = require('buffer-writer')
1515
var Reader = require('packet-reader')
1616

17+
var warnDeprecation = require('./compat/warn-deprecation')
18+
1719
var TEXT_MODE = 0
1820
var BINARY_MODE = 1
1921
var Connection = function (config) {
@@ -103,6 +105,9 @@ Connection.prototype.connect = function (port, host) {
103105
secureOptions: self.ssl.secureOptions,
104106
NPNProtocols: self.ssl.NPNProtocols
105107
}
108+
if (typeof self.ssl.rejectUnauthorized !== 'boolean') {
109+
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')
110+
}
106111
if (net.isIP(host) === 0) {
107112
options.servername = host
108113
}

0 commit comments

Comments
 (0)