Skip to content

Commit aafd8ac

Browse files
brianccharmandergabegorelickNatalieWolfe
authored
8.0 Release (#2117)
* Drop support for EOL versions of node (#2062) * Drop support for EOL versions of node * Re-add testing for [email protected] * Revert changes to .travis.yml * Update packages/pg-pool/package.json Co-Authored-By: Charmander <[email protected]> Co-authored-by: Charmander <[email protected]> * Remove password from stringified outputs (#2066) * Remove password from stringified outputs Theres a security concern where if you're not careful and you include your client or pool instance in console.log or stack traces it might include the database password. To widen the pit of success I'm making that field non-enumerable. You can still get at it...it just wont show up "by accident" when you're logging things now. The backwards compatiblity impact of this is very small, but it is still technically somewhat an API change so...8.0. * Implement feedback * Fix more whitespace the autoformatter changed * Simplify code a bit * Remove password from stringified outputs (#2070) * Keep ConnectionParameters’s password property writable `Client` writes to it when `password` is a function. * Avoid creating password property on pool options when it didn’t exist previously. * Allow password option to be non-enumerable to avoid breaking uses like `new Pool(existingPool.options)`. * Make password property definitions consistent in formatting and configurability. Co-authored-by: Charmander <[email protected]> * Make `native` non-enumerable (#2065) * Make `native` non-enumerable Making it non-enumerable means less spurious "Cannot find module" errors in your logs when iterating over `pg` objects. `Object.defineProperty` has been available since Node 0.12. See #1894 (comment) * Add test for `native` enumeration Co-authored-by: Gabe Gorelick <[email protected]> * Use class-extends to wrap Pool (#1541) * Use class-extends to wrap Pool * Minimize diff * Test `BoundPool` inheritance Co-authored-by: Charmander <[email protected]> Co-authored-by: Brian C <[email protected]> * Continue support for creating a pg.Pool from another instance’s options (#2076) * Add failing test for creating a `BoundPool` from another instance’s settings * Continue support for creating a pg.Pool from another instance’s options by dropping the requirement for the `password` property to be enumerable. * Use user name as default database when user is non-default (#1679) Not entirely backwards-compatible. * Make native client password property consistent with others i.e. configurable. * Make notice messages not an instance of Error (#2090) * Make notice messages not an instance of Error Slight API cleanup to make a notice instance the same shape as it was, but not be an instance of error. This is a backwards incompatible change though I expect the impact to be minimal. Closes #1982 * skip notice test in travis * Pin [email protected] for regression in async iterators * Check and see if node 13.8 is still borked on async iterator * Yeah, node still has changed edge case behavior on stream * Emit notice messages on travis * Revert "Revert "Support additional tls.connect() options (#1996)" (#2010)" (#2113) This reverts commit 510a273. * Fix ssl tests (#2116) * Convert Query to an ES6 class (#2126) The last missing `new` deprecation warning for pg 8. Co-authored-by: Charmander <[email protected]> Co-authored-by: Gabe Gorelick <[email protected]> Co-authored-by: Natalie Wolfe <[email protected]>
1 parent c036779 commit aafd8ac

22 files changed

+416
-317
lines changed

packages/pg-pool/index.js

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ class Pool extends EventEmitter {
6464
constructor (options, Client) {
6565
super()
6666
this.options = Object.assign({}, options)
67+
68+
if (options != null && 'password' in options) {
69+
// "hiding" the password so it doesn't show up in stack traces
70+
// or if the client is console.logged
71+
Object.defineProperty(this.options, 'password', {
72+
configurable: true,
73+
enumerable: false,
74+
writable: true,
75+
value: options.password
76+
})
77+
}
78+
6779
this.options.max = this.options.max || this.options.poolSize || 10
6880
this.log = this.options.log || function () { }
6981
this.Client = this.options.Client || Client || require('pg').Client

packages/pg-pool/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@
3434
"pg-cursor": "^1.3.0"
3535
},
3636
"peerDependencies": {
37-
"pg": ">5.0"
37+
"pg": ">=8.0"
3838
}
3939
}

packages/pg/Makefile

+1-3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,4 @@ test-pool:
6262

6363
lint:
6464
@echo "***Starting lint***"
65-
node -e "process.exit(Number(process.versions.node.split('.')[0]) < 8 ? 0 : 1)" \
66-
&& echo "***Skipping lint (node version too old)***" \
67-
|| node_modules/.bin/eslint lib
65+
node_modules/.bin/eslint lib

packages/pg/lib/client.js

+10-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,16 @@ var Client = function (config) {
3030
this.database = this.connectionParameters.database
3131
this.port = this.connectionParameters.port
3232
this.host = this.connectionParameters.host
33-
this.password = this.connectionParameters.password
33+
34+
// "hiding" the password so it doesn't show up in stack traces
35+
// or if the client is console.logged
36+
Object.defineProperty(this, 'password', {
37+
configurable: true,
38+
enumerable: false,
39+
writable: true,
40+
value: this.connectionParameters.password
41+
})
42+
3443
this.replication = this.connectionParameters.replication
3544

3645
var c = config || {}

packages/pg/lib/compat/check-constructor.js

-22
This file was deleted.

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

-19
This file was deleted.

packages/pg/lib/connection-fast.js

+3-17
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ 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-
2018
var TEXT_MODE = 0
2119

2220
// TODO(bmc) support binary mode here
@@ -95,21 +93,9 @@ Connection.prototype.connect = function (port, host) {
9593
return self.emit('error', new Error('There was an error establishing an SSL connection'))
9694
}
9795
var tls = require('tls')
98-
const options = {
99-
socket: self.stream,
100-
checkServerIdentity: self.ssl.checkServerIdentity || tls.checkServerIdentity,
101-
rejectUnauthorized: self.ssl.rejectUnauthorized,
102-
ca: self.ssl.ca,
103-
pfx: self.ssl.pfx,
104-
key: self.ssl.key,
105-
passphrase: self.ssl.passphrase,
106-
cert: self.ssl.cert,
107-
secureOptions: self.ssl.secureOptions,
108-
NPNProtocols: self.ssl.NPNProtocols
109-
}
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-
}
96+
const options = Object.assign({
97+
socket: self.stream
98+
}, self.ssl)
11399
if (net.isIP(host) === 0) {
114100
options.servername = host
115101
}

packages/pg/lib/connection-parameters.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,23 @@ var ConnectionParameters = function (config) {
5252

5353
this.user = val('user', config)
5454
this.database = val('database', config)
55+
56+
if (this.database === undefined) {
57+
this.database = this.user
58+
}
59+
5560
this.port = parseInt(val('port', config), 10)
5661
this.host = val('host', config)
57-
this.password = val('password', config)
62+
63+
// "hiding" the password so it doesn't show up in stack traces
64+
// or if the client is console.logged
65+
Object.defineProperty(this, 'password', {
66+
configurable: true,
67+
enumerable: false,
68+
writable: true,
69+
value: val('password', config)
70+
})
71+
5872
this.binary = val('binary', config)
5973
this.ssl = typeof config.ssl === 'undefined' ? useSsl() : config.ssl
6074
this.client_encoding = val('client_encoding', config)

packages/pg/lib/connection.js

+7-21
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ 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-
1917
var TEXT_MODE = 0
2018
var BINARY_MODE = 1
2119
var Connection = function (config) {
@@ -95,21 +93,9 @@ Connection.prototype.connect = function (port, host) {
9593
return self.emit('error', new Error('There was an error establishing an SSL connection'))
9694
}
9795
var tls = require('tls')
98-
const options = {
99-
socket: self.stream,
100-
checkServerIdentity: self.ssl.checkServerIdentity || tls.checkServerIdentity,
101-
rejectUnauthorized: self.ssl.rejectUnauthorized,
102-
ca: self.ssl.ca,
103-
pfx: self.ssl.pfx,
104-
key: self.ssl.key,
105-
passphrase: self.ssl.passphrase,
106-
cert: self.ssl.cert,
107-
secureOptions: self.ssl.secureOptions,
108-
NPNProtocols: self.ssl.NPNProtocols
109-
}
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-
}
96+
const options = Object.assign({
97+
socket: self.stream
98+
}, self.ssl)
11399
if (net.isIP(host) === 0) {
114100
options.servername = host
115101
}
@@ -602,7 +588,7 @@ Connection.prototype._readValue = function (buffer) {
602588
}
603589

604590
// parses error
605-
Connection.prototype.parseE = function (buffer, length) {
591+
Connection.prototype.parseE = function (buffer, length, isNotice) {
606592
var fields = {}
607593
var fieldType = this.readString(buffer, 1)
608594
while (fieldType !== '\0') {
@@ -611,10 +597,10 @@ Connection.prototype.parseE = function (buffer, length) {
611597
}
612598

613599
// the msg is an Error instance
614-
var msg = new Error(fields.M)
600+
var msg = isNotice ? { message: fields.M } : new Error(fields.M)
615601

616602
// for compatibility with Message
617-
msg.name = 'error'
603+
msg.name = isNotice ? 'notice' : 'error'
618604
msg.length = length
619605

620606
msg.severity = fields.S
@@ -638,7 +624,7 @@ Connection.prototype.parseE = function (buffer, length) {
638624

639625
// same thing, different name
640626
Connection.prototype.parseN = function (buffer, length) {
641-
var msg = this.parseE(buffer, length)
627+
var msg = this.parseE(buffer, length, true)
642628
msg.name = 'notice'
643629
return msg
644630
}

packages/pg/lib/defaults.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
user: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
1616

1717
// name of database to connect
18-
database: process.platform === 'win32' ? process.env.USERNAME : process.env.USER,
18+
database: undefined,
1919

2020
// database user's password
2121
password: null,

packages/pg/lib/index.js

+25-25
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,17 @@
77
* README.md file in the root directory of this source tree.
88
*/
99

10-
var util = require('util')
1110
var Client = require('./client')
1211
var defaults = require('./defaults')
1312
var Connection = require('./connection')
1413
var Pool = require('pg-pool')
15-
const checkConstructor = require('./compat/check-constructor')
1614

1715
const poolFactory = (Client) => {
18-
var BoundPool = function (options) {
19-
// eslint-disable-next-line no-eval
20-
checkConstructor('pg.Pool', 'PG-POOL-NEW', () => eval('new.target'))
21-
22-
var config = Object.assign({ Client: Client }, options)
23-
return new Pool(config)
16+
return class BoundPool extends Pool {
17+
constructor (options) {
18+
super(options, Client)
19+
}
2420
}
25-
26-
util.inherits(BoundPool, Pool)
27-
28-
return BoundPool
2921
}
3022

3123
var PG = function (clientConstructor) {
@@ -44,20 +36,28 @@ if (typeof process.env.NODE_PG_FORCE_NATIVE !== 'undefined') {
4436
module.exports = new PG(Client)
4537

4638
// lazy require native module...the native module may not have installed
47-
module.exports.__defineGetter__('native', function () {
48-
delete module.exports.native
49-
var native = null
50-
try {
51-
native = new PG(require('./native'))
52-
} catch (err) {
53-
if (err.code !== 'MODULE_NOT_FOUND') {
54-
throw err
39+
Object.defineProperty(module.exports, 'native', {
40+
configurable: true,
41+
enumerable: false,
42+
get() {
43+
var native = null
44+
try {
45+
native = new PG(require('./native'))
46+
} catch (err) {
47+
if (err.code !== 'MODULE_NOT_FOUND') {
48+
throw err
49+
}
50+
/* eslint-disable no-console */
51+
console.error(err.message)
52+
/* eslint-enable no-console */
5553
}
56-
/* eslint-disable no-console */
57-
console.error(err.message)
58-
/* eslint-enable no-console */
54+
55+
// overwrite module.exports.native so that getter is never called again
56+
Object.defineProperty(module.exports, 'native', {
57+
value: native
58+
})
59+
60+
return native
5961
}
60-
module.exports.native = native
61-
return native
6262
})
6363
}

packages/pg/lib/native/client.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,15 @@ var Client = module.exports = function (config) {
4343
// for the time being. TODO: deprecate all this jazz
4444
var cp = this.connectionParameters = new ConnectionParameters(config)
4545
this.user = cp.user
46-
this.password = cp.password
46+
47+
// "hiding" the password so it doesn't show up in stack traces
48+
// or if the client is console.logged
49+
Object.defineProperty(this, 'password', {
50+
configurable: true,
51+
enumerable: false,
52+
writable: true,
53+
value: cp.password
54+
})
4755
this.database = cp.database
4856
this.host = cp.host
4957
this.port = cp.port

0 commit comments

Comments
 (0)