Skip to content

Commit 1091d7c

Browse files
charmanderbrianc
authored andcommitted
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.
1 parent 26e3a75 commit 1091d7c

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

packages/pg-pool/index.js

+12-9
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,18 @@ class Pool extends EventEmitter {
6060
constructor (options, Client) {
6161
super()
6262
this.options = Object.assign({}, options)
63-
const password = this.options.password
64-
// "hiding" the password so it doesn't show up in stack traces
65-
// or if the client is console.logged
66-
Object.defineProperty(this.options, 'password', {
67-
configurable: true,
68-
enumerable: false,
69-
value: password,
70-
writable: true
71-
})
63+
64+
if (options != null && 'password' in options) {
65+
// "hiding" the password so it doesn't show up in stack traces
66+
// or if the client is console.logged
67+
Object.defineProperty(this.options, 'password', {
68+
configurable: true,
69+
enumerable: false,
70+
writable: true,
71+
value: options.password
72+
})
73+
}
74+
7275
this.options.max = this.options.max || this.options.poolSize || 10
7376
this.log = this.options.log || function () { }
7477
this.Client = this.options.Client || Client || require('pg').Client

packages/pg/lib/client.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,11 @@ var Client = function (config) {
3333

3434
// "hiding" the password so it doesn't show up in stack traces
3535
// or if the client is console.logged
36-
const password = this.connectionParameters.password
3736
Object.defineProperty(this, 'password', {
37+
configurable: true,
3838
enumerable: false,
39-
configurable: false,
4039
writable: true,
41-
value: password
40+
value: this.connectionParameters.password
4241
})
4342

4443
this.replication = this.connectionParameters.replication

packages/pg/lib/connection-parameters.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,11 @@ var ConnectionParameters = function (config) {
5757

5858
// "hiding" the password so it doesn't show up in stack traces
5959
// or if the client is console.logged
60-
const password = val('password', config)
6160
Object.defineProperty(this, 'password', {
61+
configurable: true,
6262
enumerable: false,
63-
configurable: false,
64-
writable: false,
65-
value: password
63+
writable: true,
64+
value: val('password', config)
6665
})
6766

6867
this.binary = val('binary', config)

0 commit comments

Comments
 (0)