Skip to content

Commit

Permalink
Remove password from stringified outputs (#2070)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
charmander authored and brianc committed Jan 13, 2020
1 parent 26e3a75 commit 1091d7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
21 changes: 12 additions & 9 deletions packages/pg-pool/index.js
Expand Up @@ -60,15 +60,18 @@ class Pool extends EventEmitter {
constructor (options, Client) {
super()
this.options = Object.assign({}, options)
const password = this.options.password
// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
Object.defineProperty(this.options, 'password', {
configurable: true,
enumerable: false,
value: password,
writable: true
})

if (options != null && 'password' in options) {
// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
Object.defineProperty(this.options, 'password', {
configurable: true,
enumerable: false,
writable: true,
value: options.password
})
}

this.options.max = this.options.max || this.options.poolSize || 10
this.log = this.options.log || function () { }
this.Client = this.options.Client || Client || require('pg').Client
Expand Down
5 changes: 2 additions & 3 deletions packages/pg/lib/client.js
Expand Up @@ -33,12 +33,11 @@ var Client = function (config) {

// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
const password = this.connectionParameters.password
Object.defineProperty(this, 'password', {
configurable: true,
enumerable: false,
configurable: false,
writable: true,
value: password
value: this.connectionParameters.password
})

this.replication = this.connectionParameters.replication
Expand Down
7 changes: 3 additions & 4 deletions packages/pg/lib/connection-parameters.js
Expand Up @@ -57,12 +57,11 @@ var ConnectionParameters = function (config) {

// "hiding" the password so it doesn't show up in stack traces
// or if the client is console.logged
const password = val('password', config)
Object.defineProperty(this, 'password', {
configurable: true,
enumerable: false,
configurable: false,
writable: false,
value: password
writable: true,
value: val('password', config)
})

this.binary = val('binary', config)
Expand Down

0 comments on commit 1091d7c

Please sign in to comment.