Security: simplify defineProperty non-enumerables

* `password` already has this set, but was a little long considering we only want to override default of one property
* `ssl.key` was showing up in tracebacks
This commit is contained in:
Lewis Cowles 2020-08-05 12:06:50 +01:00 committed by Brian C
parent 36342c9a84
commit fd2c3563a5
3 changed files with 22 additions and 0 deletions

View File

@ -73,6 +73,14 @@ class Pool extends EventEmitter {
value: options.password,
})
}
if (options != null && options.ssl && options.ssl.key) {
// "hiding" the ssl->key so it doesn't show up in stack traces
// or if the client is console.logged
this.options.ssl.key = options.ssl.key
Object.defineProperty(this.options.ssl, 'key', {
enumerable: false,
})
}
this.options.max = this.options.max || this.options.poolSize || 10
this.options.maxUses = this.options.maxUses || Infinity

View File

@ -57,6 +57,15 @@ class Client extends EventEmitter {
this.processID = null
this.secretKey = null
this.ssl = this.connectionParameters.ssl || false
// As with Password, make SSL->Key (the private key) non-enumerable.
// It won't show up in stack traces
// or if the client is console.logged
if (this.ssl && this.ssl.key) {
Object.defineProperty(this.ssl, 'key', {
enumerable: false,
})
}
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
}

View File

@ -84,6 +84,11 @@ class ConnectionParameters {
if (this.ssl === 'no-verify') {
this.ssl = { rejectUnauthorized: false }
}
if (this.ssl && this.ssl.key) {
Object.defineProperty(this.ssl, 'key', {
enumerable: false,
})
}
this.client_encoding = val('client_encoding', config)
this.replication = val('replication', config)