Skip to content

Commit fd2c356

Browse files
Lewiscowles1986brianc
authored andcommitted
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
1 parent 36342c9 commit fd2c356

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

Diff for: packages/pg-pool/index.js

+8
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,14 @@ class Pool extends EventEmitter {
7373
value: options.password,
7474
})
7575
}
76+
if (options != null && options.ssl && options.ssl.key) {
77+
// "hiding" the ssl->key so it doesn't show up in stack traces
78+
// or if the client is console.logged
79+
this.options.ssl.key = options.ssl.key
80+
Object.defineProperty(this.options.ssl, 'key', {
81+
enumerable: false,
82+
})
83+
}
7684

7785
this.options.max = this.options.max || this.options.poolSize || 10
7886
this.options.maxUses = this.options.maxUses || Infinity

Diff for: packages/pg/lib/client.js

+9
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ class Client extends EventEmitter {
5757
this.processID = null
5858
this.secretKey = null
5959
this.ssl = this.connectionParameters.ssl || false
60+
// As with Password, make SSL->Key (the private key) non-enumerable.
61+
// It won't show up in stack traces
62+
// or if the client is console.logged
63+
if (this.ssl && this.ssl.key) {
64+
Object.defineProperty(this.ssl, 'key', {
65+
enumerable: false,
66+
})
67+
}
68+
6069
this._connectionTimeoutMillis = c.connectionTimeoutMillis || 0
6170
}
6271

Diff for: packages/pg/lib/connection-parameters.js

+5
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class ConnectionParameters {
8484
if (this.ssl === 'no-verify') {
8585
this.ssl = { rejectUnauthorized: false }
8686
}
87+
if (this.ssl && this.ssl.key) {
88+
Object.defineProperty(this.ssl, 'key', {
89+
enumerable: false,
90+
})
91+
}
8792

8893
this.client_encoding = val('client_encoding', config)
8994
this.replication = val('replication', config)

0 commit comments

Comments
 (0)