Skip to content

Commit c546e88

Browse files
committed
feat(pg-connection-string): warn if non-standard ssl options are used
In preparation for v3.0.0, we start warning users to be explicit about the sslmode they want.
1 parent 26ace0a commit c546e88

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/pg-connection-string/index.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict'
22

3+
const { emitWarning } = require('node:process')
4+
35
//Parse method copied from https://github.com/brianc/node-postgres
46
//Copyright (c) 2010-2014 Brian Carlson ([email protected])
57
//MIT License
@@ -133,6 +135,9 @@ function parse(str, options = {}) {
133135
case 'require':
134136
case 'verify-ca':
135137
case 'verify-full': {
138+
if (config.sslmode !== 'verify-full') {
139+
deprecatedSslModeWarning(config.sslmode)
140+
}
136141
break
137142
}
138143
case 'no-verify': {
@@ -201,6 +206,20 @@ function parseIntoClientConfig(str) {
201206
return toClientConfig(parse(str))
202207
}
203208

209+
function deprecatedSslModeWarning(sslmode) {
210+
if (!deprecatedSslModeWarning.warned) {
211+
deprecatedSslModeWarning.warned = true
212+
emitWarning(`SECURITY WARNING: The SSL modes 'prefer', 'require', and 'verify-ca' are treated as aliases for 'verify-full'.
213+
In the next major version (v3.0.0), these modes will adopt standard libpq semantics, which have weaker security guarantees.
214+
215+
To prepare for this change:
216+
- If you want the current behavior, explicitly use 'sslmode=verify-full'
217+
- If you want libpq compatibility now, use 'uselibpqcompat=true&sslmode=${sslmode}'
218+
219+
See https://www.postgresql.org/docs/current/libpq-ssl.html for libpq SSL mode definitions.`)
220+
}
221+
}
222+
204223
module.exports = parse
205224

206225
parse.parse = parse

0 commit comments

Comments
 (0)